]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
parse_size: distinguish between 0 and error.
authorNeilBrown <neilb@suse.de>
Tue, 3 Apr 2012 18:00:42 +0000 (04:00 +1000)
committerNeilBrown <neilb@suse.de>
Wed, 4 Apr 2012 04:03:13 +0000 (14:03 +1000)
It isn't sufficient to use '0' for 'error' as well will
later have fields that can validly be '0'.

So return "-1" on error.

Also fix parsing of --bitmap_check so that '0' is treated
as an error: we don't support 512B anyway.

Signed-off-by: NeilBrown <neilb@suse.de>
mdadm.c
util.c

diff --git a/mdadm.c b/mdadm.c
index 1efa3e80a2eb40292f9379eb0270b17bc1584f4d..4d4820d39394c8e5dfcbfa556a7875391cb989cf 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -1056,15 +1056,14 @@ int main(int argc, char *argv[])
                case O(BUILD,BitmapChunk):
                case O(CREATE,BitmapChunk): /* bitmap chunksize */
                        bitmap_chunk = parse_size(optarg);
-                       if (bitmap_chunk < 0 ||
+                       if (bitmap_chunk <= 0 ||
                            bitmap_chunk & (bitmap_chunk - 1)) {
                                fprintf(stderr,
                                        Name ": invalid bitmap chunksize: %s\n",
                                        optarg);
                                exit(2);
                        }
-                       /* convert sectors to B, chunk of 0 means 512B */
-                       bitmap_chunk = bitmap_chunk ? bitmap_chunk * 512 : 512;
+                       bitmap_chunk = bitmap_chunk * 512;
                        continue;
 
                case O(GROW, WriteBehind):
diff --git a/util.c b/util.c
index d32e6506492fa980c4dc36f82b628f6943413752..b94205856bddf056aff7002f4416f3f4e06db05d 100644 (file)
--- a/util.c
+++ b/util.c
@@ -194,6 +194,7 @@ long long parse_size(char *size)
         * followed by 'K', 'M', or 'G'.
         * Without a suffix, K is assumed.
         * Number returned is in sectors (half-K)
+        * -1 returned on error.
         */
        char *c;
        long long s = strtoll(size, &c, 10);
@@ -215,7 +216,7 @@ long long parse_size(char *size)
                }
        }
        if (*c)
-               s = 0;
+               s = -1;
        return s;
 }