@@ -511,5 +511,7 @@ int main(int argc, char **argv)
out:
close_ctree(root);
free(roots);
+ if (ret < 0)
+ ret = -ret;
return ret;
}
@@ -988,8 +988,12 @@ int main(int ac, char **av)
logical += root->sectorsize;
bytes -= root->sectorsize;
}
+ if (ret < 0)
+ ret = -ret;
return ret;
out_close:
close_ctree(root);
+ if (ret < 0)
+ ret = -ret;
return ret;
}
@@ -57,9 +57,8 @@ int main(int argc, char **argv)
seed = atol(optarg);
break;
case 'h':
+ default:
usage();
- case '?':
- return 255;
}
}
@@ -68,7 +67,7 @@ int main(int argc, char **argv)
if (!loop) {
if (check_argc_min(argc - optind, 1))
- return 255;
+ return EINVAL;
printf("%12u - %s\n", crc32c(~1, str, strlen(str)), str);
return 0;
@@ -76,7 +75,7 @@ int main(int argc, char **argv)
buf = malloc(length);
if (!buf)
- return -ENOMEM;
+ return ENOMEM;
srand(seed);
while (1) {
@@ -408,5 +408,8 @@ no_node:
printf("uuid %s\n", uuidbuf);
printf("%s\n", BTRFS_BUILD_VERSION);
close_root:
- return close_ctree(root);
+ ret = close_ctree(root);
+ if (ret < 0)
+ ret = -ret;
+ return ret;
}
@@ -329,5 +329,7 @@ int main(int argc, char **argv)
csum_size = btrfs_super_csum_size(root->fs_info->super_copy);
ret = find_root(root);
close_ctree(root);
+ if (ret < 0)
+ ret = -ret;
return ret;
}
@@ -173,8 +173,10 @@ int main(int ac, char **av)
info_file = stderr;
} else {
out_fd = open(output_file, O_RDWR | O_CREAT, 0600);
- if (out_fd < 0)
+ if (out_fd < 0) {
+ ret = errno;
goto close;
+ }
ret = ftruncate(out_fd, 0);
if (ret) {
ret = 1;
@@ -211,5 +213,7 @@ out_close_fd:
close(out_fd);
close:
close_ctree(root);
+ if (ret < 0)
+ ret = -ret;
return ret;
}
@@ -81,10 +81,10 @@ int main(int ac, char **av)
if((ret = check_mounted(av[optind])) < 0) {
fprintf(stderr, "Could not check mount status: %s\n", strerror(-ret));
- return ret;
+ return -ret;
} else if(ret) {
fprintf(stderr, "%s is currently mounted. Aborting.\n", av[optind]);
- return -EBUSY;
+ return EBUSY;
}
root = open_ctree(av[optind], bytenr, 1);
@@ -104,5 +104,7 @@ int main(int ac, char **av)
*/
printf("using SB copy %llu, bytenr %llu\n", (unsigned long long)num,
(unsigned long long)bytenr);
+ if (ret < 0)
+ ret = -ret;
return ret;
}
@@ -216,6 +216,7 @@ int main(int argc, char **argv)
{
const struct cmd_struct *cmd;
const char *bname;
+ int ret;
if ((bname = strrchr(argv[0], '/')) != NULL)
bname++;
@@ -244,5 +245,8 @@ int main(int argc, char **argv)
crc32c_optimization_init();
fixup_argv0(argv, cmd->token);
- exit(cmd->fn(argc, argv));
+ ret = cmd->fn(argc, argv);
+ if (ret < 0)
+ ret = -ret;
+ exit(ret);
}
btrfs command may return minus value, however most shell only supports return value in range [0,255], so minus return value will overflow, which is quite confusing for end user. This patch will do the minus check return value check before return it to shell for all the btrfs-progs commands. Also fix several easy-to-find errno leak and insane manual return value. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- btrfs-calc-size.c | 2 ++ btrfs-corrupt-block.c | 4 ++++ btrfs-crc.c | 7 +++---- btrfs-debug-tree.c | 5 ++++- btrfs-find-root.c | 2 ++ btrfs-map-logical.c | 6 +++++- btrfs-select-super.c | 6 ++++-- btrfs.c | 6 +++++- 8 files changed, 29 insertions(+), 9 deletions(-)