]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Allow parse_size to return 0.
authorNeilBrown <neilb@suse.de>
Thu, 4 Oct 2012 06:34:20 +0000 (16:34 +1000)
committerNeilBrown <neilb@suse.de>
Thu, 4 Oct 2012 06:34:20 +0000 (16:34 +1000)
We will shortly introduce --data-offset= which is allowed to
be zero.  We will want to use parse_size() so it needs to be
able to return '0' without it being an error.

So define INVALID_SECTORS to be an impossible value (currently '1')
and return and test for it consistently.

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

diff --git a/mdadm.c b/mdadm.c
index 870e5376b5bb38414ca25bec5a27eabbe063249a..51c57c5d06dabdb8a9d2c720440ba10b3095be00 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -372,7 +372,8 @@ int main(int argc, char *argv[])
                                exit(2);
                        }
                        s.chunk = parse_size(optarg);
-                       if (s.chunk < 8 || (s.chunk&1)) {
+                       if (s.chunk == INVALID_SECTORS ||
+                           s.chunk < 8 || (s.chunk&1)) {
                                pr_err("invalid chunk/rounding value: %s\n",
                                        optarg);
                                exit(2);
@@ -426,7 +427,8 @@ int main(int argc, char *argv[])
                                s.size = MAX_SIZE;
                        else {
                                s.size = parse_size(optarg);
-                               if (s.size < 8) {
+                               if (s.size == INVALID_SECTORS ||
+                                   s.size < 8) {
                                        pr_err("invalid size: %s\n",
                                                optarg);
                                        exit(2);
@@ -446,7 +448,8 @@ int main(int argc, char *argv[])
                                array_size = MAX_SIZE;
                        else {
                                array_size = parse_size(optarg);
-                               if (array_size <= 0) {
+                               if (array_size == 0 ||
+                                   array_size == INVALID_SECTORS) {
                                        pr_err("invalid array size: %s\n",
                                                optarg);
                                        exit(2);
@@ -1062,7 +1065,8 @@ int main(int argc, char *argv[])
                case O(BUILD,BitmapChunk):
                case O(CREATE,BitmapChunk): /* bitmap chunksize */
                        s.bitmap_chunk = parse_size(optarg);
-                       if (s.bitmap_chunk <= 0 ||
+                       if (s.bitmap_chunk == 0 ||
+                           s.bitmap_chunk == INVALID_SECTORS ||
                            s.bitmap_chunk & (s.bitmap_chunk - 1)) {
                                pr_err("invalid bitmap chunksize: %s\n",
                                       optarg);
diff --git a/mdadm.h b/mdadm.h
index 6980bfb8195e9e014ccb62464f86c227bd1a9360..6db7714a291774552ba82763a3d76719f8b89365 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -1460,4 +1460,10 @@ char *xstrdup(const char *str);
  * In those cases with use MAX_SIZE
  */
 #define MAX_SIZE       1
+
+/* We want to use unsigned numbers for sector counts, but need
+ * a value for 'invalid'.  Use '1'.
+ */
+#define INVALID_SECTORS 1
+
 extern int __offroot;
diff --git a/util.c b/util.c
index fad72cc951ecad77ce17a44f4575420452d5b4ee..4bd07e1b969f9f04664b238687b142748bbf6e40 100644 (file)
--- a/util.c
+++ b/util.c
@@ -194,7 +194,7 @@ unsigned 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)
-        * 0 returned on error.
+        * INVALID_SECTORS returned on error.
         */
        char *c;
        long long s = strtoll(size, &c, 10);
@@ -215,9 +215,9 @@ unsigned long long parse_size(char *size)
                        break;
                }
        } else
-               s = 0;
+               s = INVALID_SECTORS;
        if (*c)
-               s = 0;
+               s = INVALID_SECTORS;
        return s;
 }