ret = load_chunk_and_device_info(fd, &chunkinfo, &chunkcount, &devinfo,
&devcount);
- if (ret) {
- ret = -1;
- goto exit;
- }
+ if (ret)
+ goto out;
for (i = 0; i < devcount; i++) {
printf("%s, ID: %llu\n", devinfo[i].path, devinfo[i].devid);
printf("\n");
}
-exit:
+out:
free(devinfo);
free(chunkinfo);
{
int mode = UNITS_HUMAN;
+ int ret = 0;
int i, more_than_one = 0;
optind = 1;
usage(cmd_device_usage_usage);
for (i = optind; i < argc ; i++) {
- int r, fd;
+ int fd;
DIR *dirstream = NULL;
if (more_than_one)
printf("\n");
fd = open_file_or_dir(argv[i], &dirstream);
if (fd < 0) {
- fprintf(stderr, "ERROR: can't access to '%s'\n",
+ fprintf(stderr, "ERROR: can't access '%s'\n",
argv[1]);
- return 12;
+ ret = 1;
+ goto out;
}
- r = _cmd_device_usage(fd, argv[i], mode);
+ ret = _cmd_device_usage(fd, argv[i], mode);
close_file_or_dir(fd, dirstream);
- if (r)
- return r;
+ if (ret)
+ goto out;
more_than_one = 1;
-
}
-
- return 0;
+out:
+ return !!ret;
}
const struct cmd_group device_cmd_group = {
if (!res) {
free(*info_ptr);
fprintf(stderr, "ERROR: not enough memory\n");
- return -1;
+ return -ENOMEM;
}
*info_ptr = res;
fprintf(stderr,
"ERROR: can't perform the search - %s\n",
strerror(e));
- return -99;
+ return ret;
}
/* the ioctl returns the number of item it found in nr_items */
off += sizeof(*sh);
item = (struct btrfs_chunk *)(args.buf + off);
- if (add_info_to_list(info_ptr, info_count, item)) {
+ ret = add_info_to_list(info_ptr, info_count, item);
+ if (ret) {
*info_ptr = 0;
- return -100;
+ return ret;
}
off += sh->len;
double K;
u64 raid5_used, raid6_used;
- if ((sargs = load_space_info(fd, path)) == NULL) {
- ret = -1;
+ sargs = load_space_info(fd, path);
+ if (!sargs) {
+ ret = 1;
goto exit;
}
"ERROR: couldn't get space info on '%s' - %s\n",
path, strerror(e));
- ret = 19;
+ ret = 1;
goto exit;
}
get_raid56_used(fd, chunkinfo, chunkcount, &raid5_used, &raid6_used);
return ret;
if (ret < 0) {
fprintf(stderr, "ERROR: cannot get filesystem info\n");
- return -1;
+ return ret;
}
info = calloc(fi_args.num_devices, sizeof(struct device_info));
if (!info) {
fprintf(stderr, "ERROR: not enough memory\n");
- return -1;
+ return ret;
}
for (i = 0, ndevs = 0 ; i <= fi_args.max_id ; i++) {
"ERROR: cannot get info about device devid=%d\n",
i);
free(info);
- return -1;
+ return ret;
}
info[ndevs].devid = dev_info.devid;
sargs = load_space_info(fd, path);
if (!sargs) {
ret = 1;
- goto exit;
+ goto out;
}
if (tabular)
_cmd_filesystem_usage_linear(mode, sargs, chunkinfo,
chunkcount, devinfo, devcount);
-exit:
free(sargs);
-
+out:
return ret;
}
int cmd_filesystem_usage(int argc, char **argv)
{
int mode = UNITS_HUMAN;
+ int ret = 0;
int i, more_than_one = 0;
int tabular = 0;
usage(cmd_filesystem_usage_usage);
for (i = optind; i < argc; i++) {
- int ret;
int fd;
DIR *dirstream = NULL;
struct chunk_info *chunkinfo = NULL;
fd = open_file_or_dir(argv[i], &dirstream);
if (fd < 0) {
- fprintf(stderr, "ERROR: can't access to '%s'\n",
+ fprintf(stderr, "ERROR: can't access '%s'\n",
argv[1]);
- return 12;
+ ret = 1;
+ goto out;
}
if (more_than_one)
printf("\n");
free(devinfo);
if (ret)
- return ret;
+ goto out;
more_than_one = 1;
}
- return 0;
+out:
+ return !!ret;
}
void print_device_chunks(int fd, struct device_info *devinfo,