summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-04-18 10:45:17 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2008-04-18 10:45:17 -0400
commit0e08036ee4292cb230ce3fb8b8c59407faac7747 (patch)
treefe0755f4ff584578b663e96d4b226b98a4e2099a /utils.c
parent734603d9272da5a54c5aa0d688a63193e102fc28 (diff)
Add checks to avoid adding the same device twice during mkfs
Diffstat (limited to 'utils.c')
-rw-r--r--utils.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/utils.c b/utils.c
index ba9c7fbb..b9d85ac0 100644
--- a/utils.c
+++ b/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);
}
+
+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;
+}