From 8615dcff2865a01e17bb63cdbcc6064c3c1b424a Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 11 May 2009 15:47:10 +1000 Subject: mapfile: allow the path name to the device to be empty. Allowing an empty name and coping with it is less confusing than seeing "/empty" appear. Signed-off-by: NeilBrown --- mapfile.c | 13 ++++++++----- mdadm.c | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/mapfile.c b/mapfile.c index 01185e6..3a26c6d 100644 --- a/mapfile.c +++ b/mapfile.c @@ -92,7 +92,7 @@ int map_write(struct map_ent *mel) fprintf(f, "%s ", mel->metadata); fprintf(f, "%08x:%08x:%08x:%08x ", mel->uuid[0], mel->uuid[1], mel->uuid[2], mel->uuid[3]); - fprintf(f, "%s\n", mel->path); + fprintf(f, "%s\n", mel->path?:""); } fflush(f); err = ferror(f); @@ -142,7 +142,7 @@ void map_add(struct map_ent **melp, me->devnum = devnum; strcpy(me->metadata, metadata); memcpy(me->uuid, uuid, 16); - me->path = strdup(path); + me->path = path ? strdup(path) : NULL; me->next = *melp; me->bad = 0; *melp = me; @@ -169,9 +169,10 @@ void map_read(struct map_ent **melp) return; while (fgets(buf, sizeof(buf), f)) { + path[0] = 0; if (sscanf(buf, " %3[mdp]%d %s %x:%x:%x:%x %200s", nam, &devnum, metadata, uuid, uuid+1, - uuid+2, uuid+3, path) == 8) { + uuid+2, uuid+3, path) >= 7) { if (strncmp(nam, "md", 2) != 0) continue; if (nam[2] == 'p') @@ -208,7 +209,7 @@ int map_update(struct map_ent **mpp, int devnum, char *metadata, strcpy(mp->metadata, metadata); memcpy(mp->uuid, uuid, 16); free(mp->path); - mp->path = strdup(path); + mp->path = path ? strdup(path) : NULL; break; } if (!mp) @@ -280,6 +281,8 @@ struct map_ent *map_by_name(struct map_ent **map, char *name) map_read(map); for (mp = *map ; mp ; mp = mp->next) { + if (!mp->path) + continue; if (strncmp(mp->path, "/dev/md/", 8) != 0) continue; if (strcmp(mp->path+8, name) != 0) @@ -334,7 +337,7 @@ void RebuildMap(void) path = map_dev(mdp, (-1-md->devnum)<< 6, 0); map_add(&map, md->devnum, info.text_version, - info.uuid, path ? : "/unknown"); + info.uuid, path); st->ss->free_super(st); break; } diff --git a/mdadm.c b/mdadm.c index 74d230e..3b14ea5 100644 --- a/mdadm.c +++ b/mdadm.c @@ -1257,7 +1257,8 @@ int main(int argc, char *argv[]) char *name; struct map_ent *me; me = map_by_devnum(&map, e->devnum); - if (me && me->path) + if (me && me->path + && strcmp(me->path, "/unknown") != 0) name = me->path; else name = get_md_name(e->devnum); -- cgit