diff options
author | Josef Bacik <jbacik@fb.com> | 2014-10-31 14:01:26 -0400 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2014-11-14 11:00:43 +0100 |
commit | 2dc4c0015ffc0ec1ff47ef1eda51659dae98f195 (patch) | |
tree | 3a197a3187ba1d1c9f112330f9c1b2753d2eb777 /cmds-check.c | |
parent | 2d80d0d645d1b72523ab4d8bf053ad91c90665ca (diff) |
Btrfs-progs: add ability to replace missing dir item/dir indexes
If we have everything except the dir item and dir index we can easily replace
them, so add this ability to btrfsck. Thanks,
Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'cmds-check.c')
-rw-r--r-- | cmds-check.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/cmds-check.c b/cmds-check.c index 923fb10c..f42e3c5c 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -1772,6 +1772,33 @@ static int repair_inode_backrefs(struct btrfs_root *root, } } + if (!delete && (!backref->found_dir_index && + !backref->found_dir_item && + backref->found_inode_ref)) { + struct btrfs_trans_handle *trans; + struct btrfs_key location; + + location.objectid = rec->ino; + location.type = BTRFS_INODE_ITEM_KEY; + location.offset = 0; + + trans = btrfs_start_transaction(root, 1); + if (IS_ERR(trans)) { + ret = PTR_ERR(trans); + break; + } + fprintf(stderr, "adding missing dir index/item pair " + "for inode %llu\n", + (unsigned long long)rec->ino); + ret = btrfs_insert_dir_item(trans, root, backref->name, + backref->namelen, + backref->dir, &location, + imode_to_type(rec->imode), + backref->index); + BUG_ON(ret); + btrfs_commit_transaction(trans, root); + repaired++; + } } return ret ? ret : repaired; } |