summaryrefslogtreecommitdiff
path: root/btrfs-corrupt-block.c
diff options
context:
space:
mode:
authorNikolay Borisov <nborisov@suse.com>2018-05-14 14:13:28 +0300
committerDavid Sterba <dsterba@suse.com>2018-06-07 16:37:39 +0200
commit572637b6f95cd9dd7be658ea2d18718d04c4ac17 (patch)
treee214b91a2d04252844bae568c0279b9cefc611b9 /btrfs-corrupt-block.c
parent04be0e4b19627e9e4d7295d89c58ca08f6a04f9f (diff)
btrfs-progs: corrupt-block: Factor out key parsing function
Currently passing a key with -K handling is open coded. I intend on changing the interface a bit to make the program more usable. To aid in this factor out common code which parses a triplet of the "u64,u8,u64" format, corresponding to a btrfs key. No functional changes. Signed-off-by: Nikolay Borisov <nborisov@suse.com> [ print optarg too ] Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'btrfs-corrupt-block.c')
-rw-r--r--btrfs-corrupt-block.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index b2ec5dea..f115ca53 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -1081,6 +1081,16 @@ out:
}
+static void parse_key(u64 *objectid, u8 *type, u64 *offset)
+{
+
+ int ret = sscanf(optarg, "%llu,%hhu,%llu", objectid, type, offset);
+ if (ret != 3) {
+ fprintf(stderr, "error parsing key '%s': %d\n", optarg, errno);
+ print_usage(1);
+ }
+}
+
static struct btrfs_root *open_root(struct btrfs_fs_info *fs_info,
u64 root_objectid)
{