diff options
author | David Sterba <dsterba@suse.cz> | 2014-04-25 19:39:11 +0200 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2014-12-04 16:48:11 +0100 |
commit | 0c67867530f6dd706eaa41a6eaa44245a3252a90 (patch) | |
tree | 1e558b5887f65f1ffd27888e31737dd3fc005289 /cmds-device.c | |
parent | 6312ac884361f719936cb25188fc6f91a28b905b (diff) |
btrfs-progs: cleanup filesystem/device usage code
The main point of this is to load the device and chunk infos at one
place and pass down to the printers. The EPERM is handled separately, in
case kernel does not give us all the information about chunks or
devices, but we want to warn and print at least something.
For non-root users, 'filesystem usage' prints only the overall stats and
warns about RAID5/6.
The sole cleanup changes affect mostly the modified code and the related
functions, should be reasonably small.
Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'cmds-device.c')
-rw-r--r-- | cmds-device.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/cmds-device.c b/cmds-device.c index 197f9d59..9294046f 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -462,31 +462,29 @@ static int _cmd_device_usage(int fd, char *path, int mode) { int i; int ret = 0; - int info_count = 0; - struct chunk_info *info_ptr = 0; - struct device_info *device_info_ptr = 0; - int device_info_count = 0; + struct chunk_info *chunkinfo = NULL; + struct device_info *devinfo = NULL; + int chunkcount = 0; + int devcount = 0; - if (load_chunk_info(fd, &info_ptr, &info_count) || - load_device_info(fd, &device_info_ptr, &device_info_count)) { + ret = load_chunk_and_device_info(fd, &chunkinfo, &chunkcount, &devinfo, + &devcount); + if (ret) { ret = -1; goto exit; } - for (i = 0; i < device_info_count; i++) { - printf("%s, ID: %llu\n", device_info_ptr[i].path, - device_info_ptr[i].devid); - print_device_sizes(fd, &device_info_ptr[i], mode); - print_device_chunks(fd, &device_info_ptr[i], - info_ptr, info_count, mode); + for (i = 0; i < devcount; i++) { + printf("%s, ID: %llu\n", devinfo[i].path, devinfo[i].devid); + print_device_sizes(fd, &devinfo[i], mode); + print_device_chunks(fd, &devinfo[i], chunkinfo, chunkcount, + mode); printf("\n"); } exit: - if (device_info_ptr) - free(device_info_ptr); - if (info_ptr) - free(info_ptr); + free(devinfo); + free(chunkinfo); return ret; } @@ -528,6 +526,7 @@ int cmd_device_usage(int argc, char **argv) argv[1]); return 12; } + r = _cmd_device_usage(fd, argv[i], flags); close_file_or_dir(fd, dirstream); |