btrfs-progs: restore: check if specified root is fs/file tree firstly
authorWang Shilong <wangsl.fnst@cn.fujitsu.com>
Thu, 19 Jun 2014 01:27:05 +0000 (09:27 +0800)
committerDavid Sterba <dsterba@suse.cz>
Fri, 22 Aug 2014 12:43:09 +0000 (14:43 +0200)
Steps to reproduce:
 # mkfs.btrfs -f /dev/sda9
 # mount /dev/sda9 /mnt
 # dd if=/dev/zero of=/mnt/data bs=1M count=1
 # btrfs restore -r /dev/sda9 -r 2 -o /tmp

If users don't input a valid fs/file root objectid, btrfs restore still
continue and don't restore anything, this is unfriendly, we could
check it firstly.

Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
cmds-restore.c

index 4338493..c84ac17 100644 (file)
@@ -1186,6 +1186,11 @@ int cmd_restore(int argc, char **argv)
                                break;
                        case 'r':
                                root_objectid = arg_strtou64(optarg);
+                               if (!is_fstree(root_objectid)) {
+                                       fprintf(stderr, "objectid %llu is not a valid fs/file tree\n",
+                                                       root_objectid);
+                                       exit(1);
+                               }
                                break;
                        case 'l':
                                list_roots = 1;