+ device = list_first_entry(&fs_devices->devices, struct btrfs_device,
+ dev_list);
+
+ dev_cnt_total = device->total_devs;
+
+ list_for_each_entry(device, &fs_devices->devices, dev_list)
+ dev_cnt++;
+
+ return dev_cnt_total != dev_cnt;
+}
+
+static int search_umounted_fs_uuids(struct list_head *all_uuids,
+ char *search, int *found)
+{
+ struct btrfs_fs_devices *cur_fs, *fs_copy;
+ struct list_head *fs_uuids;
+ int ret = 0;
+
+ fs_uuids = btrfs_scanned_uuids();
+
+ /*
+ * The fs_uuids list is global, and open_ctree_* will
+ * modify it, make a private copy here
+ */
+ list_for_each_entry(cur_fs, fs_uuids, list) {
+ /* don't bother handle all fs, if search target specified */
+ if (search) {
+ if (uuid_search(cur_fs, search) == 0)
+ continue;
+ if (found)
+ *found = 1;
+ }
+
+ /* skip all fs already shown as mounted fs */
+ if (is_seen_fsid(cur_fs->fsid, seen_fsid_hash))
+ continue;
+
+ fs_copy = calloc(1, sizeof(*fs_copy));
+ if (!fs_copy) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ ret = copy_fs_devices(fs_copy, cur_fs);
+ if (ret) {
+ free(fs_copy);
+ goto out;
+ }
+
+ list_add(&fs_copy->list, all_uuids);
+ }
+
+out:
+ return ret;
+}
+
+static int map_seed_devices(struct list_head *all_uuids)
+{
+ struct btrfs_fs_devices *cur_fs, *cur_seed;
+ struct btrfs_fs_devices *seed_copy;
+ struct btrfs_fs_devices *opened_fs;
+ struct btrfs_device *device;
+ struct btrfs_fs_info *fs_info;
+ struct list_head *fs_uuids;
+ int ret = 0;
+
+ fs_uuids = btrfs_scanned_uuids();
+
+ list_for_each_entry(cur_fs, all_uuids, list) {
+ device = list_first_entry(&cur_fs->devices,
+ struct btrfs_device, dev_list);
+ if (!device)
+ continue;
+
+ /* skip fs without seeds */
+ if (!has_seed_devices(cur_fs))
+ continue;
+
+ /*
+ * open_ctree_* detects seed/sprout mapping
+ */
+ fs_info = open_ctree_fs_info(device->name, 0, 0, 0,
+ OPEN_CTREE_PARTIAL);
+ if (!fs_info)
+ continue;
+
+ /*
+ * copy the seed chain under the opened fs
+ */
+ opened_fs = fs_info->fs_devices;
+ cur_seed = cur_fs;
+ while (opened_fs->seed) {
+ seed_copy = malloc(sizeof(*seed_copy));
+ if (!seed_copy) {
+ ret = -ENOMEM;
+ goto fail_out;
+ }
+ ret = find_and_copy_seed(opened_fs->seed, seed_copy,
+ fs_uuids);
+ if (ret) {
+ free(seed_copy);
+ goto fail_out;
+ }
+
+ cur_seed->seed = seed_copy;
+
+ opened_fs = opened_fs->seed;
+ cur_seed = cur_seed->seed;
+ }
+
+ close_ctree(fs_info->chunk_root);
+ }