Improve option parsing

stuff

====Do Not Remove====
Status: ok
Signed-off-by: Neil Brown <neilb@suse.de>
This commit is contained in:
Neil Brown 2005-12-05 05:54:33 +00:00
parent 8b0dabea07
commit c06487ce20
6 changed files with 25 additions and 13 deletions

View File

@ -204,11 +204,9 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
/* Impossible! */
fprintf(stderr, Name ": fstat failed for %s: %s\n",
devname, strerror(errno));
close(dfd);
} else if ((stb.st_mode & S_IFMT) != S_IFBLK) {
fprintf(stderr, Name ": %s is not a block device.\n",
devname);
close(dfd);
} else if (!tst && (tst = guess_super(dfd)) == NULL) {
if ((inargv && verbose >= 0) || verbose > 0)
fprintf(stderr, Name ": no recogniseable superblock\n");
@ -216,11 +214,10 @@ int Assemble(struct supertype *st, char *mddev, int mdfd,
if ((inargv && verbose >= 0) || verbose > 0)
fprintf( stderr, Name ": no RAID superblock on %s\n",
devname);
close(dfd);
} else {
tst->ss->getinfo_super(&info, &ident2, super);
close(dfd);
}
if (dfd >= 0) close(dfd);
if (ident->uuid_set &&
(!super || same_uuid(info.uuid, ident->uuid, tst->ss->swapuuid)==0)) {

View File

@ -4,6 +4,9 @@ Changes Prior to this release
- Support little-endian (Rather than hostendian) bitmaps.
- Return correct error code from 'mdadm -S'
- Remove extra blank line from 'mdadm -Eb' output.
- Improve option parsing so that -a and -b do not have
optional arguements: the arg is either required or not
depending on context.
- Allow scanning of devices listed in /proc/partitions even
if they don't appear in /dev.

View File

@ -98,7 +98,7 @@ mdassemble : $(ASSEMBLE_SRCS) mdadm.h
mdassemble.static : $(ASSEMBLE_SRCS) mdadm.h
rm -f $(OBJS)
$(CC) $(LDFLAGS) $(ASSEMBLE_FLAGS) -static -o mdassemble $(ASSEMBLE_SRCS)
$(CC) $(LDFLAGS) $(ASSEMBLE_FLAGS) -static -o mdassemble.static $(ASSEMBLE_SRCS)
mdassemble.uclibc : $(ASSEMBLE_SRCS) mdadm.h
rm -f $(OBJS)

View File

@ -91,7 +91,8 @@ char Version[] = Name " - v2.1 - 12 September 2005\n";
* At the time if writing, there is only minimal support.
*/
char short_options[]="-ABCDEFGQhVXvqb::c:i:l:p:m:n:x:u:c:d:z:U:sa::rfRSow1te:";
char short_options[]="-ABCDEFGQhVXvqbc:i:l:p:m:n:x:u:c:d:z:U:sarfRSow1te:";
char short_bitmap_auto_options[]="-ABCDEFGQhVXvqb:c:i:l:p:m:n:x:u:c:d:z:U:sa:rfRSow1te:";
struct option long_options[] = {
{"manage", 0, 0, '@'},
{"misc", 0, 0, '#'},

24
mdadm.c
View File

@ -93,6 +93,7 @@ int main(int argc, char *argv[])
struct supertype *ss = NULL;
int writemostly = 0;
int re_add = 0;
char *shortopt = short_options;
int copies;
@ -113,7 +114,7 @@ int main(int argc, char *argv[])
while ((option_index = -1) ,
(opt=getopt_long(argc, argv,
short_options, long_options,
shortopt, long_options,
&option_index)) != -1) {
int newmode = mode;
/* firstly, some mode-independant options */
@ -150,6 +151,10 @@ int main(int argc, char *argv[])
if (mode == ASSEMBLE || mode == BUILD || mode == CREATE || mode == GROW)
break; /* b means bitmap */
brief = 1;
if (optarg) {
fprintf(stderr, Name ": -b cannot have any extra immediately after it, sorry.\n");
exit(2);
}
continue;
case ':':
@ -164,19 +169,24 @@ int main(int argc, char *argv[])
switch(opt) {
case '@': /* just incase they say --manage */
newmode = MANAGE; break;
newmode = MANAGE;
shortopt = short_bitmap_auto_options;
break;
case 'a':
case 'r':
case 'f':
case 6: /* re-add */
if (!mode) newmode = MANAGE;
if (!mode) {
newmode = MANAGE;
shortopt = short_bitmap_auto_options;
}
break;
case 'A': newmode = ASSEMBLE; break;
case 'B': newmode = BUILD; break;
case 'C': newmode = CREATE; break;
case 'A': newmode = ASSEMBLE; shortopt = short_bitmap_auto_options; break;
case 'B': newmode = BUILD; shortopt = short_bitmap_auto_options; break;
case 'C': newmode = CREATE; shortopt = short_bitmap_auto_options; break;
case 'F': newmode = MONITOR;break;
case 'G': newmode = GROW; break;
case 'G': newmode = GROW; shortopt = short_bitmap_auto_options; break;
case '#':
case 'D':

View File

@ -91,6 +91,7 @@ enum mode {
};
extern char short_options[];
extern char short_bitmap_auto_options[];
extern struct option long_options[];
extern char Version[], Usage[], Help[], OptionHelp[],
Help_create[], Help_build[], Help_assemble[], Help_grow[],