/*
* mdadm - manage Linux "md" devices aka RAID arrays.
*
- * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
+ * Copyright (C) 2001-2009 Neil Brown <neilb@suse.de>
*
*
* This program is free software; you can redistribute it and/or modify
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Neil Brown
- * Email: <neilb@cse.unsw.edu.au>
- * Paper: Neil Brown
- * School of Computer Science and Engineering
- * The University of New South Wales
- * Sydney, 2052
- * Australia
+ * Email: <neilb@suse.de>
*/
#include "mdadm.h"
int odig = odig; /* quiet gcc -Os unitialized warning */
int i;
int nlen = strlen(dev) + 20;
- char *name = malloc(nlen);
+ char *name;
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)
return;
+
if (S_ISLNK(stb.st_mode)) {
int len = readlink(dev, orig, sizeof(orig));
if (len < 0 || len > 1000)
minor_num = minor(stb.st_rdev);
} else
return;
+ name = malloc(nlen);
for (i=1; i <= cnt ; i++) {
struct stat stb2;
snprintf(name, nlen, "%s%s%d", dev, dig?"p":"", i);
perror("chown");
if (chmod(name, stb2.st_mode & 07777))
perror("chmod");
+ err = 0;
} else {
- snprintf(sym, 10000, "%s%s%d", orig, odig?"p":"", i);
- symlink(sym, name);
+ snprintf(sym, sizeof(sym), "%s%s%d", orig, odig?"p":"", i);
+ 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);
}
+ free(name);
}
if (dev) {
-
if (strncmp(dev, "/dev/md/", 8) == 0) {
strcpy(cname, dev+8);
} else if (strncmp(dev, "/dev/", 5) == 0) {
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
conflict = 0;
}
}
- if (cname[0] == 0)
+
+ if (dev && dev[0] == '/')
+ strcpy(chosen, dev);
+ else if (cname[0] == 0)
strcpy(chosen, devname);
/* We have a device number and name.
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);
}