mirror of
https://github.com/kdave/btrfs-progs
synced 2025-01-28 08:22:46 +00:00
btrfs-progs: corrupt-block: Factor out common "-r" handling code
Since more and more of the "corrupt XXX" options are going to support combination with -r option, let's extract the common code needed for this. No functional changes. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
f7a27396cf
commit
32acc8eed2
@ -1114,7 +1114,7 @@ int main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
struct cache_tree root_cache;
|
struct cache_tree root_cache;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
struct btrfs_root *root;
|
struct btrfs_root *root, *target_root;
|
||||||
char *dev;
|
char *dev;
|
||||||
/* chunk offset can be 0,so change to (u64)-1 */
|
/* chunk offset can be 0,so change to (u64)-1 */
|
||||||
u64 logical = (u64)-1;
|
u64 logical = (u64)-1;
|
||||||
@ -1245,6 +1245,10 @@ int main(int argc, char **argv)
|
|||||||
fprintf(stderr, "Open ctree failed\n");
|
fprintf(stderr, "Open ctree failed\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
target_root = root;
|
||||||
|
if (root_objectid)
|
||||||
|
target_root = open_root(root->fs_info, root_objectid);
|
||||||
|
|
||||||
if (extent_rec) {
|
if (extent_rec) {
|
||||||
struct btrfs_trans_handle *trans;
|
struct btrfs_trans_handle *trans;
|
||||||
|
|
||||||
@ -1342,26 +1346,19 @@ int main(int argc, char **argv)
|
|||||||
goto out_close;
|
goto out_close;
|
||||||
}
|
}
|
||||||
if (corrupt_item) {
|
if (corrupt_item) {
|
||||||
struct btrfs_root *target;
|
|
||||||
if (!key.objectid)
|
if (!key.objectid)
|
||||||
print_usage(1);
|
print_usage(1);
|
||||||
if (!root_objectid)
|
if (!root_objectid)
|
||||||
print_usage(1);
|
print_usage(1);
|
||||||
|
|
||||||
target = open_root(root->fs_info, root_objectid);
|
ret = corrupt_btrfs_item(target_root, &key, field);
|
||||||
|
|
||||||
ret = corrupt_btrfs_item(target, &key, field);
|
|
||||||
goto out_close;
|
goto out_close;
|
||||||
}
|
}
|
||||||
if (delete) {
|
if (delete) {
|
||||||
struct btrfs_root *target = root;
|
|
||||||
|
|
||||||
if (!key.objectid)
|
if (!key.objectid)
|
||||||
print_usage(1);
|
print_usage(1);
|
||||||
if (root_objectid)
|
|
||||||
target = open_root(root->fs_info, root_objectid);
|
|
||||||
|
|
||||||
ret = delete_item(target, &key);
|
ret = delete_item(target_root, &key);
|
||||||
goto out_close;
|
goto out_close;
|
||||||
}
|
}
|
||||||
if (should_corrupt_key) {
|
if (should_corrupt_key) {
|
||||||
|
Loading…
Reference in New Issue
Block a user