fprintf(stderr, "unable to open %s\n", file);
exit(1);
}
+ ret = btrfs_device_already_in_root(root, fd,
+ BTRFS_SUPER_INFO_OFFSET);
+ if (ret) {
+ fprintf(stderr, "skipping duplicate device %s in FS\n",
+ file);
+ close(fd);
+ continue;
+ }
ret = btrfs_prepare_device(fd, file, zero_end,
&dev_block_count);
{
return btrfs_scan_one_dir("/dev", run_ioctls);
}
+
+int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
+ int super_offset)
+{
+ struct btrfs_super_block *disk_super;
+ char *buf;
+ int ret = 0;
+
+ buf = malloc(BTRFS_SUPER_INFO_SIZE);
+ if (!buf) {
+ ret = -ENOMEM;
+ goto out;
+ }
+ ret = pread(fd, buf, BTRFS_SUPER_INFO_SIZE, super_offset);
+ if (ret != BTRFS_SUPER_INFO_SIZE)
+ goto brelse;
+
+ ret = 0;
+ disk_super = (struct btrfs_super_block *)buf;
+ if (strncmp((char *)(&disk_super->magic), BTRFS_MAGIC,
+ sizeof(disk_super->magic)))
+ goto brelse;
+
+ if (!memcmp(disk_super->fsid, root->fs_info->super_copy.fsid,
+ BTRFS_FSID_SIZE))
+ ret = 1;
+brelse:
+ free(buf);
+out:
+ return ret;
+}
int btrfs_register_one_device(char *fname);
int btrfs_scan_one_dir(char *dirname, int run_ioctl);
int check_mounted(char *devicename);
+int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
+ int super_offset);
#endif