static int cmd_qgroup_show(int argc, char **argv) { char *path; int ret = 0; int fd; int e; DIR *dirstream = NULL; u64 qgroupid; int filter_flag = 0; unsigned unit_mode; struct btrfs_qgroup_comparer_set *comparer_set; struct btrfs_qgroup_filter_set *filter_set; filter_set = btrfs_qgroup_alloc_filter_set(); comparer_set = btrfs_qgroup_alloc_comparer_set(); unit_mode = get_unit_mode_from_arg(&argc, argv, 0); optind = 1; while (1) { int c; static const struct option long_options[] = { {"sort", required_argument, NULL, 'S'}, { NULL, 0, NULL, 0 } }; c = getopt_long(argc, argv, "pcreFf", long_options, NULL); if (c < 0) break; switch (c) { case 'p': btrfs_qgroup_setup_print_column( BTRFS_QGROUP_PARENT); break; case 'c': btrfs_qgroup_setup_print_column( BTRFS_QGROUP_CHILD); break; case 'r': btrfs_qgroup_setup_print_column( BTRFS_QGROUP_MAX_RFER); break; case 'e': btrfs_qgroup_setup_print_column( BTRFS_QGROUP_MAX_EXCL); break; case 'F': filter_flag |= 0x1; break; case 'f': filter_flag |= 0x2; break; case 'S': ret = btrfs_qgroup_parse_sort_string(optarg, &comparer_set); if (ret) usage(cmd_qgroup_show_usage); break; default: usage(cmd_qgroup_show_usage); } } btrfs_qgroup_setup_units(unit_mode); if (check_argc_exact(argc - optind, 1)) usage(cmd_qgroup_show_usage); path = argv[optind]; fd = btrfs_open_dir(path, &dirstream, 1); if (fd < 0) { btrfs_qgroup_free_filter_set(filter_set); btrfs_qgroup_free_comparer_set(comparer_set); return 1; } if (filter_flag) { qgroupid = btrfs_get_path_rootid(fd); if (filter_flag & 0x1) btrfs_qgroup_setup_filter(&filter_set, BTRFS_QGROUP_FILTER_ALL_PARENT, qgroupid); if (filter_flag & 0x2) btrfs_qgroup_setup_filter(&filter_set, BTRFS_QGROUP_FILTER_PARENT, qgroupid); } ret = btrfs_show_qgroups(fd, filter_set, comparer_set); e = errno; close_file_or_dir(fd, dirstream); if (ret < 0) error("can't list qgroups: %s", strerror(e)); return !!ret; }
static int cmd_qgroup_show(int argc, char **argv) { char *path; int ret = 0; int fd; int e; DIR *dirstream = NULL; u64 qgroupid; int filter_flag = 0; unsigned unit_mode = UNITS_DEFAULT; struct btrfs_qgroup_comparer_set *comparer_set; struct btrfs_qgroup_filter_set *filter_set; filter_set = btrfs_qgroup_alloc_filter_set(); comparer_set = btrfs_qgroup_alloc_comparer_set(); optind = 1; while (1) { int c; int option_index = 0; static const struct option long_options[] = { {"sort", 1, NULL, 'S'}, {"raw", no_argument, NULL, GETOPT_VAL_RAW}, {"kbytes", no_argument, NULL, GETOPT_VAL_KBYTES}, {"mbytes", no_argument, NULL, GETOPT_VAL_MBYTES}, {"gbytes", no_argument, NULL, GETOPT_VAL_GBYTES}, {"tbytes", no_argument, NULL, GETOPT_VAL_TBYTES}, {"si", no_argument, NULL, GETOPT_VAL_SI}, {"iec", no_argument, NULL, GETOPT_VAL_IEC}, { "human-readable", no_argument, NULL, GETOPT_VAL_HUMAN_READABLE}, { NULL, 0, NULL, 0 } }; c = getopt_long(argc, argv, "pcreFf", long_options, &option_index); if (c < 0) break; switch (c) { case 'p': btrfs_qgroup_setup_print_column( BTRFS_QGROUP_PARENT); break; case 'c': btrfs_qgroup_setup_print_column( BTRFS_QGROUP_CHILD); break; case 'r': btrfs_qgroup_setup_print_column( BTRFS_QGROUP_MAX_RFER); break; case 'e': btrfs_qgroup_setup_print_column( BTRFS_QGROUP_MAX_EXCL); break; case 'F': filter_flag |= 0x1; break; case 'f': filter_flag |= 0x2; break; case 'S': ret = btrfs_qgroup_parse_sort_string(optarg, &comparer_set); if (ret) usage(cmd_qgroup_show_usage); break; case GETOPT_VAL_RAW: unit_mode = UNITS_RAW; break; case GETOPT_VAL_KBYTES: units_set_base(&unit_mode, UNITS_KBYTES); break; case GETOPT_VAL_MBYTES: units_set_base(&unit_mode, UNITS_MBYTES); break; case GETOPT_VAL_GBYTES: units_set_base(&unit_mode, UNITS_GBYTES); break; case GETOPT_VAL_TBYTES: units_set_base(&unit_mode, UNITS_TBYTES); break; case GETOPT_VAL_SI: units_set_mode(&unit_mode, UNITS_DECIMAL); break; case GETOPT_VAL_IEC: units_set_mode(&unit_mode, UNITS_BINARY); break; case GETOPT_VAL_HUMAN_READABLE: unit_mode = UNITS_HUMAN_BINARY; break; default: usage(cmd_qgroup_show_usage); } } btrfs_qgroup_setup_units(unit_mode); if (check_argc_exact(argc - optind, 1)) usage(cmd_qgroup_show_usage); path = argv[optind]; fd = open_file_or_dir(path, &dirstream); if (fd < 0) { fprintf(stderr, "ERROR: can't access '%s'\n", path); return 1; } if (filter_flag) { qgroupid = btrfs_get_path_rootid(fd); if (filter_flag & 0x1) btrfs_qgroup_setup_filter(&filter_set, BTRFS_QGROUP_FILTER_ALL_PARENT, qgroupid); if (filter_flag & 0x2) btrfs_qgroup_setup_filter(&filter_set, BTRFS_QGROUP_FILTER_PARENT, qgroupid); } ret = btrfs_show_qgroups(fd, filter_set, comparer_set); e = errno; close_file_or_dir(fd, dirstream); if (ret < 0) fprintf(stderr, "ERROR: can't list qgroups: %s\n", strerror(e)); return !!ret; }