diff mbox series

[2/3] btrfs-progs: Correctly identify fs on image files in "filesystem" subcommands

Message ID 20190516084250.19363-3-nborisov@suse.com (mailing list archive)
State New, archived
Headers show
Series Fix "filesystem" command when fs is on file image | expand

Commit Message

Nikolay Borisov May 16, 2019, 8:42 a.m. UTC
Currently if a new filesystem is created and interrogated with we get
an error:

    truncate -s 3g btrfs.img
    mkfs.btrfs btrfs.img
    btrfs fi show btrfs.img
    ERROR: not a valid btrfs filesystem: /root/btrfs.img

The reason is that the image is not automatically recognised by libblkid
meaning btrfs_scan_devices will not "see" the device, resulting in the
aofrementioned error.

Fix it by detecting when this condition occurs and pass the path to the
file to btrfs_scan_devices, which will correctly add it to libblkid's
cache.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 cmds-filesystem.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 4657deb20fde..0327563154d5 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -771,8 +771,7 @@  static int cmd_filesystem_show(int argc, char **argv)
 		goto out;
 
 devs_only:
-	ret = btrfs_scan_devices(NULL);
-
+	ret = btrfs_scan_devices(type == BTRFS_ARG_REG ? search : NULL);
 	if (ret) {
 		error("blkid device scan returned %d", ret);
 		return 1;