#include "commands.h"
#include "version.h"
+#include "help.h"
/*
* Add the chunk info to the chunk_info list
* which compose the chunk, which could be different from the number of devices
* if a disk is added later.
*/
-static void get_raid56_used(int fd, struct chunk_info *chunks, int chunkcount,
+static void get_raid56_used(struct chunk_info *chunks, int chunkcount,
u64 *raid5_used, u64 *raid6_used)
{
struct chunk_info *info_ptr = chunks;
}
}
-#define MIN_UNALOCATED_THRESH (16 * 1024 * 1024)
+#define MIN_UNALOCATED_THRESH SZ_16M
static int print_filesystem_usage_overall(int fd, struct chunk_info *chunkinfo,
int chunkcount, struct device_info *devinfo, int devcount,
char *path, unsigned unit_mode)
ret = 1;
goto exit;
}
- get_raid56_used(fd, chunkinfo, chunkcount, &raid5_used, &raid6_used);
+ get_raid56_used(chunkinfo, chunkcount, &raid5_used, &raid6_used);
for (i = 0; i < sargs->total_spaces; i++) {
int ratio;
printf(" Device allocated:\t\t%*s\n", width,
pretty_size_mode(r_total_chunks, unit_mode));
printf(" Device unallocated:\t\t%*s\n", width,
- pretty_size_mode(r_total_unused, unit_mode));
+ pretty_size_mode(r_total_unused, unit_mode | UNITS_NEGATIVE));
printf(" Device missing:\t\t%*s\n", width,
pretty_size_mode(r_total_missing, unit_mode));
printf(" Used:\t\t\t%*s\n", width,
}
for (i = 0, ndevs = 0 ; i <= fi_args.max_id ; i++) {
- BUG_ON(ndevs >= fi_args.num_devices);
+ if (ndevs >= fi_args.num_devices) {
+ error("unexpected number of devices: %d >= %llu", ndevs,
+ (unsigned long long)fi_args.num_devices);
+ goto out;
+ }
memset(&dev_info, 0, sizeof(dev_info));
ret = get_device_info(fd, i, &dev_info);
continue;
if (ret) {
error("cannot get info about device devid=%d", i);
- free(info);
- return ret;
+ goto out;
}
info[ndevs].devid = dev_info.devid;
++ndevs;
}
- BUG_ON(ndevs != fi_args.num_devices);
+ if (ndevs != fi_args.num_devices) {
+ error("unexpected number of devices: %d != %llu", ndevs,
+ (unsigned long long)fi_args.num_devices);
+ goto out;
+ }
+
qsort(info, fi_args.num_devices,
sizeof(struct device_info), cmp_device_info);
*device_info_ptr = info;
return 0;
+
+out:
+ free(info);
+ return ret;
}
int load_chunk_and_device_info(int fd, struct chunk_info **chunkinfo,
unused = get_partition_size(device_info_ptr[i].path)
- total_allocated;
- table_printf(matrix, unallocated_col, vhdr_skip + i,
- ">%s", pretty_size_mode(unused, unit_mode));
+ table_printf(matrix, unallocated_col, vhdr_skip + i, ">%s",
+ pretty_size_mode(unused, unit_mode | UNITS_NEGATIVE));
total_unused += unused;
}
}
table_printf(matrix, unallocated_col, vhdr_skip + device_info_count + 1,
- ">%s", pretty_size_mode(total_unused, unit_mode));
+ ">%s",
+ pretty_size_mode(total_unused, unit_mode | UNITS_NEGATIVE));
table_printf(matrix, 1, vhdr_skip + device_info_count + 2, "<Used");
for (i = 0, col = spaceinfos_col; i < sargs->total_spaces; i++) {
printf("Unallocated:\n");
print_unused(info_ptr, info_count, device_info_ptr, device_info_count,
- unit_mode);
+ unit_mode | UNITS_NEGATIVE);
}
static int print_filesystem_usage_by_chunk(int fd,
return !!ret;
}
-void print_device_chunks(int fd, struct device_info *devinfo,
+void print_device_chunks(struct device_info *devinfo,
struct chunk_info *chunks_info_ptr,
int chunks_info_count, unsigned unit_mode)
{
}
printf(" Unallocated: %*s%10s\n",
(int)(20 - strlen("Unallocated")), "",
- pretty_size_mode(devinfo->size - allocated, unit_mode));
+ pretty_size_mode(devinfo->size - allocated,
+ unit_mode | UNITS_NEGATIVE));
}
-void print_device_sizes(int fd, struct device_info *devinfo, unsigned unit_mode)
+void print_device_sizes(struct device_info *devinfo, unsigned unit_mode)
{
printf(" Device size: %*s%10s\n",
(int)(20 - strlen("Device size")), "",