Returned success from ntfsprogs utilities with options --version and --help

The ntfsprogs used to return failure when option --version or --help
was used, and this has triggered complains from distribution packagers
who use these options in packaging scripts.
With this patch, success is returned (same behavior as gcc).
edge.strict_endians
Jean-Pierre André 2014-04-23 10:13:27 +02:00
parent 70e5b1b250
commit c0287870e1
13 changed files with 148 additions and 108 deletions

View File

@ -6,7 +6,7 @@
* Copyright (c) 2002-2006 Szabolcs Szakacsits
* Copyright (c) 2005 Erik Sornes
* Copyright (c) 2007 Yura Pakhuchiy
* Copyright (c) 2010 Jean-Pierre Andre
* Copyright (c) 2010-2014 Jean-Pierre Andre
*
* This utility will create an NTFS 1.2 or 3.1 volume on a user
* specified (block) device.
@ -287,7 +287,7 @@ static void mkntfs_version(void)
ntfs_log_info("Copyright (c) 2002-2006 Szabolcs Szakacsits\n");
ntfs_log_info("Copyright (c) 2005 Erik Sornes\n");
ntfs_log_info("Copyright (c) 2007 Yura Pakhuchiy\n");
ntfs_log_info("Copyright (c) 2010-2012 Jean-Pierre Andre\n");
ntfs_log_info("Copyright (c) 2010-2014 Jean-Pierre Andre\n");
ntfs_log_info("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
@ -590,7 +590,7 @@ static void mkntfs_init_options(struct mkntfs_options *opts2)
/**
* mkntfs_parse_options
*/
static BOOL mkntfs_parse_options(int argc, char *argv[], struct mkntfs_options *opts2)
static int mkntfs_parse_options(int argc, char *argv[], struct mkntfs_options *opts2)
{
static const char *sopt = "-c:CfFhH:IlL:np:qQs:S:TUvVz:";
static const struct option lopt[] = {
@ -620,6 +620,7 @@ static BOOL mkntfs_parse_options(int argc, char *argv[], struct mkntfs_options *
int c = -1;
int lic = 0;
int help = 0;
int err = 0;
int ver = 0;
@ -661,7 +662,7 @@ static BOOL mkntfs_parse_options(int argc, char *argv[], struct mkntfs_options *
err++;
break;
case 'h':
err++; /* display help */
help++; /* display help */
break;
case 'I':
opts2->disable_indexing = TRUE;
@ -745,7 +746,7 @@ static BOOL mkntfs_parse_options(int argc, char *argv[], struct mkntfs_options *
}
}
if (!err && !ver && !lic) {
if (!err && !help && !ver && !lic) {
if (opts2->dev_name == NULL) {
if (argc > 1)
ntfs_log_error("You must specify a device.\n");
@ -757,10 +758,11 @@ static BOOL mkntfs_parse_options(int argc, char *argv[], struct mkntfs_options *
mkntfs_version();
if (lic)
mkntfs_license();
if (err)
if (err || help)
mkntfs_usage();
return (!err && !ver && !lic);
/* tri-state 0 : done, 1 : error, -1 : proceed */
return (err ? 1 : (help || ver || lic ? 0 : -1));
}
@ -5168,10 +5170,11 @@ int main(int argc, char *argv[])
mkntfs_init_options(&opts); /* Set up the options */
if (!mkntfs_parse_options(argc, argv, &opts)) /* Read the command line options */
goto done;
/* Read the command line options */
result = mkntfs_parse_options(argc, argv, &opts);
if (result < 0)
result = mkntfs_redirect(&opts);
result = mkntfs_redirect(&opts);
done:
return result;
}

View File

@ -216,12 +216,6 @@ static int parse_options(int argc, char **argv)
opts.force++;
break;
case 'h':
case '?':
if (strncmp (argv[optind-1], "--log-", 6) == 0) {
if (!ntfs_log_parse_option (argv[optind-1]))
err++;
break;
}
help++;
break;
case 'i':
@ -257,6 +251,13 @@ static int parse_options(int argc, char **argv)
case 'r':
opts.raw = TRUE;
break;
case '?':
if (strncmp (argv[optind-1], "--log-", 6) == 0) {
if (!ntfs_log_parse_option (argv[optind-1]))
err++;
break;
}
/* fall through */
default:
ntfs_log_error("Unknown option '%s'.\n", argv[optind-1]);
err++;
@ -300,7 +301,8 @@ static int parse_options(int argc, char **argv)
if (help || err)
usage();
return (!err && !help && !ver);
/* tri-state 0 : done, 1 : error, -1 : proceed */
return (err ? 1 : (help || ver ? 0 : -1));
}
/**
@ -401,12 +403,14 @@ int main(int argc, char *argv[])
ntfs_volume *vol;
ntfs_inode *inode;
ATTR_TYPES attr;
int res;
int result = 1;
ntfs_log_set_handler(ntfs_log_handler_stderr);
if (!parse_options(argc, argv))
return 1;
res = parse_options(argc, argv);
if (res >= 0)
return (res);
utils_set_locale();

View File

@ -347,7 +347,7 @@ static void perr_exit(const char *fmt, ...)
__attribute__((noreturn))
static void usage(void)
static void usage(int ret)
{
fprintf(stderr, "\nUsage: %s [OPTIONS] SOURCE\n"
" Efficiently clone NTFS to a sparse file, image, device or standard output.\n"
@ -375,7 +375,7 @@ static void usage(void)
" and --restore-image is used then read the image from the standard input.\n"
"\n", EXEC_NAME);
fprintf(stderr, "%s%s", ntfs_bugs, ntfs_home);
exit(1);
exit(ret);
}
/**
@ -390,7 +390,7 @@ static void version(void)
"Copyright (c) 2004-2006 Anton Altaparmakov\n"
"Copyright (c) 2010-2014 Jean-Pierre Andre\n\n");
fprintf(stderr, "%s\n%s%s", ntfs_gpl, ntfs_bugs, ntfs_home);
exit(1);
exit(0);
}
static void parse_options(int argc, char **argv)
@ -426,7 +426,7 @@ static void parse_options(int argc, char **argv)
switch (c) {
case 1: /* A non-option argument */
if (opt.volume)
usage();
usage(1);
opt.volume = argv[optind-1];
break;
case 'd':
@ -439,8 +439,9 @@ static void parse_options(int argc, char **argv)
opt.force++;
break;
case 'h':
usage(0);
case '?':
usage();
usage(1);
case 'i': /* not proposed as a short option */
opt.new_serial |= 1;
break;
@ -457,7 +458,7 @@ static void parse_options(int argc, char **argv)
opt.overwrite++;
case 'o':
if (opt.output)
usage();
usage(1);
opt.output = optarg;
break;
case 'r':
@ -480,13 +481,13 @@ static void parse_options(int argc, char **argv)
break;
default:
err_printf("Unknown option '%s'.\n", argv[optind-1]);
usage();
usage(1);
}
}
if (!opt.no_action && (opt.output == NULL)) {
err_printf("You must specify an output file.\n");
usage();
usage(1);
}
if (!opt.no_action && (strcmp(opt.output, "-") == 0))
@ -494,12 +495,12 @@ static void parse_options(int argc, char **argv)
if (opt.volume == NULL) {
err_printf("You must specify a device file.\n");
usage();
usage(1);
}
if (!opt.restore_image && !strcmp(opt.volume, "-")) {
err_printf("Only special images can be read from standard input\n");
usage();
usage(1);
}
if (opt.metadata && opt.save_image) {

View File

@ -169,12 +169,6 @@ static int parse_options(int argc, char **argv)
opts.force++;
break;
case 'h':
case '?':
if (strncmp (argv[optind-1], "--log-", 6) == 0) {
if (!ntfs_log_parse_option (argv[optind-1]))
err++;
break;
}
help++;
break;
case 'I':
@ -217,6 +211,13 @@ static int parse_options(int argc, char **argv)
case 'V':
ver++;
break;
case '?':
if (strncmp (argv[optind-1], "--log-", 6) == 0) {
if (!ntfs_log_parse_option (argv[optind-1]))
err++;
break;
}
/* fall through */
default:
if ((optopt == 'c') || (optopt == 's'))
ntfs_log_error("Option '%s' requires an argument.\n", argv[optind-1]);
@ -267,7 +268,8 @@ static int parse_options(int argc, char **argv)
if (help || err)
usage();
return (!err && !help && !ver);
/* tri-state 0 : done, 1 : error, -1 : proceed */
return (err ? 1 : (help || ver ? 0 : -1));
}
@ -482,12 +484,14 @@ int main(int argc, char *argv[])
ntfs_volume *vol;
ntfs_inode *ino = NULL;
struct match m;
int res;
int result = 1;
ntfs_log_set_handler(ntfs_log_handler_outerr);
if (!parse_options(argc, argv))
return 1;
res = parse_options(argc, argv);
if (res >= 0)
return (res);
utils_set_locale();

View File

@ -215,12 +215,6 @@ static int parse_options(int argc, char **argv)
opts.force++;
break;
case 'h':
case '?':
if (strncmp(argv[optind - 1], "--log-", 6) == 0) {
if (!ntfs_log_parse_option(argv[optind - 1]))
err++;
break;
}
help++;
break;
case 'm':
@ -248,6 +242,13 @@ static int parse_options(int argc, char **argv)
opts.verbose++;
ntfs_log_set_levels(NTFS_LOG_LEVEL_VERBOSE);
break;
case '?':
if (strncmp(argv[optind - 1], "--log-", 6) == 0) {
if (!ntfs_log_parse_option(argv[optind - 1]))
err++;
break;
}
/* fall through */
default:
ntfs_log_error("Unknown option '%s'.\n",
argv[optind - 1]);
@ -290,7 +291,8 @@ static int parse_options(int argc, char **argv)
if (help || err)
usage();
return (!err && !help && !ver);
/* tri-state 0 : done, 1 : error, -1 : proceed */
return (err ? 1 : (help || ver ? 0 : -1));
}
/**
@ -824,6 +826,7 @@ int main(int argc, char *argv[])
ntfs_inode *out;
ntfs_attr *na;
int flags = 0;
int res;
int result = 1;
s64 new_size;
u64 offset;
@ -834,8 +837,9 @@ int main(int argc, char *argv[])
ntfs_log_set_handler(ntfs_log_handler_stderr);
if (!parse_options(argc, argv))
return 1;
res = parse_options(argc, argv);
if (res >= 0)
return (res);
utils_set_locale();

View File

@ -233,7 +233,6 @@ static int parse_options(int argc, char **argv)
opts.force++;
break;
case 'h':
case '?':
help++;
break;
case 'k':
@ -266,6 +265,7 @@ static int parse_options(int argc, char **argv)
opts.verbose++;
ntfs_log_set_levels(NTFS_LOG_LEVEL_VERBOSE);
break;
case '?':
default:
ntfs_log_error("Unknown option '%s'.\n",
argv[optind - 1]);
@ -305,7 +305,8 @@ static int parse_options(int argc, char **argv)
if (help || err)
usage();
return (!err && !help && !ver);
/* tri-state 0 : done, 1 : error, -1 : proceed */
return (err ? 1 : (help || ver ? 0 : -1));
}
/**
@ -1541,8 +1542,9 @@ int main(int argc, char *argv[])
ntfs_log_set_handler(ntfs_log_handler_stderr);
if (!parse_options(argc, argv))
return 1;
res = parse_options(argc, argv);
if (res >= 0)
return (res);
utils_set_locale();
/* Initialize crypto in ntfs. */

View File

@ -4,7 +4,7 @@
* Copyright (c) 2000-2006 Anton Altaparmakov
* Copyright (c) 2002-2006 Szabolcs Szakacsits
* Copyright (c) 2007 Yura Pakhuchiy
* Copyright (c) 2011-2012 Jean-Pierre Andre
* Copyright (c) 2011-2014 Jean-Pierre Andre
*
* This utility fixes some common NTFS problems, resets the NTFS journal file
* and schedules an NTFS consistency check for the first boot into Windows.
@ -123,7 +123,7 @@ struct MFT_SELF_LOCATED {
* usage
*/
__attribute__((noreturn))
static void usage(void)
static void usage(int ret)
{
ntfs_log_info("%s v%s (libntfs-3g)\n"
"\n"
@ -140,7 +140,7 @@ static void usage(void)
EXEC_NAME, VERSION, EXEC_NAME,
EXEC_NAME);
ntfs_log_info("%s%s", ntfs_bugs, ntfs_home);
exit(1);
exit(ret);
}
/**
@ -154,10 +154,10 @@ static void version(void)
"Copyright (c) 2000-2006 Anton Altaparmakov\n"
"Copyright (c) 2002-2006 Szabolcs Szakacsits\n"
"Copyright (c) 2007 Yura Pakhuchiy\n"
"Copyright (c) 2011-2012 Jean-Pierre Andre\n\n",
"Copyright (c) 2011-2014 Jean-Pierre Andre\n\n",
EXEC_NAME, VERSION);
ntfs_log_info("%s\n%s%s", ntfs_gpl, ntfs_bugs, ntfs_home);
exit(1);
exit(0);
}
/**
@ -185,7 +185,7 @@ static void parse_options(int argc, char **argv)
opt.volume = argv[optind - 1];
else {
ntfs_log_info("ERROR: Too many arguments.\n");
usage();
usage(1);
}
break;
case 'b':
@ -198,20 +198,21 @@ static void parse_options(int argc, char **argv)
opt.no_action = TRUE;
break;
case 'h':
usage(0);
case '?':
usage();
usage(1);
/* fall through */
case 'V':
version();
default:
ntfs_log_info("ERROR: Unknown option '%s'.\n", argv[optind - 1]);
usage();
usage(1);
}
}
if (opt.volume == NULL) {
ntfs_log_info("ERROR: You must specify a device.\n");
usage();
usage(1);
}
}

View File

@ -8,7 +8,7 @@
* Copyright (c) 2004-2005 Yuval Fledel
* Copyright (c) 2004-2007 Yura Pakhuchiy
* Copyright (c) 2005 Cristian Klein
* Copyright (c) 2011-2012 Jean-Pierre Andre
* Copyright (c) 2011-2014 Jean-Pierre Andre
*
* This utility will dump a file's attributes.
*
@ -119,7 +119,7 @@ static void version(void)
printf(" 2003 Leonard Norrgård\n");
printf(" 2004-2005 Yuval Fledel\n");
printf(" 2004-2007 Yura Pakhuchiy\n");
printf(" 2011-2012 Jean-Pierre Andre\n");
printf(" 2011-2014 Jean-Pierre Andre\n");
printf("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
@ -304,7 +304,8 @@ static int parse_options(int argc, char *argv[])
if (help || err)
usage();
return (!err && !help && !ver);
/* tri-state 0 : done, 1 : error, -1 : proceed */
return (err ? 1 : (help || ver ? 0 : -1));
}
@ -2346,15 +2347,17 @@ static void ntfs_dump_file_attributes(ntfs_inode *inode)
int main(int argc, char **argv)
{
ntfs_volume *vol;
int res;
setlinebuf(stdout);
ntfs_log_set_handler(ntfs_log_handler_outerr);
if (!parse_options(argc, argv)) {
res = parse_options(argc, argv);
if (res > 0)
printf("Failed to parse command line options\n");
exit(1);
}
if (res >= 0)
exit(res);
utils_set_locale();

View File

@ -83,7 +83,7 @@ static void version(void)
ntfs_log_info(" 2002 Matthew J. Fanto\n");
ntfs_log_info(" 2002-2005 Anton Altaparmakov\n");
ntfs_log_info(" 2002-2003 Richard Russon\n");
ntfs_log_info(" 2012 Jean-Pierre Andre\n");
ntfs_log_info(" 2012-2014 Jean-Pierre Andre\n");
ntfs_log_info("\n%s\n%s%s\n", ntfs_gpl, ntfs_bugs, ntfs_home);
}
@ -156,12 +156,6 @@ static int parse_options(int argc, char *argv[])
opts.force++;
break;
case 'h':
case '?':
if (strncmp (argv[optind-1], "--log-", 6) == 0) {
if (!ntfs_log_parse_option (argv[optind-1]))
err++;
break;
}
help++;
break;
case 'I' : /* not proposed as a short option letter */
@ -195,6 +189,13 @@ static int parse_options(int argc, char *argv[])
case 'V':
ver++;
break;
case '?':
if (strncmp (argv[optind-1], "--log-", 6) == 0) {
if (!ntfs_log_parse_option (argv[optind-1]))
err++;
break;
}
/* fall through */
default:
ntfs_log_error("Unknown option '%s'.\n", argv[optind-1]);
err++;
@ -230,7 +231,8 @@ static int parse_options(int argc, char *argv[])
if (help || err)
usage();
return (!err && !help && !ver);
/* tri-state 0 : done, 1 : error, -1 : proceed */
return (err ? 1 : (help || ver ? 0 : -1));
}
static int change_serial(ntfs_volume *vol, u64 sector, le64 serial_number,
@ -413,9 +415,11 @@ int main(int argc, char **argv)
ntfs_log_set_handler(ntfs_log_handler_outerr);
if (!parse_options(argc, argv))
return 1;
result = parse_options(argc, argv);
if (result >= 0)
return (result);
result = 0;
utils_set_locale();
if ((opts.label || opts.new_serial)
@ -453,6 +457,7 @@ int main(int argc, char **argv)
unmount :
ntfs_umount(vol, FALSE);
abort :
return result;
/* "result" may be a negative reply of a library function */
return (result ? 1 : 0);
}

View File

@ -333,7 +333,7 @@ static void perr_exit(const char *fmt, ...)
* Return: none
*/
__attribute__((noreturn))
static void usage(void)
static void usage(int ret)
{
printf("\nUsage: %s [OPTIONS] DEVICE\n"
@ -364,7 +364,7 @@ static void usage(void)
"\n", EXEC_NAME);
printf("%s%s", ntfs_bugs, ntfs_home);
printf("Ntfsresize FAQ: http://linux-ntfs.sourceforge.net/info/ntfsresize.html\n");
exit(1);
exit(ret);
}
/**
@ -433,7 +433,7 @@ static s64 get_new_volume_size(char *s)
if (strlen(suffix) == 2 && suffix[1] == 'i')
prefix_kind = 1024;
else if (strlen(suffix) > 1)
usage();
usage(1);
/* We follow the SI prefixes:
http://physics.nist.gov/cuu/Units/prefixes.html
@ -457,7 +457,7 @@ static s64 get_new_volume_size(char *s)
size *= prefix_kind;
break;
default:
usage();
usage(1);
}
return size;
@ -523,7 +523,6 @@ static int parse_options(int argc, char **argv)
opt.force++;
break;
case 'h':
case '?':
help++;
break;
case 'i':
@ -554,6 +553,7 @@ static int parse_options(int argc, char **argv)
case 'x':
opt.expand++;
break;
case '?':
default:
if (optopt == 's') {
printf("Option '%s' requires an argument.\n", argv[optind-1]);
@ -578,12 +578,12 @@ static int parse_options(int argc, char **argv)
&& (opt.expand || opt.info || opt.infombonly)) {
printf(NERR_PREFIX "Options --info(-mb-only) and --expand "
"cannot be used with --size.\n");
usage();
usage(1);
}
if (opt.expand && opt.infombonly) {
printf(NERR_PREFIX "Options --info-mb-only "
"cannot be used with --expand.\n");
usage();
usage(1);
}
}
@ -604,9 +604,10 @@ static int parse_options(int argc, char **argv)
if (ver)
version();
if (help || err)
usage();
usage(err > 0);
return (!err && !help && !ver);
/* tri-state 0 : done, 1 : error, -1 : proceed */
return (err ? 1 : (help || ver ? 0 : -1));
}
static void print_advise(ntfs_volume *vol, s64 supp_lcn)
@ -4370,13 +4371,15 @@ int main(int argc, char **argv)
s64 new_size = 0; /* in clusters; 0 = --info w/o --size */
s64 device_size; /* in bytes */
ntfs_volume *vol = NULL;
int res;
ntfs_log_set_handler(ntfs_log_handler_outerr);
printf("%s v%s (libntfs-3g)\n", EXEC_NAME, VERSION);
if (!parse_options(argc, argv))
return 1;
res = parse_options(argc, argv);
if (res >= 0)
return (res);
utils_set_locale();

View File

@ -137,7 +137,7 @@ static void license(void)
* usage - print a list of the parameters to the program
*/
__attribute__((noreturn))
static void usage(void)
static void usage(int ret)
{
copyright();
fprintf(stderr, "Usage: %s [options] device inode [attr-type "
@ -155,7 +155,7 @@ static void usage(void)
" -l Display licensing information\n"
" -h Display this help\n", EXEC_NAME);
fprintf(stderr, "%s%s", ntfs_bugs, ntfs_home);
exit(1);
exit(ret);
}
/**
@ -194,12 +194,13 @@ static void parse_options(int argc, char *argv[])
license();
exit(0);
case 'h':
usage(0);
case '?':
default:
usage();
usage(1);
}
if (optind == argc)
usage();
usage(1);
if (opts.verbose > 1)
ntfs_log_set_levels(NTFS_LOG_LEVEL_DEBUG | NTFS_LOG_LEVEL_TRACE |
@ -210,7 +211,7 @@ static void parse_options(int argc, char *argv[])
ntfs_log_verbose("device name = %s\n", dev_name);
if (optind == argc)
usage();
usage(1);
/* Get the inode. */
ll = strtoll(argv[optind++], &s, 0);
@ -220,7 +221,7 @@ static void parse_options(int argc, char *argv[])
ntfs_log_verbose("inode = %lli\n", (long long)inode);
if (optind == argc)
usage();
usage(1);
/* Get the attribute type, if specified. */
s = argv[optind++];
@ -251,7 +252,7 @@ static void parse_options(int argc, char *argv[])
s = argv[optind++];
if (optind != argc)
usage();
usage(1);
} else {
attr_name = AT_UNNAMED;
attr_name_len = 0;

View File

@ -680,10 +680,13 @@ static int parse_options(int argc, char *argv[])
opts.force++;
break;
case 'h':
help++;
break;
case '?':
if (ntfs_log_parse_option (argv[optind-1]))
break;
help++;
ntfs_log_error("Unknown option '%s'.\n", argv[optind-1]);
err++;
break;
case 'i':
end = NULL;
@ -878,7 +881,8 @@ static int parse_options(int argc, char *argv[])
if (help || err)
usage();
return (!err && !help && !ver);
/* tri-state 0 : done, 1 : error, -1 : proceed */
return (err ? 1 : (help || ver ? 0 : -1));
}
/**
@ -2442,7 +2446,8 @@ int main(int argc, char *argv[])
with_regex = 0;
avoid_duplicate_printing = 0;
if (!parse_options(argc, argv))
result = parse_options(argc, argv);
if (result >= 0)
goto free;
utils_set_locale();

View File

@ -343,12 +343,6 @@ static int parse_options(int argc, char *argv[])
opts.force++;
break;
case 'h':
case '?':
if (strncmp (argv[optind-1], "--log-", 6) == 0) {
if (!ntfs_log_parse_option (argv[optind-1]))
err++;
break;
}
help++;
break;
case 'l':
@ -383,6 +377,13 @@ static int parse_options(int argc, char *argv[])
case 'V':
ver++;
break;
case '?':
if (strncmp (argv[optind-1], "--log-", 6) == 0) {
if (!ntfs_log_parse_option (argv[optind-1]))
err++;
break;
}
/* fall through */
default:
if ((optopt == 'b') || (optopt == 'c')) {
ntfs_log_error("Option '%s' requires an argument.\n", argv[optind-1]);
@ -451,7 +452,8 @@ static int parse_options(int argc, char *argv[])
if (help || err)
usage();
return (!err && !help && !ver);
/* tri-state 0 : done, 1 : error, -1 : proceed */
return (err ? 1 : (help || ver ? 0 : -1));
}
/**
@ -1995,13 +1997,15 @@ int main(int argc, char *argv[])
ntfs_volume *vol;
int result = 1;
int flags = 0;
int res;
int i, j;
enum action act = act_info;
ntfs_log_set_handler(ntfs_log_handler_outerr);
if (!parse_options(argc, argv))
return 1;
res = parse_options(argc, argv);
if (res >= 0)
return (res);
utils_set_locale();