summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorNeil Brown <neilb@suse.de>2005-04-04 05:16:10 +0000
committerNeil Brown <neilb@suse.de>2005-04-04 05:16:10 +0000
commit8d80900b492998a112eda80614a793012bee2770 (patch)
tree5f5e4d00396ccd6b6606ec56a191e17240a9d97a /util.c
parent182661f4097636eb5578ca1d8291880114f15ad0 (diff)
downloadmdadm-8d80900b492998a112eda80614a793012bee2770.tar.gz
mdadm-8d80900b492998a112eda80614a793012bee2770.tar.xz
mdadm-8d80900b492998a112eda80614a793012bee2770.zip
When assembling with --auto, honour common device names
Signed-off-by: Neil Brown <neilb@cse.unsw.edu.au>
Diffstat (limited to 'util.c')
-rw-r--r--util.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/util.c b/util.c
index 121ddbb..2396871 100644
--- a/util.c
+++ b/util.c
@@ -395,28 +395,37 @@ int map_name(mapping_t *map, char *name)
}
-int is_standard(char *dev)
+int is_standard(char *dev, int *nump)
{
/* tests if dev is a "standard" md dev name.
* i.e if the last component is "/dNN" or "/mdNN",
* where NN is a string of digits
*/
- dev = strrchr(dev, '/');
- if (!dev)
+ char *d = strrchr(dev, '/');
+ int type=0;
+ int num;
+ if (!d)
return 0;
- if (strncmp(dev, "/d",2)==0)
- dev += 2;
- else if (strncmp(dev, "/md", 3)==0)
- dev += 3;
+ if (strncmp(d, "/d",2)==0)
+ d += 2, type=1; /* /dev/md/dN{pM} */
+ else if (strncmp(d, "/md_d", 5)==0)
+ d += 5, type=1; /* /dev/md_dNpM */
+ else if (strncmp(d, "/md", 3)==0)
+ d += 3, type=-1; /* /dev/mdN */
+ else if (d-dev > 3 && strncmp(d-2, "md/", 3)==0)
+ type = -1; /* /dev/md/N */
else
return 0;
- if (!*dev)
+ if (!*d)
return 0;
- while (isdigit(*dev))
- dev++;
- if (*dev)
+ num = atoi(d);
+ while (isdigit(*d))
+ d++;
+ if (*d)
return 0;
- return 1;
+ if (nump) *nump = num;
+
+ return type;
}
@@ -468,7 +477,7 @@ int add_dev(const char *name, const struct stat *stb, int flag)
/*
* Find a block device with the right major/minor number.
- * Avoid /dev/mdNN and /dev/md/dNN is possible
+ * Avoid /dev/mdNN and /dev/md/dNN if possible
*/
char *map_dev(int major, int minor)
{
@@ -486,7 +495,7 @@ char *map_dev(int major, int minor)
for (p=devlist; p; p=p->next)
if (p->major == major &&
p->minor == minor) {
- if (is_standard(p->name))
+ if (is_standard(p->name, NULL))
std = p->name;
else
return p->name;
@@ -620,7 +629,7 @@ char *get_md_name(int dev)
&& (stb.st_rdev == rdev))
return devname;
}
- dn = map_dev(MAJOR(rdev), MINOR(rdev));
+ dn = map_dev(major(rdev), minor(rdev));
if (dn)
return dn;
sprintf(devname, "/dev/.tmp.md%d", dev);