Rewrite piece of code which I committed some time ago that allows to

show file name for 'mdconfig -l -u <x>' command.
This allows to preserve API/ABI compatibility with version 0 (that's why
I changed version number back to 0) and will allow to merge this change
to RELENG_5.

MFC after:	5 days
This commit is contained in:
Pawel Jakub Dawidek 2004-12-27 17:20:06 +00:00
parent 77fc70c1ef
commit 88b5b78d59
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=139359
3 changed files with 15 additions and 13 deletions

View File

@ -60,6 +60,10 @@ main(int argc, char **argv)
int cmdline = 0; int cmdline = 0;
bzero(&mdio, sizeof(mdio)); bzero(&mdio, sizeof(mdio));
mdio.md_file = malloc(PATH_MAX);
if (mdio.md_file == NULL)
err(1, "could not allocate memory");
bzero(mdio.md_file, PATH_MAX);
for (;;) { for (;;) {
ch = getopt(argc, argv, "ab:df:lno:s:S:t:u:x:y:"); ch = getopt(argc, argv, "ab:df:lno:s:S:t:u:x:y:");
if (ch == -1) if (ch == -1)
@ -223,7 +227,7 @@ main(int argc, char **argv)
if (mdio.md_mediasize == 0) if (mdio.md_mediasize == 0)
errx(1, "must specify -s for -t malloc or -t swap"); errx(1, "must specify -s for -t malloc or -t swap");
if (cmdline == 2 && mdio.md_type == MD_VNODE) if (cmdline == 2 && mdio.md_type == MD_VNODE)
if (mdio.md_file == NULL) if (mdio.md_file[0] == '\0')
errx(1, "must specify -f for -t vnode"); errx(1, "must specify -f for -t vnode");
if (action == LIST) { if (action == LIST) {
if (mdio.md_options & MD_AUTOUNIT) if (mdio.md_options & MD_AUTOUNIT)

View File

@ -862,10 +862,9 @@ mdcreate_vnode(struct md_s *sc, struct md_ioctl *mdio, struct thread *td)
struct nameidata nd; struct nameidata nd;
int error, flags; int error, flags;
if (strlcpy(sc->file, mdio->md_file, sizeof(sc->file)) >= error = copyinstr(mdio->md_file, sc->file, sizeof(sc->file), NULL);
sizeof(sc->file)) { if (error != 0)
return (ENAMETOOLONG); return (error);
}
flags = FREAD|FWRITE; flags = FREAD|FWRITE;
NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, sc->file, td); NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, sc->file, td);
error = vn_open(&nd, &flags, 0, -1); error = vn_open(&nd, &flags, 0, -1);
@ -1087,8 +1086,7 @@ mdctlioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, struct thread
case MDIOCDETACH: case MDIOCDETACH:
if (mdio->md_version != MDIOVERSION) if (mdio->md_version != MDIOVERSION)
return (EINVAL); return (EINVAL);
if (mdio->md_file[0] != '\0' || mdio->md_mediasize != 0 || if (mdio->md_mediasize != 0 || mdio->md_options != 0)
mdio->md_options != 0)
return (EINVAL); return (EINVAL);
return (mddetach(mdio->md_unit, td)); return (mddetach(mdio->md_unit, td));
case MDIOCQUERY: case MDIOCQUERY:
@ -1102,10 +1100,10 @@ mdctlioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, struct thread
mdio->md_mediasize = sc->mediasize; mdio->md_mediasize = sc->mediasize;
mdio->md_sectorsize = sc->sectorsize; mdio->md_sectorsize = sc->sectorsize;
if (sc->type == MD_VNODE) { if (sc->type == MD_VNODE) {
if (strlcpy(mdio->md_file, sc->file, error = copyout(sc->file, mdio->md_file,
sizeof(mdio->md_file)) >= sizeof(mdio->md_file)) { strlen(sc->file) + 1);
return (ENAMETOOLONG); if (error != 0)
} return (error);
} }
return (0); return (0);
case MDIOCLIST: case MDIOCLIST:

View File

@ -54,20 +54,20 @@ struct md_ioctl {
unsigned md_version; /* Structure layout version */ unsigned md_version; /* Structure layout version */
unsigned md_unit; /* unit number */ unsigned md_unit; /* unit number */
enum md_types md_type ; /* type of disk */ enum md_types md_type ; /* type of disk */
char *md_file; /* pathname of file to mount */
off_t md_mediasize; /* size of disk in bytes */ off_t md_mediasize; /* size of disk in bytes */
unsigned md_sectorsize; /* sectorsize */ unsigned md_sectorsize; /* sectorsize */
unsigned md_options; /* options */ unsigned md_options; /* options */
u_int64_t md_base; /* base address */ u_int64_t md_base; /* base address */
int md_fwheads; /* firmware heads */ int md_fwheads; /* firmware heads */
int md_fwsectors; /* firmware sectors */ int md_fwsectors; /* firmware sectors */
char md_file[PATH_MAX]; /* pathname of file to mount */
int md_pad[MDNPAD]; /* padding for future ideas */ int md_pad[MDNPAD]; /* padding for future ideas */
}; };
#define MD_NAME "md" #define MD_NAME "md"
#define MD_MODNAME "g_md" #define MD_MODNAME "g_md"
#define MDCTL_NAME "mdctl" #define MDCTL_NAME "mdctl"
#define MDIOVERSION 1 #define MDIOVERSION 0
/* /*
* Before you can use a unit, it must be configured with MDIOCSET. * Before you can use a unit, it must be configured with MDIOCSET.