bcachefs: bch2_acl_to_text()
authorKent Overstreet <kent.overstreet@linux.dev>
Fri, 8 Sep 2023 22:14:08 +0000 (18:14 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:10:12 +0000 (17:10 -0400)
We can now print out acls from bch2_xattr_to_text(), when the xattr
contains an acl.

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/Makefile
fs/bcachefs/acl.c
fs/bcachefs/acl.h
fs/bcachefs/xattr.c

index b4fa88dfd484c291227f2c0504a108dec428be60..0a4d2fed66c13648888e90e5c69cf753e236a960 100644 (file)
@@ -2,6 +2,7 @@
 obj-$(CONFIG_BCACHEFS_FS)      += bcachefs.o
 
 bcachefs-y             :=      \
+       acl.o                   \
        alloc_background.o      \
        alloc_foreground.o      \
        backpointers.o          \
@@ -81,5 +82,4 @@ bcachefs-y            :=      \
        varint.o                \
        xattr.o
 
-bcachefs-$(CONFIG_BCACHEFS_POSIX_ACL) += acl.o
 obj-$(CONFIG_MEAN_AND_VARIANCE_UNIT_TEST)   += mean_and_variance_test.o
index b1a488860678cd9242f84e7ab5ddd2b1724cd26f..ae2036b0fcc4b3d9953fe54b9c9abda804756b89 100644 (file)
@@ -1,18 +1,71 @@
 // SPDX-License-Identifier: GPL-2.0
-#ifdef CONFIG_BCACHEFS_POSIX_ACL
 
 #include "bcachefs.h"
 
-#include <linux/fs.h>
+#include "acl.h"
+#include "xattr.h"
+
 #include <linux/posix_acl.h>
+
+static const char * const acl_types[] = {
+       [ACL_USER_OBJ]  = "user_obj",
+       [ACL_USER]      = "user",
+       [ACL_GROUP_OBJ] = "group_obj",
+       [ACL_GROUP]     = "group",
+       [ACL_MASK]      = "mask",
+       [ACL_OTHER]     = "other",
+       NULL,
+};
+
+void bch2_acl_to_text(struct printbuf *out, const void *value, size_t size)
+{
+       const void *p, *end = value + size;
+
+       if (!value ||
+           size < sizeof(bch_acl_header) ||
+           ((bch_acl_header *)value)->a_version != cpu_to_le32(BCH_ACL_VERSION))
+               return;
+
+       p = value + sizeof(bch_acl_header);
+       while (p < end) {
+               const bch_acl_entry *in = p;
+               unsigned tag = le16_to_cpu(in->e_tag);
+
+               prt_str(out, acl_types[tag]);
+
+               switch (tag) {
+               case ACL_USER_OBJ:
+               case ACL_GROUP_OBJ:
+               case ACL_MASK:
+               case ACL_OTHER:
+                       p += sizeof(bch_acl_entry_short);
+                       break;
+               case ACL_USER:
+                       prt_printf(out, " uid %u", le32_to_cpu(in->e_id));
+                       p += sizeof(bch_acl_entry);
+                       break;
+               case ACL_GROUP:
+                       prt_printf(out, " gid %u", le32_to_cpu(in->e_id));
+                       p += sizeof(bch_acl_entry);
+                       break;
+               }
+
+               prt_printf(out, " %o", le16_to_cpu(in->e_perm));
+
+               if (p != end)
+                       prt_char(out, ' ');
+       }
+}
+
+#ifdef CONFIG_BCACHEFS_POSIX_ACL
+
+#include "fs.h"
+
+#include <linux/fs.h>
 #include <linux/posix_acl_xattr.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
 
-#include "acl.h"
-#include "fs.h"
-#include "xattr.h"
-
 static inline size_t bch2_acl_size(unsigned nr_short, unsigned nr_long)
 {
        return sizeof(bch_acl_header) +
index bb21d8d696a2fc3806d9ee1e353999ccd424d99b..27e7eec0f278c63784ec9520ffc31c7fad8cd7eb 100644 (file)
@@ -7,8 +7,6 @@ struct bch_hash_info;
 struct bch_inode_info;
 struct posix_acl;
 
-#ifdef CONFIG_BCACHEFS_POSIX_ACL
-
 #define BCH_ACL_VERSION        0x0001
 
 typedef struct {
@@ -26,6 +24,10 @@ typedef struct {
        __le32          a_version;
 } bch_acl_header;
 
+void bch2_acl_to_text(struct printbuf *, const void *, size_t);
+
+#ifdef CONFIG_BCACHEFS_POSIX_ACL
+
 struct posix_acl *bch2_get_acl(struct mnt_idmap *, struct dentry *, int);
 
 int bch2_set_acl_trans(struct btree_trans *, subvol_inum,
index 6f6b3caf06078684426ce740cf35a580d26131f1..637174b249a2248bcf26fd76249bd1a9ec29f055 100644 (file)
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 
 #include "bcachefs.h"
+#include "acl.h"
 #include "bkey_methods.h"
 #include "btree_update.h"
 #include "extents.h"
@@ -130,6 +131,13 @@ void bch2_xattr_to_text(struct printbuf *out, struct bch_fs *c,
               xattr.v->x_name,
               le16_to_cpu(xattr.v->x_val_len),
               (char *) xattr_val(xattr.v));
+
+       if (xattr.v->x_type == KEY_TYPE_XATTR_INDEX_POSIX_ACL_ACCESS ||
+           xattr.v->x_type == KEY_TYPE_XATTR_INDEX_POSIX_ACL_DEFAULT) {
+               prt_char(out, ' ');
+               bch2_acl_to_text(out, xattr_val(xattr.v),
+                                le16_to_cpu(xattr.v->x_val_len));
+       }
 }
 
 static int bch2_xattr_get_trans(struct btree_trans *trans, struct bch_inode_info *inode,