diff options
Diffstat (limited to 'fs/bcachefs/xattr.c')
-rw-r--r-- | fs/bcachefs/xattr.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/fs/bcachefs/xattr.c b/fs/bcachefs/xattr.c index cb84bdabb6ed..44bf4a2f3c84 100644 --- a/fs/bcachefs/xattr.c +++ b/fs/bcachefs/xattr.c @@ -111,12 +111,12 @@ const char *bch2_xattr_invalid(const struct bch_fs *c, struct bkey_s_c k) } } -void bch2_xattr_to_text(struct bch_fs *c, char *buf, - size_t size, struct bkey_s_c k) +int bch2_xattr_to_text(struct bch_fs *c, char *buf, + size_t size, struct bkey_s_c k) { + char *out = buf, *end = buf + size; const struct xattr_handler *handler; struct bkey_s_c_xattr xattr; - size_t n = 0; switch (k.k->type) { case BCH_XATTR: @@ -124,24 +124,26 @@ void bch2_xattr_to_text(struct bch_fs *c, char *buf, handler = bch2_xattr_type_to_handler(xattr.v->x_type); if (handler && handler->prefix) - n += scnprintf(buf + n, size - n, "%s", handler->prefix); + out += scnprintf(out, end - out, "%s", handler->prefix); else if (handler) - n += scnprintf(buf + n, size - n, "(type %u)", - xattr.v->x_type); + out += scnprintf(out, end - out, "(type %u)", + xattr.v->x_type); else - n += scnprintf(buf + n, size - n, "(unknown type %u)", - xattr.v->x_type); - - n += bch_scnmemcpy(buf + n, size - n, xattr.v->x_name, - xattr.v->x_name_len); - n += scnprintf(buf + n, size - n, ":"); - n += bch_scnmemcpy(buf + n, size - n, xattr_val(xattr.v), - le16_to_cpu(xattr.v->x_val_len)); + out += scnprintf(out, end - out, "(unknown type %u)", + xattr.v->x_type); + + out += bch_scnmemcpy(out, end - out, xattr.v->x_name, + xattr.v->x_name_len); + out += scnprintf(out, end - out, ":"); + out += bch_scnmemcpy(out, end - out, xattr_val(xattr.v), + le16_to_cpu(xattr.v->x_val_len)); break; case BCH_XATTR_WHITEOUT: - scnprintf(buf, size, "whiteout"); + out += scnprintf(out, end - out, "whiteout"); break; } + + return out - buf; } int bch2_xattr_get(struct bch_fs *c, struct bch_inode_info *inode, |