All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: btrfs-sb-mod add devid to the modifiable list
@ 2020-10-07 10:08 Anand Jain
  2020-10-19 18:39 ` David Sterba
  0 siblings, 1 reply; 3+ messages in thread
From: Anand Jain @ 2020-10-07 10:08 UTC (permalink / raw)
  To: linux-btrfs

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>
---
 btrfs-sb-mod.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/btrfs-sb-mod.c b/btrfs-sb-mod.c
index ad143ca05aa6..832e29d29710 100644
--- a/btrfs-sb-mod.c
+++ b/btrfs-sb-mod.c
@@ -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;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs-progs: btrfs-sb-mod add devid to the modifiable list
  2020-10-07 10:08 [PATCH] btrfs-progs: btrfs-sb-mod add devid to the modifiable list Anand Jain
@ 2020-10-19 18:39 ` David Sterba
  2020-10-20  7:01   ` Anand Jain
  0 siblings, 1 reply; 3+ messages in thread
From: David Sterba @ 2020-10-19 18:39 UTC (permalink / raw)
  To: Anand Jain; +Cc: linux-btrfs

On Wed, Oct 07, 2020 at 06:08:05PM +0800, Anand Jain wrote:
> We need this patch to create a crafted image with bogus devid.
> 
> For example:
> ./btrfs-sb-mod devid =0

This should maintain some parity with the output of 'dump-super', ie.
this should have dev_item. prefix. There's also total_size for a device
and this could be confusing with the superblock total_size. I'll fix it
and add the remaining dev_item members as well.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs-progs: btrfs-sb-mod add devid to the modifiable list
  2020-10-19 18:39 ` David Sterba
@ 2020-10-20  7:01   ` Anand Jain
  0 siblings, 0 replies; 3+ messages in thread
From: Anand Jain @ 2020-10-20  7:01 UTC (permalink / raw)
  To: dsterba; +Cc: linux-btrfs

On 20/10/20 2:39 am, David Sterba wrote:
> On Wed, Oct 07, 2020 at 06:08:05PM +0800, Anand Jain wrote:
>> We need this patch to create a crafted image with bogus devid.
>>
>> For example:
>> ./btrfs-sb-mod devid =0
> 
> This should maintain some parity with the output of 'dump-super', ie.
> this should have dev_item. prefix.

  Ah. dev_item.devid  is nice.

> There's also total_size for a device
> and this could be confusing with the superblock total_size.
> I'll fix it
> and add the remaining dev_item members as well.

  Ok. Looks good.

Reviewed-by: Anand Jain <anand.jain@oracle.com>

  f0b3cf9e3224 btrfs-progs: sb-mod: add syntax to the help text
  bd873c39d3da btrfs-progs: sb-mod: add remaining dev_item members
  5cee4e5a7d2d btrfs-progs: sb-mod: add dev_item prefix for sb::device 
members


Thanks, Anand

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-20  7:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-07 10:08 [PATCH] btrfs-progs: btrfs-sb-mod add devid to the modifiable list Anand Jain
2020-10-19 18:39 ` David Sterba
2020-10-20  7:01   ` Anand Jain

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.