btrfs-progs: corrupt generic item data with btrfs-corrupt-block
Sweet Tea Dorminy
Reviewed-byQuoted 7 lines
(quoted diff) +0
-1- printf("\t-I <u64,u8,u64> Corrupt an item corresponding to thepassed key triplet (must also specify the field to corrupt and root for the item)\n");
(quoted diff) +1
-0+ printf("\t-I <u64,u8,u64> Corrupt an item corresponding to thepassed key triplet (must also specify the field, or bytes, offset, and value to corrupt and root for the item)\n");
I'd find it a little more understandable, even though I know it's not intended to be read often, as:
+ printf("\t-I <u64,u8,u64> Corrupt an item corresponding to the passed key triplet (must also specify the field, or (bytes, offset, value) tuple, to corrupt, and root for the item)\n");
Review
Quoted 2 lines
(quoted diff) +2
-0+ data = btrfs_item_ptr(leaf, slot, void); + // TODO: check offset/size legitimacy
Is it worth fixing this todo?
I'd prefer if there was a check that the existing data at the offset isn't the same as the new value, so as to ensure we notice if we're failing to corrupt.
Review
Quoted 3 lines
(quoted diff) +3
-0+ case 'v': + bogus_value = arg_strtou64(optarg); + break;
You're parsing, and storing here, a u64; meanwhile corrupt_btrfs_item_data() takes a char bogus_value. I think it probably makes sense to only parse and store a char, but
Review
Quoted 3 lines
(quoted diff) +3
-0+ else if (bogus_offset != (u64)-1 && + bytes != (u64)-1 && + bogus_value != (u64)-1)
Might be worth calling out (u64)-1 as #define UNSET_VALUE for easier readability?
Review
Quoted 5 lines
(quoted diff) +5
-0+ ret = corrupt_btrfs_item_data(target_root, &key, + bogus_offset, bytes, + bogus_value); + else + print_usage(1);
Maybe add an extra message here to say that either field or all of offset, bytes, and value have to be set?