Split the logic of

static int setrootbyname(char *name);
out into
   dev_t getdiskbyname(char *name);

This makes it easy to create a new DDB command, which is the big reason
for the change.  You can now do the following in DDB:

Example rc.conf entry:
dumpdev="/dev/ad0s1b"   # Device name to crashdump to (if enabled).

db> show disk/ad0s1b
dev_t = 0xc0b7ea00
db> p *dumpdev
c0b7ea00
This commit is contained in:
Brian Feldman 2000-03-20 16:28:35 +00:00
parent 0ef1d1f59c
commit 16aae9cbc0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=58389
4 changed files with 98 additions and 22 deletions

View File

@ -55,6 +55,11 @@
#include <sys/conf.h>
#include <sys/cons.h>
#include "opt_ddb.h"
#ifdef DDB
#include <ddb/ddb.h>
#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

View File

@ -55,6 +55,11 @@
#include <sys/conf.h>
#include <sys/cons.h>
#include "opt_ddb.h"
#ifdef DDB
#include <ddb/ddb.h>
#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

View File

@ -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;

View File

@ -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;