summaryrefslogtreecommitdiff
path: root/btrfs-corrupt-block.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.cz>2015-02-10 15:17:10 +0100
committerDavid Sterba <dsterba@suse.cz>2015-02-10 15:17:33 +0100
commit478a4f21e480096b6c2f54ee5dd6421a557f26ab (patch)
tree77ef50db2046f1977caea9dd93f345b1fb7163b1 /btrfs-corrupt-block.c
parent8fa8156a0e8dc60403d3a182532ed0c0e5bcb287 (diff)
parent4915964fc653033189c733ec738b4b23c87b9e5d (diff)
Merge remote-tracking branch 'remotes/josef/for-kdave' into v3.19.x
"This series of patches fixes up btrfsck in lots of ways and adds some new functionality. These patches were required to fix Hugo's broken multi-disk fs as well as fix fsck so it would actually pass all of the fsck tests. This also fixes a long standing btrfs-image problem where it wouldn't restore multi disk images onto a single disk properly."
Diffstat (limited to 'btrfs-corrupt-block.c')
-rw-r--r--btrfs-corrupt-block.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index 5db18a18..f332bdf7 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -109,6 +109,7 @@ static void print_usage(void)
"to corrupt and a root+key for the item)\n");
fprintf(stderr, "\t-D Corrupt a dir item, must specify key and field\n");
fprintf(stderr, "\t-d Delete this item (must specify -K)\n");
+ fprintf(stderr, "\t-r Operate on this root (only works with -d)\n");
exit(1);
}
@@ -1007,6 +1008,7 @@ int main(int ac, char **av)
u64 metadata_block = 0;
u64 inode = 0;
u64 file_extent = (u64)-1;
+ u64 root_objectid = 0;
char field[FIELD_BUF_LEN];
field[0] = '\0';
@@ -1034,11 +1036,12 @@ int main(int ac, char **av)
{ "item", 0, NULL, 'I'},
{ "dir-item", 0, NULL, 'D'},
{ "delete", 0, NULL, 'd'},
+ { "root", 0, NULL, 'r'},
{ NULL, 0, NULL, 0 }
};
- c = getopt_long(ac, av, "l:c:b:eEkuUi:f:x:m:K:IDd", long_options,
- &option_index);
+ c = getopt_long(ac, av, "l:c:b:eEkuUi:f:x:m:K:IDdr:",
+ long_options, &option_index);
if (c < 0)
break;
switch(c) {
@@ -1098,6 +1101,9 @@ int main(int ac, char **av)
case 'd':
delete = 1;
break;
+ case 'r':
+ root_objectid = arg_strtou64(optarg);
+ break;
default:
print_usage();
}
@@ -1206,9 +1212,25 @@ int main(int ac, char **av)
ret = corrupt_btrfs_item(root, &key, field);
}
if (delete) {
+ struct btrfs_root *target = root;
+
if (!key.objectid)
print_usage();
- ret = delete_item(root, &key);
+ if (root_objectid) {
+ struct btrfs_key root_key;
+
+ root_key.objectid = root_objectid;
+ root_key.type = BTRFS_ROOT_ITEM_KEY;
+ root_key.offset = (u64)-1;
+
+ target = btrfs_read_fs_root(root->fs_info, &root_key);
+ if (IS_ERR(target)) {
+ fprintf(stderr, "Couldn't find root %llu\n",
+ (unsigned long long)root_objectid);
+ print_usage();
+ }
+ }
+ ret = delete_item(target, &key);
goto out_close;
}
if (key.objectid || key.offset || key.type) {