int dig = isdigit(dev[strlen(dev)-1]);
char orig[1024];
char sym[1024];
+ int err;
if (cnt==0) cnt=4;
if (lstat(dev, &stb)!= 0)
perror("chown");
if (chmod(name, stb2.st_mode & 07777))
perror("chmod");
+ err = 0;
} else {
snprintf(sym, sizeof(sym), "%s%s%d", orig, odig?"p":"", i);
- symlink(sym, name);
+ err = symlink(sym, name);
}
- stat(name, &stb2);
- add_dev(name, &stb2, 0, NULL);
+
+ if (err == 0 && stat(name, &stb2) == 0)
+ add_dev(name, &stb2, 0, NULL);
}
}
use_mdp = 0;
}
if (num < 0 && trustworthy == LOCAL && name) {
- /* if name is numeric, use that for num
+ /* if name is numeric, possibly prefixed by
+ * 'md' or '/dev/md', use that for num
* if it is not already in use */
char *ep;
- num = strtoul(name, &ep, 10);
- if (ep == name || *ep)
+ char *n2 = name;
+ if (strncmp(n2, "/dev/", 5) == 0)
+ n2 += 5;
+ if (strncmp(n2, "md", 2) == 0)
+ n2 += 2;
+ if (*n2 == '/')
+ n2++;
+ num = strtoul(n2, &ep, 10);
+ if (ep == n2 || *ep)
num = -1;
else if (mddev_busy(use_mdp ? (-1-num) : num))
num = -1;
}
cnlen = strlen(cname);
while (conflict) {
- if (trustworthy == METADATA)
+ if (trustworthy == METADATA && !isdigit(cname[cnlen-1]))
sprintf(cname+cnlen, "%d", unum);
else
/* add _%d to FOREIGN array that don't
chosen);
strcpy(chosen, devname);
}
- } else
- symlink(devname, chosen);
+ } else if (symlink(devname, chosen) != 0)
+ fprintf(stderr, Name ": failed to create %s: %s\n",
+ chosen, strerror(errno));
if (use_mdp && strcmp(chosen, devname) != 0)
make_parts(chosen, parts);
}