xattr support for btrfs-progs
authorJosef Bacik <jbacik@redhat.com>
Fri, 16 Nov 2007 16:46:07 +0000 (11:46 -0500)
committerDavid Woodhouse <dwmw2@hera.kernel.org>
Fri, 16 Nov 2007 16:46:07 +0000 (11:46 -0500)
ctree.h
dir-item.c
print-tree.c

diff --git a/ctree.h b/ctree.h
index 4539eae..2f55b15 100644 (file)
--- a/ctree.h
+++ b/ctree.h
@@ -53,7 +53,8 @@ struct btrfs_trans_handle;
 #define BTRFS_FT_FIFO          5
 #define BTRFS_FT_SOCK          6
 #define BTRFS_FT_SYMLINK       7
-#define BTRFS_FT_MAX           8
+#define BTRFS_FT_XATTR         8
+#define BTRFS_FT_MAX           9
 
 /*
  * the key defines the order in the tree, and so it also defines (optimal)
@@ -216,7 +217,7 @@ struct btrfs_inline_data_item {
 
 struct btrfs_dir_item {
        struct btrfs_disk_key location;
-       __le16 flags;
+       __le16 data_len;
        __le16 name_len;
        u8 type;
 } __attribute__ ((__packed__));
@@ -339,8 +340,9 @@ struct btrfs_root {
  * the FS
  */
 #define BTRFS_INODE_ITEM_KEY           1
+#define BTRFS_XATTR_ITEM_KEY            2
 
-/* reserve 2-15 close to the inode for later flexibility */
+/* reserve 3-15 close to the inode for later flexibility */
 
 /*
  * dir items are the name -> inode pointers in a directory.  There is one
@@ -587,16 +589,6 @@ static inline void btrfs_set_item_size(struct btrfs_item *item, u32 val)
        item->size = cpu_to_le32(val);
 }
 
-static inline u16 btrfs_dir_flags(struct btrfs_dir_item *d)
-{
-       return le16_to_cpu(d->flags);
-}
-
-static inline void btrfs_set_dir_flags(struct btrfs_dir_item *d, u16 val)
-{
-       d->flags = cpu_to_le16(val);
-}
-
 static inline u8 btrfs_dir_type(struct btrfs_dir_item *d)
 {
        return d->type;
@@ -617,6 +609,16 @@ static inline void btrfs_set_dir_name_len(struct btrfs_dir_item *d, u16 val)
        d->name_len = cpu_to_le16(val);
 }
 
+static inline u16 btrfs_dir_data_len(struct btrfs_dir_item *d)
+{
+       return le16_to_cpu(d->data_len);
+}
+
+static inline void btrfs_set_dir_data_len(struct btrfs_dir_item *d, u16 val)
+{
+       d->data_len = cpu_to_le16(val);
+}
+
 static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
                                         struct btrfs_disk_key *disk)
 {
index c681beb..3c49c56 100644 (file)
@@ -82,8 +82,8 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
        }
        btrfs_cpu_key_to_disk(&dir_item->location, location);
        btrfs_set_dir_type(dir_item, type);
-       btrfs_set_dir_flags(dir_item, 0);
        btrfs_set_dir_name_len(dir_item, name_len);
+       btrfs_set_dir_data_len(dir_item, 0);
        name_ptr = (char *)(dir_item + 1);
        memcpy(name_ptr, name, name_len);
 
@@ -101,8 +101,8 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
        }
        btrfs_cpu_key_to_disk(&dir_item->location, location);
        btrfs_set_dir_type(dir_item, type);
-       btrfs_set_dir_flags(dir_item, 0);
        btrfs_set_dir_name_len(dir_item, name_len);
+       btrfs_set_dir_data_len(dir_item, 0);
        name_ptr = (char *)(dir_item + 1);
        memcpy(name_ptr, name, name_len);
 out:
index 90d5507..dd442c5 100644 (file)
@@ -31,13 +31,15 @@ static int print_dir_item(struct btrfs_item *item,
        u32 len;
        total = btrfs_item_size(item);
        while(cur < total) {
-               printf("\t\tdir index %llu flags %u type %u\n",
+               printf("\t\tdir index %llu type %u\n",
                     (unsigned long long)btrfs_disk_key_objectid(&di->location),
-                    btrfs_dir_flags(di),
                     btrfs_dir_type(di));
-               printf("\t\tname %.*s\n",
+               printf("\t\tname: %.*s\n",
                       btrfs_dir_name_len(di),(char *)(di + 1));
-               len = sizeof(*di) + btrfs_dir_name_len(di);
+               if (btrfs_dir_data_len(di))
+                       printf("\t\tdata: %.*s\n", btrfs_dir_data_len(di),
+                              (char *)((char *)(di + 1) + btrfs_dir_name_len(di)));
+               len = sizeof(*di) + btrfs_dir_name_len(di) + btrfs_dir_data_len(di);
                di = (struct btrfs_dir_item *)((char *)di + len);
                cur += len;
        }
@@ -87,6 +89,7 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l)
                        di = btrfs_item_ptr(l, i, struct btrfs_dir_item);
                        print_dir_item(l->items + i, di);
                        break;
+               case BTRFS_XATTR_ITEM_KEY:
                case BTRFS_DIR_INDEX_KEY:
                        di = btrfs_item_ptr(l, i, struct btrfs_dir_item);
                        print_dir_item(l->items + i, di);