Josef Bacik
2007-Nov-07 18:15 UTC
[Btrfs-devel] [PATCH 1/4] btrfs-progs changes for xattr support
Hello, This patch changes the dir_item structure to handle xattrs, as well as make print-tree spit out info about xattrs it finds. Thank you, Josef diff -r f4810b8d5822 ctree.h --- a/ctree.h Wed Aug 29 15:56:44 2007 -0400 +++ b/ctree.h Fri Oct 12 22:33:06 2007 -0500 @@ -52,6 +52,7 @@ struct btrfs_trans_handle; #define BTRFS_FT_SOCK 6 #define BTRFS_FT_SYMLINK 7 #define BTRFS_FT_MAX 8 +#define BTRFS_FT_XATTR 9 /* * the key defines the order in the tree, and so it also defines (optimal) @@ -211,7 +212,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__)); @@ -322,8 +323,9 @@ struct btrfs_root { * the FS */ #define BTRFS_INODE_ITEM_KEY 1 - -/* reserve 2-15 close to the inode for later flexibility */ +#define BTRFS_XATTR_ITEM_KEY 2 + +/* reserve 3-15 close to the inode for later flexibility */ /* * dir items are the name -> inode pointers in a directory. There is one @@ -570,16 +572,6 @@ static inline void btrfs_set_item_size(s item->size = cpu_to_le16(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; @@ -598,6 +590,16 @@ static inline void btrfs_set_dir_name_le 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, diff -r f4810b8d5822 dir-item.c --- a/dir-item.c Wed Aug 29 15:56:44 2007 -0400 +++ b/dir-item.c Thu Nov 08 04:01:38 2007 -0500 @@ -83,8 +83,8 @@ int btrfs_insert_dir_item(struct btrfs_t } 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); @@ -102,8 +102,8 @@ int btrfs_insert_dir_item(struct btrfs_t } 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: diff -r f4810b8d5822 print-tree.c --- a/print-tree.c Wed Aug 29 15:56:44 2007 -0400 +++ b/print-tree.c Fri Oct 12 22:53:51 2007 -0500 @@ -31,13 +31,12 @@ static int print_dir_item(struct btrfs_i 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); + 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 +86,10 @@ void btrfs_print_leaf(struct btrfs_root print_dir_item(l->items + i, di); break; case BTRFS_DIR_INDEX_KEY: + di = btrfs_item_ptr(l, i, struct btrfs_dir_item); + print_dir_item(l->items + i, di); + break; + case BTRFS_XATTR_ITEM_KEY: di = btrfs_item_ptr(l, i, struct btrfs_dir_item); print_dir_item(l->items + i, di); break;
Zach Brown
2007-Nov-08 09:55 UTC
[Btrfs-devel] [PATCH 1/4] btrfs-progs changes for xattr support
> @@ -87,6 +86,10 @@ void btrfs_print_leaf(struct btrfs_root > print_dir_item(l->items + i, di); > break; > case BTRFS_DIR_INDEX_KEY: > + di = btrfs_item_ptr(l, i, struct btrfs_dir_item); > + print_dir_item(l->items + i, di); > + break; > + case BTRFS_XATTR_ITEM_KEY: > di = btrfs_item_ptr(l, i, struct btrfs_dir_item); > print_dir_item(l->items + i, di); > break;It seems like that should just add the new 'case BTRFS_XATTR_ITEM_KEY:' to use the existing code for the DIR_INDEX instead of duplicating the code. - z