btrfs-progs: sb-mod: add devid to the modifiable list
We need this patch to create a crafted image with bogus devid. For example: ./btrfs-sb-mod devid =0 Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
4179885cf9
commit
c875145cb3
|
@ -139,6 +139,7 @@ struct sb_field {
|
|||
{ .name = "log_root_level", .type = TYPE_U8 },
|
||||
{ .name = "cache_generation", .type = TYPE_U64 },
|
||||
{ .name = "uuid_tree_generation", .type = TYPE_U64 },
|
||||
{ .name = "devid", .type = TYPE_U64 },
|
||||
};
|
||||
|
||||
#define MOD_FIELD_XX(fname, set, val, bits, f_dec, f_hex, f_type) \
|
||||
|
@ -154,11 +155,28 @@ struct sb_field {
|
|||
} \
|
||||
}
|
||||
|
||||
#define MOD_DEV_FIELD_XX(fname, set, val, bits, f_dec, f_hex, f_type) \
|
||||
else if (strcmp(name, #fname) == 0) { \
|
||||
if (set) { \
|
||||
printf("SET: "#fname" "f_dec" (0x"f_hex")\n", \
|
||||
(f_type)*val, (f_type)*val); \
|
||||
sb->dev_item.fname = cpu_to_le##bits(*val); \
|
||||
} else { \
|
||||
*val = le##bits##_to_cpu(sb->dev_item.fname); \
|
||||
printf("GET: "#fname" "f_dec" (0x"f_hex")\n", \
|
||||
(f_type)*val, (f_type)*val); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define MOD_FIELD64(fname, set, val) \
|
||||
MOD_FIELD_XX(fname, set, val, 64, "%llu", "%llx", unsigned long long)
|
||||
|
||||
#define MOD_DEV_FIELD64(fname, set, val) \
|
||||
MOD_DEV_FIELD_XX(fname, set, val, 64, "%llu", "%llx", unsigned long long)
|
||||
|
||||
/* Alias for u64 */
|
||||
#define MOD_FIELD(fname, set, val) MOD_FIELD64(fname, set, val)
|
||||
#define MOD_DEV_FIELD(fname, set, val) MOD_DEV_FIELD64(fname, set, val)
|
||||
|
||||
/*
|
||||
* Support only GET and SET properly, ADD and SUB may work
|
||||
|
@ -202,6 +220,7 @@ static void mod_field_by_name(struct btrfs_super_block *sb, int set, const char
|
|||
MOD_FIELD8(log_root_level, set, val)
|
||||
MOD_FIELD(cache_generation, set, val)
|
||||
MOD_FIELD(uuid_tree_generation, set, val)
|
||||
MOD_DEV_FIELD(devid, set, val)
|
||||
else {
|
||||
printf("ERROR: unhandled field: %s\n", name);
|
||||
exit(1);
|
||||
|
@ -260,7 +279,8 @@ static int arg_to_op_value(const char *arg, enum field_op *op, u64 *val)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
loff_t off;
|
||||
int ret;
|
||||
|
|
Loading…
Reference in New Issue