From fba66bd8652b954be7e98699d81c8e57222b77e4 Mon Sep 17 00:00:00 2001 From: Chris Mason Date: Wed, 12 Dec 2007 14:39:36 -0500 Subject: [PATCH] Add back pointers from the inode to the directory that referenced it --- ctree.h | 12 +++++++++++- print-tree.c | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/ctree.h b/ctree.h index 174fb239..adf09735 100644 --- a/ctree.h +++ b/ctree.h @@ -192,6 +192,11 @@ struct btrfs_extent_ref { __le64 offset; } __attribute__ ((__packed__)); +struct btrfs_inode_ref { + __le16 name_len; + /* name goes here */ +} __attribute__ ((__packed__)); + struct btrfs_inode_timespec { __le64 sec; __le32 nsec; @@ -352,7 +357,8 @@ struct btrfs_root { * the FS */ #define BTRFS_INODE_ITEM_KEY 1 -#define BTRFS_XATTR_ITEM_KEY 2 +#define BTRFS_INODE_REF_KEY 2 +#define BTRFS_XATTR_ITEM_KEY 8 /* reserve 3-15 close to the inode for later flexibility */ @@ -556,6 +562,10 @@ static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts, BTRFS_SETGET_STACK_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32); +BTRFS_SETGET_STACK_FUNCS(inode_ref_name_len, struct btrfs_inode_ref, + name_len, 16); + + BTRFS_SETGET_STACK_FUNCS(ref_root, struct btrfs_extent_ref, root, 64); BTRFS_SETGET_STACK_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64); diff --git a/print-tree.c b/print-tree.c index 9c85f638..60cf27cf 100644 --- a/print-tree.c +++ b/print-tree.c @@ -45,6 +45,24 @@ static int print_dir_item(struct btrfs_item *item, } return 0; } + +static int print_inode_ref_item(struct btrfs_item *item, + struct btrfs_inode_ref *ref) +{ + u32 total; + u32 cur = 0; + u32 len; + total = btrfs_item_size(item); + while(cur < total) { + len = btrfs_inode_ref_name_len(ref); + printf("\t\tinode ref name: %.*s\n", len, (char *)(ref + 1)); + len += sizeof(*ref); + ref = (struct btrfs_inode_ref *)((char *)ref + len); + cur += len; + } + return 0; +} + void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l) { int i; @@ -58,6 +76,7 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l) struct btrfs_csum_item *ci; struct btrfs_block_group_item *bi; struct btrfs_extent_ref *ref; + struct btrfs_inode_ref *iref; u32 type; printf("leaf %llu ptrs %d free space %d generation %llu owner %llu\n", @@ -86,6 +105,10 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l) btrfs_inode_mode(ii), btrfs_inode_nlink(ii)); break; + case BTRFS_INODE_REF_KEY: + iref = btrfs_item_ptr(l, i, struct btrfs_inode_ref); + print_inode_ref_item(l->items + i, iref); + break; case BTRFS_DIR_ITEM_KEY: di = btrfs_item_ptr(l, i, struct btrfs_dir_item); print_dir_item(l->items + i, di);