From fac44aba047abf1fb590726c1a1dc0956eb7fad1 Mon Sep 17 00:00:00 2001 From: Nikolay Borisov Date: Thu, 16 May 2019 16:12:49 +0300 Subject: [PATCH] btrfs-progs: Correctly open filesystem on image file When btrfs' 'filesystem' subcommand is passed path to an image file it currently fails since the code expects the image file is going to be recognised by libblkid (called from btrfs_scan_devices()). This is not the case since libblkid only scan well-known locations under /dev. Fix this by explicitly calling open_ctree which will correctly open the image and add it to the correct btrfs_fs_devices struct. This allows subsequent cmd_filesystem_show logic to correctly show requested information. Issue: #169 Reviewed-by: Qu Wenruo Signed-off-by: Nikolay Borisov Signed-off-by: David Sterba --- cmds-filesystem.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 9f7bb343..c4e43f84 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -774,7 +774,18 @@ static int cmd_filesystem_show(int argc, char **argv) goto out; devs_only: - ret = btrfs_scan_devices(); + if (type == BTRFS_ARG_REG) { + /* + * We don't close the fs_info because it will free the device, + * this is not a long-running process so it's fine + */ + if (open_ctree(search, btrfs_sb_offset(0), 0)) + ret = 0; + else + ret = 1; + } else { + ret = btrfs_scan_devices(); + } if (ret) { error("blkid device scan returned %d", ret);