- for (num = 127 ; num != 128 ; num = num ? num-1 : (1<<22)-1) {
- struct mdstat_ent *me;
- int devnum = num;
- if (major_num != MD_MAJOR)
- devnum = -1-num;
-
- for (me=mdlist; me; me=me->next)
- if (me->devnum == devnum)
- break;
- if (!me) {
- /* doesn't exist in mdstat.
- * make sure it is new to /dev too
- */
- char *dn;
- if (major_num != MD_MAJOR)
- minor_num = num << MdpMinorShift;
- else
- minor_num = num;
- dn = map_dev(major_num,minor_num, 0);
- if (dn==NULL || is_standard(dn, NULL)) {
- /* this number only used by a 'standard' name,
- * so it is safe to use
- */
- break;
- }
- }
- }
- } else if (major_num == MD_MAJOR)
- minor_num = num;
- else
- minor_num = num << MdpMinorShift;
- /* major and minor have been chosen */
-
- /* 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_num &&
- minor(stb.st_rdev) == minor_num)
- ;
- else {
- if (major(makedev(major_num,minor_num)) != major_num ||
- minor(makedev(major_num,minor_num)) != minor_num) {
- 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 (strncmp(dev, "/dev/md/", 8) == 0) {
- if (mkdir("/dev/md",0700)==0) {
- if (chown("/dev/md", ci->uid, ci->gid))
- perror("chown /dev/md");
- if (chmod("/dev/md", ci->mode| ((ci->mode>>2) & 0111)))
- perror("chmod /dev/md");
- }
- }
- if (mknod(dev, S_IFBLK|0600, makedev(major_num, minor_num))!= 0) {
- fprintf(stderr, Name ": failed to create %s\n", dev);
- return -1;
- }
- if (must_remove) {
- if (chown(dev, stb.st_uid, stb.st_gid))
- perror("chown");
- if (chmod(dev, stb.st_mode & 07777))
- perror("chmod");
- } else {
- if (chown(dev, ci->uid, ci->gid))
- perror("chown");
- if (chmod(dev, ci->mode))
- perror("chmod");
- }
- stat(dev, &stb);
- add_dev(dev, &stb, 0, NULL);
- if (ci->symlinks && strncmp(dev, "/dev/md/", 8) == 0)
- make_dev_symlink(dev);
- if (major_num != MD_MAJOR)
- make_parts(dev,parts, ci->symlinks);