+static const char * const cmd_device_usage_usage[] = {
+ "btrfs device usage [options] <path> [<path>..]",
+ "Show detailed information about internal allocations in devices.",
+ HELPINFO_UNITS_SHORT_LONG,
+ NULL
+};
+
+static int _cmd_device_usage(int fd, char *path, unsigned unit_mode)
+{
+ int i;
+ int ret = 0;
+ struct chunk_info *chunkinfo = NULL;
+ struct device_info *devinfo = NULL;
+ int chunkcount = 0;
+ int devcount = 0;
+
+ ret = load_chunk_and_device_info(fd, &chunkinfo, &chunkcount, &devinfo,
+ &devcount);
+ if (ret)
+ goto out;
+
+ for (i = 0; i < devcount; i++) {
+ printf("%s, ID: %llu\n", devinfo[i].path, devinfo[i].devid);
+ print_device_sizes(&devinfo[i], unit_mode);
+ print_device_chunks(&devinfo[i], chunkinfo, chunkcount,
+ unit_mode);
+ printf("\n");
+ }
+
+out:
+ free(devinfo);
+ free(chunkinfo);
+
+ return ret;
+}
+
+static int cmd_device_usage(int argc, char **argv)
+{
+ unsigned unit_mode;
+ int ret = 0;
+ int i;
+
+ unit_mode = get_unit_mode_from_arg(&argc, argv, 1);
+
+ clean_args_no_options(argc, argv, cmd_device_usage_usage);
+
+ if (check_argc_min(argc - optind, 1))
+ usage(cmd_device_usage_usage);
+
+ for (i = optind; i < argc; i++) {
+ int fd;
+ DIR *dirstream = NULL;
+
+ if (i > 1)
+ printf("\n");
+
+ fd = btrfs_open_dir(argv[i], &dirstream, 1);
+ if (fd < 0) {
+ ret = 1;
+ break;
+ }
+
+ ret = _cmd_device_usage(fd, argv[i], unit_mode);
+ close_file_or_dir(fd, dirstream);
+
+ if (ret)
+ break;
+ }
+
+ return !!ret;
+}
+
+static const char device_cmd_group_info[] =
+"manage and query devices in the filesystem";
+