* else that of dev
*/
struct stat stb;
- int major_num = major_num; /* quiet gcc -Os unitialized warning */
- int minor_num = minor_num; /* quiet gcc -Os unitialized warning */
- int odig = odig; /* quiet gcc -Os unitialized warning */
+ int major_num;
+ int minor_num;
+ int odig;
int i;
int nlen = strlen(dev) + 20;
char *name;
if (lstat(dev, &stb)!= 0)
return;
- if (S_ISLNK(stb.st_mode)) {
+ if (S_ISBLK(stb.st_mode)) {
+ major_num = major(stb.st_rdev);
+ minor_num = minor(stb.st_rdev);
+ odig = -1;
+ } else if (S_ISLNK(stb.st_mode)) {
int len = readlink(dev, orig, sizeof(orig));
if (len < 0 || len > 1000)
return;
orig[len] = 0;
odig = isdigit(orig[len-1]);
- } else if (S_ISBLK(stb.st_mode)) {
- major_num = major(stb.st_rdev);
- minor_num = minor(stb.st_rdev);
+ major_num = -1;
+ minor_num = -1;
} else
- return;
+ return;
name = malloc(nlen);
for (i=1; i <= cnt ; i++) {
struct stat stb2;
snprintf(name, nlen, "%s%s%d", dev, dig?"p":"", i);
if (stat(name, &stb2)==0) {
- if (!S_ISBLK(stb2.st_mode))
+ if (!S_ISBLK(stb2.st_mode) || !S_ISBLK(stb.st_mode))
continue;
if (stb2.st_rdev == makedev(major_num, minor_num+i))
continue;
char *ep;
if (cname[0] == 'd')
sp++;
- num = strtoul(sp, &ep, 10);
+ if (isdigit(sp[0]))
+ num = strtoul(sp, &ep, 10);
+ else
+ ep = sp;
if (ep == sp || *ep || num < 0)
num = -1;
else if (cname[0] == 'd')
int cnlen;
strncpy(cname, name, 200);
cname[200] = 0;
- while ((cp = strchr(cname, '/')) != NULL)
- *cp = '-';
+ for (cp = cname; *cp ; cp++)
+ switch (*cp) {
+ case '/':
+ *cp = '-';
+ break;
+ case ' ':
+ case '\t':
+ *cp = '_';
+ break;
+ }
+
if (trustworthy == LOCAL ||
(trustworthy == FOREIGN && strchr(cname, ':') != NULL)) {
/* Only need suffix if there is a conflict */
* If we cannot detect udev, we need to make
* devices and links ourselves.
*/
- if (stat("/dev/.udev", &stb) != 0 ||
+ if ((stat("/dev/.udev", &stb) != 0 && stat("/run/udev", &stb) != 0) ||
check_env("MDADM_NO_UDEV")) {
/* Make sure 'devname' exists and 'chosen' is a symlink to it */
if (lstat(devname, &stb) == 0) {
if (lstat(chosen, &stb) == 0) {
char buf[300];
+ ssize_t link_len = readlink(chosen, buf, sizeof(buf)-1);
+ if (link_len >= 0)
+ buf[link_len] = '\0';
+
if ((stb.st_mode & S_IFMT) != S_IFLNK ||
- readlink(chosen, buf, 300) <0 ||
+ link_len < 0 ||
strcmp(buf, devname) != 0) {
fprintf(stderr, Name ": %s exists - ignoring\n",
chosen);