- /* 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 &&
- 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");
+ cnlen = strlen(cname);
+ while (conflict) {
+ if (trustworthy == METADATA && !isdigit(cname[cnlen-1]))
+ sprintf(cname+cnlen, "%d", unum);
+ else
+ /* add _%d to FOREIGN array that don't
+ * a 'host:' prefix
+ */
+ sprintf(cname+cnlen, "_%d", unum);
+ unum++;
+ if (map_by_name(&map, cname) == NULL)
+ conflict = 0;
+ }
+ }
+
+ devnm[0] = 0;
+ if (num < 0 && cname && ci->names) {
+ int fd;
+ int n = -1;
+ sprintf(devnm, "md_%s", cname);
+ fd = open("/sys/module/md_mod/parameters/new_array", O_WRONLY);
+ if (fd >= 0) {
+ n = write(fd, devnm, strlen(devnm));
+ close(fd);
+ }
+ if (n < 0)
+ devnm[0] = 0;
+ }
+ if (devnm[0])
+ ;
+ else if (num < 0) {
+ /* need to choose a free number. */
+ char *_devnm = find_free_devnm(use_mdp);
+ if (devnm == NULL) {
+ pr_err("No avail md devices - aborting\n");
+ return -1;
+ }
+ strcpy(devnm, _devnm);
+ } else {
+ sprintf(devnm, "%s%d", use_mdp?"md_d":"md", num);
+ if (mddev_busy(devnm)) {
+ pr_err("%s is already in use.\n",
+ dev);
+ return -1;
+ }
+ }
+
+ sprintf(devname, "/dev/%s", devnm);
+
+ if (dev && dev[0] == '/')
+ strcpy(chosen, dev);
+ else if (cname[0] == 0)
+ strcpy(chosen, devname);
+
+ /* We have a device number and name.
+ * If we cannot detect udev, we need to make
+ * devices and links ourselves.
+ */
+ if (!use_udev()) {
+ /* Make sure 'devname' exists and 'chosen' is a symlink to it */
+ if (lstat(devname, &stb) == 0) {
+ /* Must be the correct device, else error */
+ if ((stb.st_mode&S_IFMT) != S_IFBLK ||
+ stb.st_rdev != (dev_t)devnm2devid(devnm)) {
+ pr_err("%s exists but looks wrong, please fix\n",
+ devname);