diff --git a/sys/kern/vfs_conf.c b/sys/kern/vfs_conf.c index 8aaa4824cb4f..e2c67e20cb1b 100644 --- a/sys/kern/vfs_conf.c +++ b/sys/kern/vfs_conf.c @@ -55,6 +55,11 @@ #include #include +#include "opt_ddb.h" +#ifdef DDB +#include +#endif + MALLOC_DEFINE(M_MOUNT, "mount", "vfs mount structure"); #define ROOTNAME "root_device" @@ -308,12 +313,11 @@ gets(char *cp) } /* - * Set rootdev to match (name), given that we expect it to - * refer to a disk-like device. + * Convert a given name to the dev_t of the disk-like device + * it refers to. */ -static int -setrootbyname(char *name) -{ +dev_t +getdiskbyname(char *name) { char *cp; int cd, unit, slice, part; dev_t dev; @@ -329,11 +333,11 @@ setrootbyname(char *name) cp++; if (cp == name) { printf("missing device name\n"); - return(1); + return (NODEV); } if (*cp == '\0') { printf("missing unit number\n"); - return(1); + return (NODEV); } unit = *cp - '0'; *cp++ = '\0'; @@ -344,7 +348,7 @@ setrootbyname(char *name) goto gotit; } printf("no such device '%s'\n", name); - return (2); + return (NODEV); gotit: while (*cp >= '0' && *cp <= '9') unit += 10 * unit + *cp++ - '0'; @@ -358,9 +362,42 @@ gotit: } if (*cp != '\0') { printf("junk after name\n"); - return (1); + return (NODEV); } - rootdev = makedev(cd, dkmakeminor(unit, slice, part)); - return 0; + return (makedev(cd, dkmakeminor(unit, slice, part))); } +/* + * Set rootdev to match (name), given that we expect it to + * refer to a disk-like device. + */ +static int +setrootbyname(char *name) +{ + dev_t diskdev; + + diskdev = getdiskbyname(name); + if (diskdev != NODEV) { + rootdev = diskdev; + return (0); + } + + return (1); +} + +#ifdef DDB +DB_SHOW_COMMAND(disk, db_getdiskbyname) +{ + dev_t dev; + + if (modif[0] == '\0') { + db_error("usage: show disk/devicename"); + return; + } + dev = getdiskbyname(modif); + if (dev != NODEV) + db_printf("dev_t = %p\n", dev); + else + db_printf("No disk device matched.\n"); +} +#endif diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index 8aaa4824cb4f..e2c67e20cb1b 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -55,6 +55,11 @@ #include #include +#include "opt_ddb.h" +#ifdef DDB +#include +#endif + MALLOC_DEFINE(M_MOUNT, "mount", "vfs mount structure"); #define ROOTNAME "root_device" @@ -308,12 +313,11 @@ gets(char *cp) } /* - * Set rootdev to match (name), given that we expect it to - * refer to a disk-like device. + * Convert a given name to the dev_t of the disk-like device + * it refers to. */ -static int -setrootbyname(char *name) -{ +dev_t +getdiskbyname(char *name) { char *cp; int cd, unit, slice, part; dev_t dev; @@ -329,11 +333,11 @@ setrootbyname(char *name) cp++; if (cp == name) { printf("missing device name\n"); - return(1); + return (NODEV); } if (*cp == '\0') { printf("missing unit number\n"); - return(1); + return (NODEV); } unit = *cp - '0'; *cp++ = '\0'; @@ -344,7 +348,7 @@ setrootbyname(char *name) goto gotit; } printf("no such device '%s'\n", name); - return (2); + return (NODEV); gotit: while (*cp >= '0' && *cp <= '9') unit += 10 * unit + *cp++ - '0'; @@ -358,9 +362,42 @@ gotit: } if (*cp != '\0') { printf("junk after name\n"); - return (1); + return (NODEV); } - rootdev = makedev(cd, dkmakeminor(unit, slice, part)); - return 0; + return (makedev(cd, dkmakeminor(unit, slice, part))); } +/* + * Set rootdev to match (name), given that we expect it to + * refer to a disk-like device. + */ +static int +setrootbyname(char *name) +{ + dev_t diskdev; + + diskdev = getdiskbyname(name); + if (diskdev != NODEV) { + rootdev = diskdev; + return (0); + } + + return (1); +} + +#ifdef DDB +DB_SHOW_COMMAND(disk, db_getdiskbyname) +{ + dev_t dev; + + if (modif[0] == '\0') { + db_error("usage: show disk/devicename"); + return; + } + dev = getdiskbyname(modif); + if (dev != NODEV) + db_printf("dev_t = %p\n", dev); + else + db_printf("No disk device matched.\n"); +} +#endif diff --git a/sys/sys/conf.h b/sys/sys/conf.h index e7447036f708..28e5357ffb05 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -274,6 +274,7 @@ dev_t makebdev __P((int maj, int min)); dev_t make_dev __P((struct cdevsw *devsw, int minor, uid_t uid, gid_t gid, int perms, char *fmt, ...)) __printflike(6, 7); int lminor __P((dev_t dev)); void setconf __P((void)); +dev_t getdiskbyname(char *name); extern devfs_create_t *devfs_create_hook; diff --git a/sys/sys/linedisc.h b/sys/sys/linedisc.h index e7447036f708..28e5357ffb05 100644 --- a/sys/sys/linedisc.h +++ b/sys/sys/linedisc.h @@ -274,6 +274,7 @@ dev_t makebdev __P((int maj, int min)); dev_t make_dev __P((struct cdevsw *devsw, int minor, uid_t uid, gid_t gid, int perms, char *fmt, ...)) __printflike(6, 7); int lminor __P((dev_t dev)); void setconf __P((void)); +dev_t getdiskbyname(char *name); extern devfs_create_t *devfs_create_hook;