static int cmd_device_scan(int argc, char **argv) { int i; int devstart; int all = 0; int ret = 0; optind = 0; while (1) { int c; static const struct option long_options[] = { { "all-devices", no_argument, NULL, 'd'}, { NULL, 0, NULL, 0} }; c = getopt_long(argc, argv, "d", long_options, NULL); if (c < 0) break; switch (c) { case 'd': all = 1; break; default: usage(cmd_device_scan_usage); } } devstart = optind; if (all && check_argc_max(argc - optind, 1)) usage(cmd_device_scan_usage); if (all || argc - optind == 0) { printf("Scanning for Btrfs filesystems\n"); ret = btrfs_scan_devices(); error_on(ret, "error %d while scanning", ret); ret = btrfs_register_all_devices(); error_on(ret, "there are %d errors while registering devices", ret); goto out; } for( i = devstart ; i < argc ; i++ ){ char *path; if (is_block_device(argv[i]) != 1) { error("not a block device: %s", argv[i]); ret = 1; goto out; } path = canonicalize_path(argv[i]); if (!path) { error("could not canonicalize path '%s': %m", argv[i]); ret = 1; goto out; } printf("Scanning for Btrfs filesystems in '%s'\n", path); if (btrfs_register_one_device(path) != 0) { ret = 1; free(path); goto out; } free(path); } out: return !!ret; }
static int cmd_scan_dev(int argc, char **argv) { int i; int devstart = 1; int all = 0; int ret = 0; optind = 1; while (1) { int c; static const struct option long_options[] = { { "all-devices", no_argument, NULL, 'd'}, { NULL, 0, NULL, 0} }; c = getopt_long(argc, argv, "d", long_options, NULL); if (c < 0) break; switch (c) { case 'd': all = 1; break; default: usage(cmd_scan_dev_usage); } } if (all && check_argc_max(argc, 2)) usage(cmd_scan_dev_usage); if (all || argc == 1) { printf("Scanning for Btrfs filesystems\n"); ret = btrfs_scan_lblkid(); if (ret) fprintf(stderr, "ERROR: error %d while scanning\n", ret); ret = btrfs_register_all_devices(); if (ret) fprintf(stderr, "ERROR: error %d while registering\n", ret); goto out; } for( i = devstart ; i < argc ; i++ ){ char *path; if (!is_block_device(argv[i])) { fprintf(stderr, "ERROR: %s is not a block device\n", argv[i]); ret = 1; goto out; } path = canonicalize_path(argv[i]); if (!path) { fprintf(stderr, "ERROR: Could not canonicalize path '%s': %s\n", argv[i], strerror(errno)); ret = 1; goto out; } printf("Scanning for Btrfs filesystems in '%s'\n", path); if (btrfs_register_one_device(path) != 0) { ret = 1; free(path); goto out; } free(path); } out: return !!ret; }