Change MAJOR() etc to major() etc
authorNeil Brown <neilb@suse.de>
Mon, 4 Apr 2005 05:16:13 +0000 (05:16 +0000)
committerNeil Brown <neilb@suse.de>
Mon, 4 Apr 2005 05:16:13 +0000 (05:16 +0000)
This allows for larger device number if glibc supports
it (requires 2.3.3).
Also fail before creating larger device number if glibc
support isn't present.

Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au>
12 files changed:
Assemble.c
Build.c
ChangeLog
Create.c
Detail.c
Grow.c
Manage.c
Monitor.c
Query.c
mdadm.c
mdopen.c
util.c

index 3f22ae9..4003e06 100644 (file)
@@ -288,7 +288,7 @@ int Assemble(char *mddev, int mdfd,
                        if (strcmp(update, "super-minor") ==0) {
                                struct stat stb2;
                                fstat(mdfd, &stb2);
-                               super.md_minor = MINOR(stb2.st_rdev);
+                               super.md_minor = minor(stb2.st_rdev);
                                if (verbose)
                                        fprintf(stderr, Name ": updating superblock of %s with minor number %d\n",
                                                devname, super.md_minor);
@@ -341,8 +341,8 @@ int Assemble(char *mddev, int mdfd,
                        fprintf(stderr, Name ": %s is identified as a member of %s, slot %d.\n",
                                devname, mddev, super.this_disk.raid_disk);
                devices[devcnt].devname = devname;
-               devices[devcnt].major = MAJOR(stb.st_rdev);
-               devices[devcnt].minor = MINOR(stb.st_rdev);
+               devices[devcnt].major = major(stb.st_rdev);
+               devices[devcnt].minor = minor(stb.st_rdev);
                devices[devcnt].oldmajor = super.this_disk.major;
                devices[devcnt].oldminor = super.this_disk.minor;
                devices[devcnt].events = md_event(&super);
@@ -665,7 +665,7 @@ This doesnt work yet
                 * so we can just start the array
                 */
                unsigned long dev;
-               dev = MKDEV(devices[chosen_drive].major,
+               dev = makedev(devices[chosen_drive].major,
                            devices[chosen_drive].minor);
                if (ioctl(mdfd, START_ARRAY, dev)) {
                    fprintf(stderr, Name ": Cannot start array: %s\n",
diff --git a/Build.c b/Build.c
index bf97533..6bb3a62 100644 (file)
--- a/Build.c
+++ b/Build.c
@@ -117,7 +117,7 @@ int Build(char *mddev, int mdfd, int chunk, int level, int layout,
                array.raid_disks = raiddisks;
                array.md_minor = 0;
                if (fstat(mdfd, &stb)==0)
-                       array.md_minor = MINOR(stb.st_rdev);
+                       array.md_minor = minor(stb.st_rdev);
                array.not_persistent = 1;
                array.state = 0; /* not clean, but no errors */
                if (assume_clean)
@@ -153,8 +153,8 @@ int Build(char *mddev, int mdfd, int chunk, int level, int layout,
                        disk.number = i;
                        disk.raid_disk = i;
                        disk.state = 6;
-                       disk.major = MAJOR(stb.st_rdev);
-                       disk.minor = MINOR(stb.st_rdev);
+                       disk.major = major(stb.st_rdev);
+                       disk.minor = minor(stb.st_rdev);
                        if (ioctl(mdfd, ADD_NEW_DISK, &disk)) {
                                fprintf(stderr, Name ": ADD_NEW_DISK failed for %s: %s\n",
                                        dv->devname, strerror(errno));
index 092be38..aede7da 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,9 @@ Changes Prior to 1.9.0 release
     -   Remove underscore from partition names, so partitions of 
        "foo" are "foo1", "foo2" etc (unchanged) and partitions of
        "f00" are "f00p1", "f00p2" etc rather than "f00_p1"...
+    -   Use "major", "minor", "makedev" macros instead of 
+       "MAJOR", "MINOR", "MKDEV" so that large device numbers work
+       on 2.6 (providing you have glibc 2.3.3 or later).
 
 Changes Prior to 1.8.0 release
     -   Makefile cleanup from  Luca Berra <bluca@comedia.it>
index 7b4988e..1c814f7 100644 (file)
--- a/Create.c
+++ b/Create.c
@@ -305,7 +305,7 @@ int Create(char *mddev, int mdfd,
         */
        array.md_minor = 0;
        if (fstat(mdfd, &stb)==0)
-               array.md_minor = MINOR(stb.st_rdev);
+               array.md_minor = minor(stb.st_rdev);
        array.not_persistent = 0;
        /*** FIX: Need to do something about RAID-6 here ***/
        if ( ( (level == 5) &&
@@ -375,8 +375,8 @@ int Create(char *mddev, int mdfd,
                                return 1;
                        }
                        fstat(fd, &stb);
-                       disk.major = MAJOR(stb.st_rdev);
-                       disk.minor = MINOR(stb.st_rdev);
+                       disk.major = major(stb.st_rdev);
+                       disk.minor = minor(stb.st_rdev);
                        close(fd);
                }
                if (ioctl(mdfd, ADD_NEW_DISK, &disk)) {
index c8992cc..7555a9a 100644 (file)
--- a/Detail.c
+++ b/Detail.c
@@ -124,7 +124,7 @@ int Detail(char *dev, int brief, int test)
                struct mdstat_ent *ms = mdstat_read(0);
                struct mdstat_ent *e;
                int devnum = array.md_minor;
-               if (MAJOR(stb.st_rdev) != MD_MAJOR)
+               if (major(stb.st_rdev) != MD_MAJOR)
                        devnum = -1 - devnum;
 
                for (e=ms; e; e=e->next)
@@ -251,8 +251,8 @@ int Detail(char *dev, int brief, int test)
                                         * device from the array, and then put it back.
                                         * If this fails, we are rebuilding
                                         */
-                                       int err = ioctl(fd, HOT_REMOVE_DISK, MKDEV(disk.major, disk.minor));
-                                       if (err == 0) ioctl(fd, HOT_ADD_DISK, MKDEV(disk.major, disk.minor));
+                                       int err = ioctl(fd, HOT_REMOVE_DISK, makedev(disk.major, disk.minor));
+                                       if (err == 0) ioctl(fd, HOT_ADD_DISK, makedev(disk.major, disk.minor));
                                        if (err && errno ==  EBUSY)
                                                printf(" rebuilding");
                                }
diff --git a/Grow.c b/Grow.c
index 82283bc..3f8a1c6 100644 (file)
--- a/Grow.c
+++ b/Grow.c
@@ -109,8 +109,8 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
        
        memset(&super.disks[d], 0, sizeof(super.disks[d]));
        super.disks[d].number = d;
-       super.disks[d].major = MAJOR(stb.st_rdev);
-       super.disks[d].minor = MINOR(stb.st_rdev);
+       super.disks[d].major = major(stb.st_rdev);
+       super.disks[d].minor = minor(stb.st_rdev);
        super.disks[d].raid_disk = d;
        super.disks[d].state = (1 << MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE);
 
@@ -122,8 +122,8 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
                return 1;
        }
        disk.number = d;
-       disk.major = MAJOR(stb.st_rdev);
-       disk.minor = MINOR(stb.st_rdev);
+       disk.major = major(stb.st_rdev);
+       disk.minor = minor(stb.st_rdev);
        disk.raid_disk = d;
        disk.state = (1 << MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE);
        close(nfd);
@@ -173,8 +173,8 @@ int Grow_Add_device(char *devname, int fd, char *newdev)
                super.working_disks = nd+1;
                memset(&super.disks[nd], 0, sizeof(super.disks[nd]));
                super.disks[nd].number = nd;
-               super.disks[nd].major = MAJOR(stb.st_rdev);
-               super.disks[nd].minor = MINOR(stb.st_rdev);
+               super.disks[nd].major = major(stb.st_rdev);
+               super.disks[nd].minor = minor(stb.st_rdev);
                super.disks[nd].raid_disk = nd;
                super.disks[nd].state = (1 << MD_DISK_SYNC) | (1 << MD_DISK_ACTIVE);
 
index 56cc1ad..8835095 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -226,8 +226,8 @@ int Manage_subdevs(char *devname, int fd,
                        disc.number =j;
                        disc.raid_disk = j;
                        disc.state = 0;
-                       disc.major = MAJOR(stb.st_rdev);
-                       disc.minor = MINOR(stb.st_rdev);
+                       disc.major = major(stb.st_rdev);
+                       disc.minor = minor(stb.st_rdev);
                        if (ioctl(fd,ADD_NEW_DISK, &disc)) {
                                fprintf(stderr, Name ": add new device failed for %s: %s\n",
                                        dv->devname, strerror(errno));
index 036c47f..16a39b4 100644 (file)
--- a/Monitor.c
+++ b/Monitor.c
@@ -246,10 +246,10 @@ int Monitor(mddev_dev_t devlist,
                                struct stat stb;
                                if (fstat(fd, &stb) == 0 &&
                                    (S_IFMT&stb.st_mode)==S_IFBLK) {
-                                       if (MAJOR(stb.st_rdev) == MD_MAJOR)
-                                               st->devnum = MINOR(stb.st_rdev);
+                                       if (major(stb.st_rdev) == MD_MAJOR)
+                                               st->devnum = minor(stb.st_rdev);
                                        else
-                                               st->devnum = -1- (MINOR(stb.st_rdev)>>6);
+                                               st->devnum = -1- (minor(stb.st_rdev)>>6);
                                }
                        }
 
@@ -323,7 +323,7 @@ int Monitor(mddev_dev_t devlist,
                                                alert("Fail", dev, dv, mailaddr, alert_cmd);
                                        else if (i >= (unsigned)array.raid_disks &&
                                                 (disc.major || disc.minor) &&
-                                                st->devid[i] == MKDEV(disc.major, disc.minor) &&
+                                                st->devid[i] == makedev(disc.major, disc.minor) &&
                                                 ((newstate&change)&(1<<MD_DISK_FAULTY))
                                                )
                                                alert("FailSpare", dev, dv, mailaddr, alert_cmd);
@@ -335,7 +335,7 @@ int Monitor(mddev_dev_t devlist,
                                                alert("SpareActive", dev, dv, mailaddr, alert_cmd);
                                }
                                st->devstate[i] = disc.state;
-                               st->devid[i] = MKDEV(disc.major, disc.minor);
+                               st->devid[i] = makedev(disc.major, disc.minor);
                        }
                        close(fd);
                        st->active = array.active_disks;
diff --git a/Query.c b/Query.c
index 28450bd..3f58c8b 100644 (file)
--- a/Query.c
+++ b/Query.c
@@ -129,7 +129,7 @@ int Query(char *dev)
                        if (md_get_version(fd) >= 9000 &&       
                            ioctl(fd, GET_ARRAY_INFO, &array)>= 0) {
                                if (ioctl(fd, GET_DISK_INFO, &disc) >= 0 &&
-                                   MKDEV((unsigned)disc.major,(unsigned)disc.minor) == stb.st_rdev)
+                                   makedev((unsigned)disc.major,(unsigned)disc.minor) == stb.st_rdev)
                                        activity = "active";
                                else
                                        activity = "mismatch";
diff --git a/mdadm.c b/mdadm.c
index 1c67b3b..a6f116f 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -675,7 +675,7 @@ int main(int argc, char *argv[])
                if ((int)ident.super_minor == -2) {
                        struct stat stb;
                        fstat(mdfd, &stb);
-                       ident.super_minor = MINOR(stb.st_rdev);
+                       ident.super_minor = minor(stb.st_rdev);
                }
        }
 
index 4e1ce6a..1ba5201 100644 (file)
--- a/mdopen.c
+++ b/mdopen.c
@@ -49,21 +49,21 @@ void make_parts(char *dev, int cnt)
                return;
        if (!S_ISBLK(stb.st_mode))
                return;
-       major = MAJOR(stb.st_rdev);
-       minor = MINOR(stb.st_rdev);
+       major = major(stb.st_rdev);
+       minor = minor(stb.st_rdev);
        for (i=1; i <= cnt ; i++) {
                struct stat stb2;
                sprintf(name, "%s%s%d", dev, dig?"p":"", i);
                if (stat(name, &stb2)==0) {
                        if (!S_ISBLK(stb2.st_mode))
                                continue;
-                       if (stb2.st_rdev == MKDEV(major, minor+i))
+                       if (stb2.st_rdev == makedev(major, minor+i))
                                continue;
                        unlink(name);
                } else {
                        stb2 = stb;
                }
-               mknod(name, S_IFBLK | 0600, MKDEV(major, minor+i));
+               mknod(name, S_IFBLK | 0600, makedev(major, minor+i));
                chown(name, stb2.st_uid, stb2.st_gid);
                chmod(name, stb2.st_mode & 07777);
        }
@@ -101,7 +101,7 @@ int open_mddev(char *dev, int autof)
                /* check major number is correct */
                if (autof>0)
                        major = get_mdp_major();
-               if (stb.st_mode && MAJOR(stb.st_rdev) != major)
+               if (stb.st_mode && major(stb.st_rdev) != major)
                        must_remove = 1;
                if (stb.st_mode && !must_remove) {
                        mdu_array_info_t array;
@@ -181,14 +181,19 @@ int open_mddev(char *dev, int autof)
                /* If it was a 'standard' name and it is in-use, then
                 * the device could already be correct
                 */
-               if (stb.st_mode && MAJOR(stb.st_rdev) == major &&
-                   MINOR(stb.st_rdev) == minor)
+               if (stb.st_mode && major(stb.st_rdev) == major &&
+                   minor(stb.st_rdev) == minor)
                        ;
                else {
+                       if (major(makedev(major,minor)) != major ||
+                           minor(makedev(major,minor)) != minor) {
+                               fprintf(stderr, Name ": Need newer C library to use more than 4 partitionable md devices, sorry\n");
+                               return -1;
+                       }
                        if (must_remove)
                                unlink(dev);
 
-                       if (mknod(dev, S_IFBLK|0600, MKDEV(major, minor))!= 0) {
+                       if (mknod(dev, S_IFBLK|0600, makedev(major, minor))!= 0) {
                                fprintf(stderr, Name ": failed to create %s\n", dev);
                                return -1;
                        }
diff --git a/util.c b/util.c
index 2396871..05eb9c9 100644 (file)
--- a/util.c
+++ b/util.c
@@ -94,7 +94,7 @@ int md_get_version(int fd)
        return  (vers.major*10000) + (vers.minor*100) + vers.patchlevel;
     if (errno == EACCES)
            return -1;
-    if (MAJOR(stb.st_rdev) == MD_MAJOR)
+    if (major(stb.st_rdev) == MD_MAJOR)
        return (3600);
     return -1;
 }
@@ -465,8 +465,8 @@ int add_dev(const char *name, const struct stat *stb, int flag)
        char *n = strdup(name);
        struct devmap *dm = malloc(sizeof(*dm));
        if (dm) {
-           dm->major = MAJOR(stb->st_rdev);
-           dm->minor = MINOR(stb->st_rdev);
+           dm->major = major(stb->st_rdev);
+           dm->minor = minor(stb->st_rdev);
            dm->name = n;
            dm->next = devlist;
            devlist = dm;
@@ -609,14 +609,14 @@ char *get_md_name(int dev)
        if (dev < 0) {
                int mdp =  get_mdp_major();
                if (mdp < 0) return NULL;
-               rdev = MKDEV(mdp, (-1-dev)<<6);
+               rdev = makedev(mdp, (-1-dev)<<6);
                sprintf(devname, "/dev/md/d%d", -1-dev);
                if (stat(devname, &stb) == 0
                    && (S_IFMT&stb.st_mode) == S_IFBLK
                    && (stb.st_rdev == rdev))
                        return devname;
        } else {
-               rdev = MKDEV(MD_MAJOR, dev);
+               rdev = makedev(MD_MAJOR, dev);
                sprintf(devname, "/dev/md%d", dev);
                if (stat(devname, &stb) == 0
                    && (S_IFMT&stb.st_mode) == S_IFBLK