diff options
author | wollman <wollman@FreeBSD.org> | 1994-10-23 21:33:57 +0000 |
---|---|---|
committer | wollman <wollman@FreeBSD.org> | 1994-10-23 21:33:57 +0000 |
commit | 171476dff789cab869728f6a9994b2281a9ebcdf (patch) | |
tree | 501ffd9e77e6537a9304116acdbd0d346f0085e9 /usr.sbin/lsdev | |
parent | 7b8e09399aded7c12a148b104ccf05419e73ba88 (diff) | |
download | FreeBSD-src-171476dff789cab869728f6a9994b2281a9ebcdf.zip FreeBSD-src-171476dff789cab869728f6a9994b2281a9ebcdf.tar.gz |
Updated to latest kernel code. Also provided a friendlier output format,
which is enabled by default (use `-c' to get the old format). The new
format looks like this (only the values are correct; this was taken on my
machine with a slightly old kernel):
Device St Parent Description
---------- -- ---------- --------------------------------------------------
isa0 NC -
sc0 NC isa0 Parallel printer adapter
ed0 NC isa0 SMC8216/SMC8216C
sio0 NC isa0 RS-232 serial port
sio1 NC isa0 RS-232 serial port
fdc0 NC isa0 floppy disk/tape controller
fd0 NC fdc0 floppy disk
wdc0 NC isa0 ST506/ESDI/IDE disk controller
wd0 NC wdc0 ST506/ESDI/IDE disk
npx0 NC isa0 Floating-point unit
Note that many of these fields could be made more informative; I tried to make
my changes as unintrusive as possible. See the `mcd' driver for an example
of one which actually does something with the `state' field.
Diffstat (limited to 'usr.sbin/lsdev')
-rw-r--r-- | usr.sbin/lsdev/i386.c | 52 | ||||
-rw-r--r-- | usr.sbin/lsdev/lsdev.8 | 10 | ||||
-rw-r--r-- | usr.sbin/lsdev/lsdev.c | 51 | ||||
-rw-r--r-- | usr.sbin/lsdev/lsdev.h | 3 |
4 files changed, 89 insertions, 27 deletions
diff --git a/usr.sbin/lsdev/i386.c b/usr.sbin/lsdev/i386.c index 221e279..037efee 100644 --- a/usr.sbin/lsdev/i386.c +++ b/usr.sbin/lsdev/i386.c @@ -1,6 +1,7 @@ #include "lsdev.h" #include <stdio.h> #include <string.h> +#include <machine/vmparam.h> static void print_isa(struct devconf *); static void print_eisa(struct devconf *); @@ -9,22 +10,32 @@ static void print_scsi(struct devconf *); static void print_disk(struct devconf *); void -print(struct devconf *dc) +hprint_config(void) +{ + printf("# This listing automatically generated by lsdev(1)\n"); +} + +void +print_config(struct devconf *dc) { if(vflag) printf("%d: ", dc->dc_number); switch(dc->dc_devtype) { case MDDT_CPU: - printf("CPU %s%d", dc->dc_name, dc->dc_unit); + printf("# CPU %s%d", dc->dc_name, dc->dc_unit); + break; + case MDDT_BUS: + printf("controller %s%d", dc->dc_name, dc->dc_unit); break; case MDDT_ISA: if(dc->dc_datalen >= ISA_EXTERNALLEN) { print_isa(dc); } else { printit: - printf("%s%d at %s", - dc->dc_name, dc->dc_unit, dc->dc_parent); + printf("%s%d at %s%d", + dc->dc_name, dc->dc_unit, dc->dc_pname, + dc->dc_punit); } break; case MDDT_EISA: @@ -58,13 +69,14 @@ printit: default: if(dc->dc_devtype >= NDEVTYPES) { - printf("%s%d (#%d) at %s", + printf("%s%d (#%d) at %s%d", dc->dc_name, dc->dc_unit, dc->dc_devtype, - dc->dc_parent); + dc->dc_pname, dc->dc_punit); } else { - printf("%s%d (%s) at %s", + printf("%s%d (%s) at %s%d", dc->dc_name, dc->dc_unit, - devtypes[dc->dc_devtype], dc->dc_parent); + devtypes[dc->dc_devtype], dc->dc_pname, + dc->dc_punit); } break; } @@ -76,7 +88,11 @@ print_isa(struct devconf *dc) { struct isa_device *id = (struct isa_device *)dc->dc_data; - printf("%s%d at isa?", dc->dc_name, dc->dc_unit); + printf("%s%d\tat isa?", dc->dc_name, dc->dc_unit); + + if(dc->dc_md.mddc_imask[0]) { + printf(" %3.3s", dc->dc_md.mddc_imask); + } if(vflag) { printf(" (id %d)", id->id_id); @@ -100,19 +116,16 @@ print_isa(struct devconf *dc) } } - if(id->id_drq) { - if(id->id_drq < 0) { - printf(" drq ?"); - } else { - printf(" drq %d", id->id_drq); - } + if(id->id_drq >= 0) { + printf(" drq %d", id->id_drq); } if(id->id_maddr) { if((unsigned long)id->id_maddr == ~0UL) { printf(" iomem ?"); } else { - printf(" iomem 0x%lx", (unsigned long)id->id_maddr); + printf(" iomem 0x%lx", + (unsigned long)id->id_maddr & ~KERNBASE); } } @@ -151,7 +164,8 @@ print_pci(struct devconf *dc) * be made to serve. */ - printf("%s%d %s", dc->dc_name, dc->dc_unit, dc->dc_parent); + printf("%s%d at %s%d", dc->dc_name, dc->dc_unit, dc->dc_pname, + dc->dc_punit); } static void @@ -177,7 +191,7 @@ print_disk(struct devconf *dc) { int *slavep = (int *)dc->dc_data; - printf("%s%d at %s drive %d", - dc->dc_name, dc->dc_unit, dc->dc_parent, *slavep); + printf("%s%d at %s%d drive %d", + dc->dc_name, dc->dc_unit, dc->dc_pname, dc->dc_punit, *slavep); } diff --git a/usr.sbin/lsdev/lsdev.8 b/usr.sbin/lsdev/lsdev.8 index bafbddf..5a7300a 100644 --- a/usr.sbin/lsdev/lsdev.8 +++ b/usr.sbin/lsdev/lsdev.8 @@ -1,4 +1,4 @@ -.\" $Id: lsvfs.1,v 1.1 1994/09/22 01:25:56 wollman Exp $ +.\" $Id: lsdev.8,v 1.1.1.1 1994/10/17 23:26:10 wollman Exp $ .\" Garrett A. Wollman, October 1994 .\" This file is in the public domain. .\" @@ -11,7 +11,7 @@ .Sh SYNOPSIS .Nm lsdev .Op Fl t Ar type -.Op Fl v +.Op Fl cv .Op Ar class Ns Op unit .Sh DESCRIPTION The @@ -25,7 +25,11 @@ of device; the types available vary from machine to machine. (Specifying an invalid type will cause a list of valid types to be printed.) The .Fl v -flag requests more verbose output. The optional +flag requests more verbose output. The +.Fl c +flag requests output in a format similar to the input of +.Xr config 8 . +The optional .Ar class argument requests information on a particular class of devices (e.g., .Dq Li wdc diff --git a/usr.sbin/lsdev/lsdev.c b/usr.sbin/lsdev/lsdev.c index 168d76f..a1b3b49 100644 --- a/usr.sbin/lsdev/lsdev.c +++ b/usr.sbin/lsdev/lsdev.c @@ -13,6 +13,9 @@ static void usage(void); static void badtype(const char *); static void badname(const char *); +static void print_pretty(struct devconf *); +static void hprint_pretty(void); + int main(int argc, char **argv) { @@ -25,10 +28,12 @@ main(int argc, char **argv) int showonlydev = 0; char showonlydevclass[MAXDEVNAME]; int showonlydevunit = -1; + void (*prtfcn)(struct devconf *) = print_pretty; + void (*hprtfcn)(void) = hprint_pretty; whoami = argv[0]; - while((c = getopt(argc, argv, "t:v")) != EOF) { + while((c = getopt(argc, argv, "t:vc")) != EOF) { switch(c) { case 't': showonlytype = findtype(optarg); @@ -38,6 +43,10 @@ main(int argc, char **argv) case 'v': vflag++; break; + case 'c': + prtfcn = print_config; + hprtfcn = hprint_config; + break; default: usage(); break; @@ -78,6 +87,8 @@ main(int argc, char **argv) } osize = 0; + hprtfcn(); + for(i = 1; i <= ndevs; i++) { mib[2] = i; if(sysctl(mib, 3, 0, &size, 0, 0) < 0) { @@ -97,14 +108,14 @@ main(int argc, char **argv) err(1, "sysctl(hw.devconf.%d)", i); } if(!showonlydev && showonlytype < 0) { - print(dc); + prtfcn(dc); } else if(showonlydev) { if(!strcmp(showonlydevclass, dc->dc_name) && (showonlydevunit < 0 || showonlydevunit == dc->dc_unit)) - print(dc); + prtfcn(dc); } else if(showonlytype == dc->dc_devtype) { - print(dc); + prtfcn(dc); } osize = size; } @@ -153,3 +164,35 @@ badname(const char *name) { errx(3, "invalid device name `%s'", name); } + +static void +hprint_pretty(void) +{ + printf("%-10.10s %-2.2s %-10.10s %s\n", + "Device", "St", "Parent", "Description"); + printf("%-10.10s %-2.2s %-10.10s %s\n", + "----------", "--", "----------", + "--------------------------------------------------"); +} + +static const char *const states[] = { "??", "NC", "I", "B" }; + +static void +print_pretty(struct devconf *dc) +{ + char buf[MAXDEVNAME * 2]; + + snprintf(buf, sizeof buf, "%s%d", dc->dc_name, dc->dc_unit); + + printf("%-10.10s %2.2s ", buf, states[dc->dc_state]); + + if(dc->dc_punit >= 0) { + snprintf(buf, sizeof buf, "%s%d", dc->dc_pname, dc->dc_punit); + } else { + buf[0] = '-'; + buf[1] = '\0'; + } + + printf("%-10.10s %s\n", buf, dc->dc_descr); +} + diff --git a/usr.sbin/lsdev/lsdev.h b/usr.sbin/lsdev/lsdev.h index 1ea3910..acf0d34 100644 --- a/usr.sbin/lsdev/lsdev.h +++ b/usr.sbin/lsdev/lsdev.h @@ -10,7 +10,8 @@ #include <sys/devconf.h> extern const char *const devtypes[]; /* device type array */ -extern void print(struct devconf *); /* machine-specific print routine */ +extern void print_config(struct devconf *); /* machine-specific print routine */ +extern void hprint_config(void); /* machine-specific header printer */ extern int vflag; extern int findtype(const char *); /* get device type by name */ |