Add checks to avoid adding the same device twice during mkfs

master
Chris Mason 2008-04-18 10:45:17 -04:00 committed by David Woodhouse
parent 734603d927
commit 0e08036ee4
3 changed files with 41 additions and 0 deletions

8
mkfs.c
View File

@ -430,6 +430,14 @@ int main(int ac, char **av)
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);

31
utils.c
View File

@ -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);
}
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;
}

View File

@ -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_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