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 <wqu@suse.com>
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
master
Nikolay Borisov 2019-05-16 16:12:49 +03:00 committed by David Sterba
parent 48248693cd
commit fac44aba04
1 changed files with 12 additions and 1 deletions

View File

@ -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);