From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH] btrfs-progs: btrfs-sb-mod add devid to the modifiable list
Date: Wed, 7 Oct 2020 18:08:05 +0800 [thread overview]
Message-ID: <8c8c3cbe61cc62d8a5f09ca497d6e88a0a1cd74d.1602065251.git.anand.jain@oracle.com> (raw)
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
next reply other threads:[~2020-10-07 10:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-07 10:08 Anand Jain [this message]
2020-10-19 18:39 ` [PATCH] btrfs-progs: btrfs-sb-mod add devid to the modifiable list David Sterba
2020-10-20 7:01 ` Anand Jain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8c8c3cbe61cc62d8a5f09ca497d6e88a0a1cd74d.1602065251.git.anand.jain@oracle.com \
--to=anand.jain@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).