+static void splice_device_list(struct list_head *seed_devices,
+ struct list_head *all_devices)
+{
+ struct btrfs_device *in_all, *next_all;
+ struct btrfs_device *in_seed, *next_seed;
+
+ list_for_each_entry_safe(in_all, next_all, all_devices, dev_list) {
+ list_for_each_entry_safe(in_seed, next_seed, seed_devices,
+ dev_list) {
+ if (in_all->devid == in_seed->devid) {
+ /*
+ * When do dev replace in a sprout fs
+ * to a dev in its seed fs, the replacing
+ * dev will reside in the sprout fs and
+ * the replaced dev will still exist
+ * in the seed fs.
+ * So pick the latest one when showing
+ * the sprout fs.
+ */
+ if (in_all->generation
+ < in_seed->generation) {
+ list_del(&in_all->dev_list);
+ free(in_all);
+ } else if (in_all->generation
+ > in_seed->generation) {
+ list_del(&in_seed->dev_list);
+ free(in_seed);
+ }
+ break;
+ }
+ }
+ }
+
+ list_splice(seed_devices, all_devices);
+}
+
+static void print_devices(struct btrfs_fs_devices *fs_devices,
+ u64 *devs_found, unsigned unit_mode)
+{
+ struct btrfs_device *device;
+ struct btrfs_fs_devices *cur_fs;
+ struct list_head *all_devices;
+
+ all_devices = &fs_devices->devices;
+ cur_fs = fs_devices->seed;
+ /* add all devices of seed fs to the fs to be printed */
+ while (cur_fs) {
+ splice_device_list(&cur_fs->devices, all_devices);
+ cur_fs = cur_fs->seed;
+ }
+
+ list_sort(NULL, all_devices, cmp_device_id);
+ list_for_each_entry(device, all_devices, dev_list) {
+ printf("\tdevid %4llu size %s used %s path %s\n",
+ (unsigned long long)device->devid,
+ pretty_size_mode(device->total_bytes, unit_mode),
+ pretty_size_mode(device->bytes_used, unit_mode),
+ device->name);
+
+ (*devs_found)++;
+ }
+}
+
+static void print_one_uuid(struct btrfs_fs_devices *fs_devices,
+ unsigned unit_mode)