From c06487ce2061b7acfe6bc40bea7ad12393b0e4c6 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Mon, 5 Dec 2005 05:54:33 +0000 Subject: [PATCH] Improve option parsing stuff ====Do Not Remove==== Status: ok Signed-off-by: Neil Brown --- Assemble.c | 5 +---- ChangeLog | 3 +++ Makefile | 2 +- ReadMe.c | 3 ++- mdadm.c | 24 +++++++++++++++++------- mdadm.h | 1 + 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Assemble.c b/Assemble.c index d251500d..c78a1b16 100644 --- a/Assemble.c +++ b/Assemble.c @@ -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)) { diff --git a/ChangeLog b/ChangeLog index 76cc6eaf..141e1b2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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. diff --git a/Makefile b/Makefile index 05b653bd..81102ea8 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/ReadMe.c b/ReadMe.c index cd69a1c6..81766ddd 100644 --- a/ReadMe.c +++ b/ReadMe.c @@ -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, '#'}, diff --git a/mdadm.c b/mdadm.c index 8af61e96..80873b22 100644 --- a/mdadm.c +++ b/mdadm.c @@ -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': diff --git a/mdadm.h b/mdadm.h index 97831b49..29bbdc48 100644 --- a/mdadm.h +++ b/mdadm.h @@ -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[], -- 2.39.2