Index: sbin/mdconfig/mdconfig.8 =================================================================== --- sbin/mdconfig/mdconfig.8 +++ sbin/mdconfig/mdconfig.8 @@ -55,6 +55,7 @@ .Op Fl u Ar unit .Op Fl x Ar sectors/track .Op Fl y Ar heads/cylinder +.Op Fl L Ar label .Nm .Fl d .Fl u Ar unit @@ -189,6 +190,12 @@ options can be used to specify a synthetic geometry. This is useful for constructing bootable images for later download to other devices. +.It Fl L Ar label +Associate a label (arbitrary string) with the new memory disk. +The label can then be inspected with +.Bd -literal -offset indent +.Nm Fl l v +.Ed .It Fl o Oo Cm no Oc Ns Ar option Set or reset options. .Bl -tag -width indent Index: sbin/mdconfig/mdconfig.c =================================================================== --- sbin/mdconfig/mdconfig.c +++ sbin/mdconfig/mdconfig.c @@ -79,7 +79,7 @@ fprintf(stderr, "usage: mdconfig -a -t type [-n] [-o [no]option] ... [-f file]\n" -" [-s size] [-S sectorsize] [-u unit]\n" +" [-s size] [-S sectorsize] [-u unit] [-L label]\n" " [-x sectors/track] [-y heads/cylinder]\n" " mdconfig -d -u unit [-o [no]force]\n" " mdconfig -r -u unit -s size [-o [no]force]\n" @@ -102,15 +102,17 @@ bzero(&mdio, sizeof(mdio)); mdio.md_file = malloc(PATH_MAX); - if (mdio.md_file == NULL) + mdio.md_label = malloc(PATH_MAX); + if (mdio.md_file == NULL || mdio.md_label == NULL) err(1, "could not allocate memory"); vflag = 0; bzero(mdio.md_file, PATH_MAX); + bzero(mdio.md_label, PATH_MAX); if (argc == 1) usage(); - while ((ch = getopt(argc, argv, "ab:df:lno:rs:S:t:u:vx:y:")) != -1) { + while ((ch = getopt(argc, argv, "ab:df:lno:rs:S:t:u:vx:y:L:")) != -1) { switch (ch) { case 'a': if (action != UNSET && action != ATTACH) @@ -239,6 +241,9 @@ case 'y': mdio.md_fwheads = strtoul(optarg, &p, 0); break; + case 'L': + strlcpy(mdio.md_label, optarg, PATH_MAX); + break; default: usage(); } @@ -418,7 +423,8 @@ struct gclass *gcl; void *sq; int retcode, ffound, ufound; - char *type, *file, *length; + char *length; + const char *type, *file, *label; type = file = length = NULL; @@ -473,10 +479,14 @@ printf("\t%s\t", type); if (length != NULL) md_prthumanval(length); - if (file != NULL) { - printf("\t%s", file); - file = NULL; - } + if (file == NULL) + file = "-"; + printf("\t%s", file); + file = NULL; + label = geom_config_get(gc, "label"); + if (label == NULL) + label = ""; + printf("\t%s", label); } opt |= OPT_DONE; if ((opt & OPT_LIST) && !(opt & OPT_VERBOSE)) Index: sys/dev/md/md.c =================================================================== --- sys/dev/md/md.c +++ sys/dev/md/md.c @@ -225,6 +225,7 @@ /* MD_VNODE related fields */ struct vnode *vnode; char file[PATH_MAX]; + char label[PATH_MAX]; struct ucred *cred; /* MD_SWAP related fields */ @@ -1613,6 +1614,11 @@ } if (sc == NULL) return (error); + if (mdio->md_label != NULL) + error = copyinstr(mdio->md_label, sc->label, + sizeof(sc->label), NULL); + if (error != 0) + goto err_after_new; if (mdio->md_options & MD_AUTOUNIT) mdio->md_unit = sc->unit; sc->mediasize = mdio->md_mediasize; @@ -1644,6 +1650,7 @@ error = mdcreate_null(sc, mdio, td); break; } +err_after_new: if (error != 0) { mddestroy(sc, td); return (error); @@ -1689,6 +1696,11 @@ mdio->md_options = sc->flags; mdio->md_mediasize = sc->mediasize; mdio->md_sectorsize = sc->sectorsize; + error = 0; + if (mdio->md_label != NULL) { + error = copyout(sc->label, mdio->md_label, + strlen(sc->label) + 1); + } if (sc->type == MD_VNODE || (sc->type == MD_PRELOAD && mdio->md_file != NULL)) error = copyout(sc->file, mdio->md_file, @@ -1841,6 +1853,7 @@ if ((mp->type == MD_VNODE && mp->vnode != NULL) || (mp->type == MD_PRELOAD && mp->file[0] != '\0')) sbuf_printf(sb, " file %s", mp->file); + sbuf_printf(sb, " label %s", mp->label); } else { sbuf_printf(sb, "%s%d\n", indent, mp->unit); @@ -1865,6 +1878,9 @@ g_conf_printf_escaped(sb, "%s", mp->file); sbuf_printf(sb, "\n"); } + sbuf_printf(sb, "%s\n"); } } } Index: sys/sys/mdioctl.h =================================================================== --- sys/sys/mdioctl.h +++ sys/sys/mdioctl.h @@ -49,7 +49,7 @@ * Ioctl definitions for memory disk pseudo-device. */ -#define MDNPAD 97 +#define MDNPAD 96 struct md_ioctl { unsigned md_version; /* Structure layout version */ unsigned md_unit; /* unit number */ @@ -61,6 +61,7 @@ u_int64_t md_base; /* base address */ int md_fwheads; /* firmware heads */ int md_fwsectors; /* firmware sectors */ + char *md_label; /* label of the device */ int md_pad[MDNPAD]; /* padding for future ideas */ };