int btrfs_scan_for_fsid(struct btrfs_fs_devices *fs_devices, u64 total_devs, int run_ioctls) { return btrfs_scan_one_dir("/dev", run_ioctls); }
static int cmd_scan_dev(int argc, char **argv) { int i, fd, e; int checklist = 1; int devstart = 1; if( argc > 1 && !strcmp(argv[1],"--all-devices")){ if (check_argc_max(argc, 2)) usage(cmd_scan_dev_usage); checklist = 0; devstart += 1; } if(argc<=devstart){ int ret; printf("Scanning for Btrfs filesystems\n"); if(checklist) ret = btrfs_scan_block_devices(1); else ret = btrfs_scan_one_dir("/dev", 1); if (ret){ fprintf(stderr, "ERROR: error %d while scanning\n", ret); return 18; } return 0; } fd = open("/dev/btrfs-control", O_RDWR); if (fd < 0) { perror("failed to open /dev/btrfs-control"); return 10; } for( i = devstart ; i < argc ; i++ ){ struct btrfs_ioctl_vol_args args; int ret; printf("Scanning for Btrfs filesystems in '%s'\n", argv[i]); strncpy(args.name, argv[i], BTRFS_PATH_NAME_MAX); args.name[BTRFS_PATH_NAME_MAX-1] = 0; /* * FIXME: which are the error code returned by this ioctl ? * it seems that is impossible to understand if there no is * a btrfs filesystem from an I/O error !!! */ ret = ioctl(fd, BTRFS_IOC_SCAN_DEV, &args); e = errno; if( ret < 0 ){ close(fd); fprintf(stderr, "ERROR: unable to scan the device '%s' - %s\n", argv[i], strerror(e)); return 11; } } close(fd); return 0; }