forked from Mirrors/btrfs-progs
Add checks to avoid adding the same device twice during mkfs
parent
734603d927
commit
0e08036ee4
8
mkfs.c
8
mkfs.c
|
@ -430,6 +430,14 @@ int main(int ac, char **av)
|
||||||
fprintf(stderr, "unable to open %s\n", file);
|
fprintf(stderr, "unable to open %s\n", file);
|
||||||
exit(1);
|
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,
|
ret = btrfs_prepare_device(fd, file, zero_end,
|
||||||
&dev_block_count);
|
&dev_block_count);
|
||||||
|
|
||||||
|
|
31
utils.c
31
utils.c
|
@ -743,3 +743,34 @@ int btrfs_scan_for_fsid(struct btrfs_fs_devices *fs_devices, u64 total_devs,
|
||||||
{
|
{
|
||||||
return btrfs_scan_one_dir("/dev", run_ioctls);
|
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;
|
||||||
|
}
|
||||||
|
|
2
utils.h
2
utils.h
|
@ -37,4 +37,6 @@ int btrfs_scan_for_fsid(struct btrfs_fs_devices *fs_devices, u64 total_devs,
|
||||||
int btrfs_register_one_device(char *fname);
|
int btrfs_register_one_device(char *fname);
|
||||||
int btrfs_scan_one_dir(char *dirname, int run_ioctl);
|
int btrfs_scan_one_dir(char *dirname, int run_ioctl);
|
||||||
int check_mounted(char *devicename);
|
int check_mounted(char *devicename);
|
||||||
|
int btrfs_device_already_in_root(struct btrfs_root *root, int fd,
|
||||||
|
int super_offset);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue