* else that of dev
*/
struct stat stb;
- int major_num, minor_num;
+ 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 i;
int nlen = strlen(dev) + 20;
char *name = malloc(nlen);
int dig = isdigit(dev[strlen(dev)-1]);
char orig[1024];
char sym[1024];
- int odig;
if (cnt==0) cnt=4;
if (lstat(dev, &stb)!= 0)
if (chmod(name, stb2.st_mode & 07777))
perror("chmod");
} else {
- snprintf(sym, 10000, "%s%s%d", orig, odig?"p":"", i);
+ snprintf(sym, sizeof(sym), "%s%s%d", orig, odig?"p":"", i);
symlink(sym, name);
}
stat(name, &stb2);
use_mdp = 0;
}
if (num < 0 && trustworthy == LOCAL && name) {
- /* if name is numeric, us that for num */
+ /* if name is numeric, use that for num
+ * if it is not already in use */
char *ep;
num = strtoul(name, &ep, 10);
if (ep == name || *ep)
num = -1;
+ else if (mddev_busy(use_mdp ? (-1-num) : num))
+ num = -1;
}
if (num < 0) {
* reasonable length and remove '/'
*/
char *cp;
+ struct map_ent *map = NULL;
+ int conflict = 1;
+ int unum = 0;
+ int cnlen;
strncpy(cname, name, 200);
cname[200] = 0;
while ((cp = strchr(cname, '/')) != NULL)
*cp = '-';
- if (trustworthy == METADATA)
- /* always add device number to metadata */
- sprintf(cname+strlen(cname), "%d", num);
- else if (trustworthy == FOREIGN &&
- strchr(cname, ':') == NULL)
- /* add _%d to FOREIGN array that don't have
- * a 'host:' prefix
- */
- sprintf(cname+strlen(cname), "_%d", num<0?(-1-num):num);
+ if (trustworthy == LOCAL ||
+ (trustworthy == FOREIGN && strchr(cname, ':') != NULL)) {
+ /* Only need suffix if there is a conflict */
+ if (map_by_name(&map, cname) == NULL)
+ conflict = 0;
+ }
+ cnlen = strlen(cname);
+ while (conflict) {
+ if (trustworthy == METADATA)
+ 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;
+ }
}
if (cname[0] == 0)
strcpy(chosen, devname);