Stop map_dev from returning [0:0]
authorNeil Brown <neilb@suse.de>
Tue, 20 Jun 2006 00:01:43 +0000 (10:01 +1000)
committerNeil Brown <neilb@suse.de>
Tue, 20 Jun 2006 00:01:43 +0000 (10:01 +1000)
We sometimes need the NULL when major==minor==0.
So make sure all callers of map_dev can cope with NULL.

Grow.c
config.c
util.c

diff --git a/Grow.c b/Grow.c
index 61347b7..1ab4fbc 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -657,7 +657,7 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
                                offsets[sd->role] = sd->offset;
                                if (fdlist[sd->role] < 0) {
                                        fprintf(stderr, Name ": %s: cannot open component %s\n",
-                                               devname, dn);
+                                               devname, dn?dn:"-unknown-");
                                        goto abort;
                                }
                        } else {
@@ -667,7 +667,7 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file,
                                offsets[d] = sd->offset;
                                if (fdlist[d]<0) {
                                        fprintf(stderr, Name ": %s: cannot open component %s\n",
-                                               devname, dn);
+                                               devname, dn?dn:"-unknown");
                                        goto abort;
                                }
                                d++;
index 20dc725..157bdff 100644 (file)
--- a/config.c
+++ b/config.c
@@ -242,7 +242,8 @@ mddev_dev_t load_partitions(void)
                minor = strtoul(mp, NULL, 10);
 
                name = map_dev(major, minor, 1);
-
+               if (!name)
+                       continue;
                d = malloc(sizeof(*d));
                d->devname = strdup(name);
                d->next = rv;
diff --git a/util.c b/util.c
index d54d445..2cb6dd3 100644 (file)
--- a/util.c
+++ b/util.c
@@ -417,12 +417,9 @@ char *map_dev(int major, int minor, int create)
        char *std = NULL, *nonstd=NULL;
        int did_check = 0;
 
-       if (major == 0 && minor == 0) {
-               if (!create)
+       if (major == 0 && minor == 0)
                        return NULL;
-               else
-                       return "0:0";
-       }
+
  retry:
        if (!devlist_ready) {
                char *dev = "/dev";
@@ -636,8 +633,12 @@ int dev_open(char *dev, int flags)
        char *e;
        int fd = -1;
        char devname[32];
-       int major = strtoul(dev, &e, 0);
+       int major;
        int minor;
+
+       if (!dev) return -1;
+
+       major = strtoul(dev, &e, 0);
        if (e > dev && *e == ':' && e[1] &&
            (minor = strtoul(e+1, &e, 0)) >= 0 &&
            *e == 0) {