Loader paged/pageable data is not always paged.

This change does modify devsw dv_print() to return the int value,
enabling walkers to interrupt the walk on non zero value from dv_print().

This will allow the pager_print actually to stop displaying data on
user input, and additionally pager is used in various *dev_print callbacks,
where it was missing.

For test, lsdev [-v] command should display data by screenfuls and should
stop when the key 'q' is pressed on pager prompt.

Reviewed by:	allanjude
Approved by:	allanjude (mentor)
Differential Revision:	https://reviews.freebsd.org/D5461
This commit is contained in:
Toomas Soome 2016-11-08 06:50:18 +00:00
parent cd1693d3f9
commit cbd6713146
27 changed files with 244 additions and 154 deletions

View File

@ -143,7 +143,7 @@ struct devsw {
int (*dv_open)(struct open_file *f, ...);
int (*dv_close)(struct open_file *f);
int (*dv_ioctl)(struct open_file *f, u_long cmd, void *data);
void (*dv_print)(int verbose); /* print device information */
int (*dv_print)(int verbose); /* print device information */
void (*dv_cleanup)(void);
};

View File

@ -80,7 +80,7 @@ static int net_open(struct open_file *, ...);
static int net_close(struct open_file *);
static void net_cleanup(void);
static int net_strategy();
static void net_print(int);
static int net_print(int);
static int net_getparams(int sock);
@ -325,23 +325,27 @@ net_getparams(int sock)
return (0);
}
static void
static int
net_print(int verbose)
{
struct netif_driver *drv;
int i, d, cnt;
int ret = 0;
cnt = 0;
for (d = 0; netif_drivers[d]; d++) {
drv = netif_drivers[d];
for (i = 0; i < drv->netif_nifs; i++) {
printf("\t%s%d:", "net", cnt++);
if (verbose)
if (verbose) {
printf(" (%s%d)", drv->netif_bname,
drv->netif_ifs[i].dif_unit);
}
if ((ret = pager_output("\n")) != 0)
return (ret);
}
}
printf("\n");
return (ret);
}
/*

View File

@ -254,7 +254,7 @@ command_lsmod(int argc, char *argv[])
struct kernel_module *mp;
struct file_metadata *md;
char lbuf[80];
int ch, verbose;
int ch, verbose, ret = 0;
verbose = 0;
optind = 1;
@ -273,11 +273,13 @@ command_lsmod(int argc, char *argv[])
pager_open();
for (fp = preloaded_files; fp; fp = fp->f_next) {
sprintf(lbuf, " %p: ", (void *) fp->f_addr);
snprintf(lbuf, sizeof(lbuf), " %p: ", (void *) fp->f_addr);
pager_output(lbuf);
pager_output(fp->f_name);
sprintf(lbuf, " (%s, 0x%lx)\n", fp->f_type, (long)fp->f_size);
pager_output(lbuf);
snprintf(lbuf, sizeof(lbuf), " (%s, 0x%lx)\n", fp->f_type,
(long)fp->f_size);
if (pager_output(lbuf))
break;
if (fp->f_args != NULL) {
pager_output(" args: ");
pager_output(fp->f_args);
@ -287,7 +289,8 @@ command_lsmod(int argc, char *argv[])
if (fp->f_modules) {
pager_output(" modules: ");
for (mp = fp->f_modules; mp; mp = mp->m_next) {
sprintf(lbuf, "%s.%d ", mp->m_name, mp->m_version);
snprintf(lbuf, sizeof(lbuf), "%s.%d ", mp->m_name,
mp->m_version);
pager_output(lbuf);
}
if (pager_output("\n"))
@ -296,11 +299,14 @@ command_lsmod(int argc, char *argv[])
if (verbose) {
/* XXX could add some formatting smarts here to display some better */
for (md = fp->f_metadata; md != NULL; md = md->md_next) {
sprintf(lbuf, " 0x%04x, 0x%lx\n", md->md_type, (long) md->md_size);
snprintf(lbuf, sizeof(lbuf), " 0x%04x, 0x%lx\n",
md->md_type, (long) md->md_size);
if (pager_output(lbuf))
break;
}
}
if (ret)
break;
}
pager_close();
return(CMD_OK);

View File

@ -834,6 +834,7 @@ ptable_iterate(const struct ptable *table, void *arg, ptable_iterate_t *iter)
{
struct pentry *entry;
char name[32];
int ret = 0;
name[0] = '\0';
STAILQ_FOREACH(entry, &table->entries, entry) {
@ -856,9 +857,8 @@ ptable_iterate(const struct ptable *table, void *arg, ptable_iterate_t *iter)
if (table->type == PTABLE_BSD)
sprintf(name, "%c", (u_char) 'a' +
entry->part.index);
if (iter(arg, name, &entry->part))
return 1;
if ((ret = iter(arg, name, &entry->part)) != 0)
return (ret);
}
return 0;
return (ret);
}

View File

@ -114,7 +114,7 @@ strlen(const char *s)
return (len);
}
void
int
printf(const char *fmt, ...)
{
va_list ap;
@ -178,4 +178,5 @@ printf(const char *fmt, ...)
}
}
va_end(ap);
return (0);
}

View File

@ -48,6 +48,6 @@ void strcat(char *dst, const char *src);
char *strchr(const char *s, char ch);
size_t strlen(const char *s);
void printf(const char *fmt, ...);
int printf(const char *fmt, ...);
#endif /* !_UTIL_H_ */

View File

@ -252,7 +252,7 @@ efinet_end(struct netif *nif)
}
static int efinet_dev_init(void);
static void efinet_dev_print(int);
static int efinet_dev_print(int);
struct devsw efinet_dev = {
.dv_name = "net",
@ -346,14 +346,13 @@ efinet_dev_init()
return (0);
}
static void
static int
efinet_dev_print(int verbose)
{
CHAR16 *text;
EFI_HANDLE h;
int unit;
int unit, ret = 0;
pager_open();
for (unit = 0, h = efi_find_handle(&efinet_dev, 0);
h != NULL; h = efi_find_handle(&efinet_dev, ++unit)) {
printf(" %s%d:", efinet_dev.dv_name, unit);
@ -364,8 +363,8 @@ efinet_dev_print(int verbose)
efi_free_devpath_name(text);
}
}
if (pager_output("\n"))
if ((ret = pager_output("\n")) != 0)
break;
}
pager_close();
return (ret);
}

View File

@ -47,7 +47,7 @@ static int efipart_realstrategy(void *, int, daddr_t, size_t, size_t, char *,
size_t *);
static int efipart_open(struct open_file *, ...);
static int efipart_close(struct open_file *);
static void efipart_print(int);
static int efipart_print(int);
struct devsw efipart_dev = {
.dv_name = "part",
@ -162,7 +162,7 @@ efipart_init(void)
return (err);
}
static void
static int
efipart_print(int verbose)
{
char line[80];
@ -170,28 +170,29 @@ efipart_print(int verbose)
EFI_HANDLE h;
EFI_STATUS status;
u_int unit;
int ret = 0;
pager_open();
for (unit = 0, h = efi_find_handle(&efipart_dev, 0);
h != NULL; h = efi_find_handle(&efipart_dev, ++unit)) {
sprintf(line, " %s%d:", efipart_dev.dv_name, unit);
if (pager_output(line))
snprintf(line, sizeof(line), " %s%d:",
efipart_dev.dv_name, unit);
if ((ret = pager_output(line)) != 0)
break;
status = BS->HandleProtocol(h, &blkio_guid, (void **)&blkio);
if (!EFI_ERROR(status)) {
sprintf(line, " %llu blocks",
snprintf(line, sizeof(line), " %llu blocks",
(unsigned long long)(blkio->Media->LastBlock + 1));
if (pager_output(line))
if ((ret = pager_output(line)) != 0)
break;
if (blkio->Media->RemovableMedia)
if (pager_output(" (removable)"))
if ((ret = pager_output(" (removable)")) != 0)
break;
}
if (pager_output("\n"))
if ((ret = pager_output("\n")) != 0)
break;
}
pager_close();
return (ret);
}
static int

View File

@ -533,6 +533,7 @@ command_memmap(int argc, char *argv[])
UINT32 dver;
EFI_STATUS status;
int i, ndesc;
char line[80];
static char *types[] = {
"Reserved",
"LoaderCode",
@ -564,14 +565,19 @@ command_memmap(int argc, char *argv[])
}
ndesc = sz / dsz;
printf("%23s %12s %12s %8s %4s\n",
snprintf(line, sizeof(line), "%23s %12s %12s %8s %4s\n",
"Type", "Physical", "Virtual", "#Pages", "Attr");
pager_open();
if (pager_output(line)) {
pager_close();
return (CMD_OK);
}
for (i = 0, p = map; i < ndesc;
i++, p = NextMemoryDescriptor(p, dsz)) {
printf("%23s %012jx %012jx %08jx ", types[p->Type],
(uintmax_t)p->PhysicalStart, (uintmax_t)p->VirtualStart,
(uintmax_t)p->NumberOfPages);
(uintmax_t)p->PhysicalStart, (uintmax_t)p->VirtualStart,
(uintmax_t)p->NumberOfPages);
if (p->Attribute & EFI_MEMORY_UC)
printf("UC ");
if (p->Attribute & EFI_MEMORY_WC)
@ -588,9 +594,11 @@ command_memmap(int argc, char *argv[])
printf("RP ");
if (p->Attribute & EFI_MEMORY_XP)
printf("XP ");
printf("\n");
if (pager_output("\n"))
break;
}
pager_close();
return (CMD_OK);
}
@ -612,10 +620,17 @@ guid_to_string(EFI_GUID *guid)
static int
command_configuration(int argc, char *argv[])
{
char line[80];
UINTN i;
printf("NumberOfTableEntries=%lu\n",
snprintf(line, sizeof(line), "NumberOfTableEntries=%lu\n",
(unsigned long)ST->NumberOfTableEntries);
pager_open();
if (pager_output(line)) {
pager_close();
return (CMD_OK);
}
for (i = 0; i < ST->NumberOfTableEntries; i++) {
EFI_GUID *guid;
@ -642,9 +657,13 @@ command_configuration(int argc, char *argv[])
printf("FDT Table");
else
printf("Unknown Table (%s)", guid_to_string(guid));
printf(" at %p\n", ST->ConfigurationTable[i].VendorTable);
snprintf(line, sizeof(line), " at %p\n",
ST->ConfigurationTable[i].VendorTable);
if (pager_output(line))
break;
}
pager_close();
return (CMD_OK);
}

View File

@ -69,7 +69,7 @@ static int fw_strategy(void *devdata, int flag, daddr_t dblk,
size_t offset, size_t size, char *buf, size_t *rsize);
static int fw_open(struct open_file *f, ...);
static int fw_close(struct open_file *f);
static void fw_print(int verbose);
static int fw_print(int verbose);
static void fw_cleanup(void);
void fw_enable(void);
@ -148,21 +148,26 @@ fw_init(void)
/*
* Print information about OHCI chips
*/
static void
static int
fw_print(int verbose)
{
int i;
char line[80];
int i, ret = 0;
struct fwohci_softc *sc;
for (i = 0; i < MAX_OHCI; i ++) {
sc = &fwinfo[i];
if (sc->state == FWOHCI_STATE_DEAD)
break;
printf("%d: locator=0x%04x devid=0x%08x"
snprintf(line, sizeof(line), "%d: locator=0x%04x devid=0x%08x"
" base_addr=0x%08x handle=0x%08x bus_id=0x%08x\n",
i, sc->locator, sc->devid,
sc->base_addr, sc->handle, sc->bus_id);
ret = pager_output(line);
if (ret != 0)
break;
}
return (ret);
}
static int

View File

@ -100,7 +100,7 @@ static int bc_realstrategy(void *devdata, int flag, daddr_t dblk,
size_t offset, size_t size, char *buf, size_t *rsize);
static int bc_open(struct open_file *f, ...);
static int bc_close(struct open_file *f);
static void bc_print(int verbose);
static int bc_print(int verbose);
struct devsw bioscd = {
"cd",
@ -177,20 +177,19 @@ bc_add(int biosdev)
/*
* Print information about disks
*/
static void
static int
bc_print(int verbose)
{
char line[80];
int i;
int i, ret = 0;
pager_open();
for (i = 0; i < nbcinfo; i++) {
sprintf(line, " cd%d: Device 0x%x\n", i,
snprintf(line, sizeof(line), " cd%d: Device 0x%x\n", i,
bcinfo[i].bc_sp.sp_devicespec);
if (pager_output(line))
if ((ret = pager_output(line)) != 0)
break;
}
pager_close();
return (ret);
}
/*

View File

@ -135,7 +135,7 @@ static int bd_realstrategy(void *devdata, int flag, daddr_t dblk, size_t offset,
static int bd_open(struct open_file *f, ...);
static int bd_close(struct open_file *f);
static int bd_ioctl(struct open_file *f, u_long cmd, void *data);
static void bd_print(int verbose);
static int bd_print(int verbose);
static void bd_cleanup(void);
#ifdef LOADER_GELI_SUPPORT
@ -321,21 +321,21 @@ bd_int13probe(struct bdinfo *bd)
/*
* Print information about disks
*/
static void
static int
bd_print(int verbose)
{
static char line[80];
struct disk_devdesc dev;
int i;
int i, ret = 0;
pager_open();
for (i = 0; i < nbdinfo; i++) {
sprintf(line, " disk%d: BIOS drive %c (%ju X %u):\n", i,
snprintf(line, sizeof(line),
" disk%d: BIOS drive %c (%ju X %u):\n", i,
(bdinfo[i].bd_unit < 0x80) ? ('A' + bdinfo[i].bd_unit):
('C' + bdinfo[i].bd_unit - 0x80),
(uintmax_t)bdinfo[i].bd_sectors,
bdinfo[i].bd_sectorsize);
if (pager_output(line))
if ((ret = pager_output(line)) != 0)
break;
dev.d_dev = &biosdisk;
dev.d_unit = i;
@ -346,12 +346,14 @@ bd_print(int verbose)
bdinfo[i].bd_sectorsize,
(bdinfo[i].bd_flags & BD_FLOPPY) ?
DISK_F_NOCACHE: 0) == 0) {
sprintf(line, " disk%d", i);
disk_print(&dev, line, verbose);
snprintf(line, sizeof(line), " disk%d", i);
ret = disk_print(&dev, line, verbose);
disk_close(&dev);
if (ret != 0)
return (ret);
}
}
pager_close();
return (ret);
}
/*

View File

@ -75,7 +75,7 @@ static int pxe_strategy(void *devdata, int flag, daddr_t dblk,
size_t offset, size_t size, char *buf, size_t *rsize);
static int pxe_open(struct open_file *f, ...);
static int pxe_close(struct open_file *f);
static void pxe_print(int verbose);
static int pxe_print(int verbose);
static void pxe_cleanup(void);
static void pxe_setnfshandle(char *rootpath);
@ -381,14 +381,20 @@ pxe_close(struct open_file *f)
return (0);
}
static void
static int
pxe_print(int verbose)
{
char line[255];
if (pxe_call == NULL)
return;
return (0);
printf(" pxe0: %s:%s\n", inet_ntoa(rootip), rootpath);
if (verbose) {
snprintf(line, sizeof(line), " pxe0: %s:%s\n",
inet_ntoa(rootip), rootpath);
} else {
snprintf(line, sizeof(line), " pxe0:\n");
}
return (pager_output(line));
}
static void

View File

@ -47,7 +47,7 @@ static int beri_cfi_disk_close(struct open_file *);
static void beri_cfi_disk_cleanup(void);
static int beri_cfi_disk_strategy(void *, int, daddr_t, size_t, size_t,
char *, size_t *);
static void beri_cfi_disk_print(int);
static int beri_cfi_disk_print(int);
struct devsw beri_cfi_disk = {
.dv_name = "cfi",
@ -112,25 +112,29 @@ beri_cfi_disk_close(struct open_file *f)
return (disk_close(dev));
}
static void
static int
beri_cfi_disk_print(int verbose)
{
struct disk_devdesc dev;
char line[80];
int ret;
sprintf(line, " cfi%d CFI flash device\n", 0);
pager_output(line);
snprintf(line, sizeof(line), " cfi%d CFI flash device\n", 0);
ret = pager_output(line);
if (ret != 0)
return (ret);
dev.d_dev = &beri_cfi_disk;
dev.d_unit = 0;
dev.d_slice = -1;
dev.d_partition = -1;
if (disk_open(&dev, cfi_get_mediasize(),
cfi_get_sectorsize(), 0) == 0) {
sprintf(line, " cfi%d", 0);
disk_print(&dev, line, verbose);
snprintf(line, sizeof(line), " cfi%d", 0);
ret = disk_print(&dev, line, verbose);
disk_close(&dev);
}
return (ret);
}
static void

View File

@ -47,7 +47,7 @@ static int beri_sdcard_disk_close(struct open_file *);
static void beri_sdcard_disk_cleanup(void);
static int beri_sdcard_disk_strategy(void *, int, daddr_t, size_t, size_t,
char *, size_t *);
static void beri_sdcard_disk_print(int);
static int beri_sdcard_disk_print(int);
struct devsw beri_sdcard_disk = {
.dv_name = "sdcard",
@ -123,19 +123,23 @@ beri_sdcard_disk_print(int verbose)
{
struct disk_devdesc dev;
char line[80];
int ret;
sprintf(line, " sdcard%d Altera SD card drive\n", 0);
pager_output(line);
snprintf(line, sizeof(line), " sdcard%d Altera SD card drive\n", 0);
ret = pager_output(line);
if (ret != 0)
return (ret);
dev.d_dev = &beri_sdcard_disk;
dev.d_unit = 0;
dev.d_slice = -1;
dev.d_partition = -1;
if (disk_open(&dev, altera_sdcard_get_mediasize(),
altera_sdcard_get_sectorsize(), 0) == 0) {
sprintf(line, " sdcard%d", 0);
disk_print(&dev, line, verbose);
snprintf(line, sizeof(line), " sdcard%d", 0);
ret = disk_print(&dev, line, verbose);
disk_close(&dev);
}
return (ret);
}
static void

View File

@ -47,7 +47,7 @@ static int ofwd_strategy(void *devdata, int flag, daddr_t dblk,
static int ofwd_open(struct open_file *f, ...);
static int ofwd_close(struct open_file *f);
static int ofwd_ioctl(struct open_file *f, u_long cmd, void *data);
static void ofwd_print(int verbose);
static int ofwd_print(int verbose);
struct devsw ofwdisk = {
"block",
@ -161,8 +161,8 @@ ofwd_ioctl(struct open_file *f __unused, u_long cmd __unused,
return (EINVAL);
}
static void
static int
ofwd_print(int verbose __unused)
{
return (0);
}

View File

@ -99,7 +99,7 @@ static int bc_realstrategy(void *devdata, int flag, daddr_t dblk,
size_t offset, size_t size, char *buf, size_t *rsize);
static int bc_open(struct open_file *f, ...);
static int bc_close(struct open_file *f);
static void bc_print(int verbose);
static int bc_print(int verbose);
struct devsw bioscd = {
"cd",
@ -173,20 +173,19 @@ bc_add(int biosdev)
/*
* Print information about disks
*/
static void
static int
bc_print(int verbose)
{
char line[80];
int i;
int i, ret = 0;
pager_open();
for (i = 0; i < nbcinfo; i++) {
sprintf(line, " cd%d: Device 0x%x\n", i,
bcinfo[i].bc_sp.sp_devicespec);
if (pager_output(line))
if ((ret = pager_output(line)) != 0)
break;
}
pager_close();
return (ret);
}
/*

View File

@ -123,7 +123,7 @@ static int bd_realstrategy(void *devdata, int flag, daddr_t dblk,
size_t offset, size_t size, char *buf, size_t *rsize);
static int bd_open(struct open_file *f, ...);
static int bd_close(struct open_file *f);
static void bd_print(int verbose);
static int bd_print(int verbose);
struct devsw biosdisk = {
"disk",
@ -249,21 +249,20 @@ bd_int13probe(struct bdinfo *bd)
/*
* Print information about disks
*/
static void
static int
bd_print(int verbose)
{
int i, j, done;
int i, j, ret = 0;
char line[80];
struct i386_devdesc dev;
struct open_disk *od;
struct pc98_partition *dptr;
pager_open();
done = 0;
for (i = 0; i < nbdinfo && !done; i++) {
sprintf(line, " disk%d: BIOS drive %c:\n", i, 'A' + i);
if (pager_output(line))
break;
for (i = 0; i < nbdinfo; i++) {
snprintf(line, sizeof(line), " disk%d: BIOS drive %c:\n",
i, 'A' + i);
if ((ret = pager_output(line)) != 0)
break;
/* try to open the whole disk */
dev.d_unit = i;
@ -278,17 +277,17 @@ bd_print(int verbose)
/* Check for a "dedicated" disk */
for (j = 0; j < od->od_nslices; j++) {
sprintf(line, " disk%ds%d", i, j + 1);
if (bd_printslice(od, &dptr[j], line, verbose)) {
done = 1;
break;
}
snprintf(line, sizeof(line), " disk%ds%d", i, j + 1);
if ((ret = bd_printslice(od, &dptr[j], line, verbose)) != 0)
break;
}
}
bd_closedisk(od);
if (ret != 0)
break;
}
}
pager_close();
return (ret);
}
/* Given a size in 512 byte sectors, convert it to a human-readable number. */

View File

@ -37,7 +37,7 @@ static int hostdisk_strategy(void *devdata, int flag, daddr_t dblk,
static int hostdisk_open(struct open_file *f, ...);
static int hostdisk_close(struct open_file *f);
static int hostdisk_ioctl(struct open_file *f, u_long cmd, void *data);
static void hostdisk_print(int verbose);
static int hostdisk_print(int verbose);
struct devsw hostdisk = {
"/dev",
@ -117,9 +117,9 @@ hostdisk_ioctl(struct open_file *f, u_long cmd, void *data)
return (EINVAL);
}
static void
static int
hostdisk_print(int verbose)
{
return (0);
}

View File

@ -49,7 +49,7 @@ static int ps3cdrom_strategy(void *devdata, int flag, daddr_t dblk,
size_t offset, size_t size, char *buf, size_t *rsize);
static int ps3cdrom_open(struct open_file *f, ...);
static int ps3cdrom_close(struct open_file *f);
static void ps3cdrom_print(int verbose);
static int ps3cdrom_print(int verbose);
struct devsw ps3cdrom = {
"cd",
@ -149,6 +149,7 @@ static int ps3cdrom_close(struct open_file *f)
return 0;
}
static void ps3cdrom_print(int verbose)
static int ps3cdrom_print(int verbose)
{
return (0);
}

View File

@ -61,7 +61,7 @@ static int ps3disk_strategy(void *devdata, int flag, daddr_t dblk,
size_t offset, size_t size, char *buf, size_t *rsize);
static int ps3disk_open(struct open_file *f, ...);
static int ps3disk_close(struct open_file *f);
static void ps3disk_print(int verbose);
static int ps3disk_print(int verbose);
struct devsw ps3disk = {
"disk",
@ -186,8 +186,9 @@ static int ps3disk_close(struct open_file *f)
return 0;
}
static void ps3disk_print(int verbose)
static int ps3disk_print(int verbose)
{
return (0);
}
static int ps3disk_open_gpt(struct ps3_devdesc *dev, struct open_dev *od)

View File

@ -78,7 +78,7 @@ static int stor_strategy(void *, int, daddr_t, size_t, size_t, char *,
static int stor_open(struct open_file *, ...);
static int stor_close(struct open_file *);
static int stor_ioctl(struct open_file *f, u_long cmd, void *data);
static void stor_print(int);
static int stor_print(int);
static void stor_cleanup(void);
struct devsw uboot_storage = {
@ -238,30 +238,31 @@ stor_readdev(struct disk_devdesc *dev, daddr_t blk, size_t size, char *buf)
return (err);
}
static void
static int
stor_print(int verbose)
{
struct disk_devdesc dev;
static char line[80];
int i;
int i, ret = 0;
pager_open();
for (i = 0; i < stor_info_no; i++) {
dev.d_dev = &uboot_storage;
dev.d_unit = i;
dev.d_slice = -1;
dev.d_partition = -1;
sprintf(line, "\tdisk%d (%s)\n", i,
snprintf(line, sizeof(line), "\tdisk%d (%s)\n", i,
ub_stor_type(SI(&dev).type));
if (pager_output(line))
if ((ret = pager_output(line)) != 0)
break;
if (stor_opendev(&dev) == 0) {
sprintf(line, "\tdisk%d", i);
disk_print(&dev, line, verbose);
ret = disk_print(&dev, line, verbose);
disk_close(&dev);
if (ret != 0)
break;
}
}
pager_close();
return (ret);
}
static int

View File

@ -50,7 +50,7 @@ static void umass_disk_cleanup(void);
static int umass_disk_ioctl(struct open_file *, u_long, void *);
static int umass_disk_strategy(void *, int, daddr_t, size_t, size_t, char *,
size_t *);
static void umass_disk_print(int);
static int umass_disk_print(int);
struct devsw umass_disk = {
.dv_name = "umass",
@ -170,23 +170,26 @@ umass_disk_close(struct open_file *f)
return (disk_close(dev));
}
static void
static int
umass_disk_print(int verbose)
{
struct disk_devdesc dev;
memset(&dev, 0, sizeof(dev));
pager_output(" umass0 UMASS device\n");
ret = pager_output(" umass0 UMASS device\n");
if (ret != 0)
return (ret);
dev.d_dev = &umass_disk;
dev.d_unit = 0;
dev.d_slice = -1;
dev.d_partition = -1;
if (umass_disk_open_sub(&dev) == 0) {
disk_print(&dev, " umass0", verbose);
ret = disk_print(&dev, " umass0", verbose);
disk_close(&dev);
}
return (ret);
}
static void

View File

@ -134,13 +134,13 @@ host_dev_init(void)
return (0);
}
static void
static int
host_dev_print(int verbose)
{
char line[80];
sprintf(line, " host%d: Host filesystem\n", 0);
pager_output(line);
snprintf(line, sizeof(line), " host%d: Host filesystem\n", 0);
return (pager_output(line));
}
/*

View File

@ -60,7 +60,7 @@ static int userdisk_realstrategy(void *devdata, int flag, daddr_t dblk,
static int userdisk_open(struct open_file *f, ...);
static int userdisk_close(struct open_file *f);
static int userdisk_ioctl(struct open_file *f, u_long cmd, void *data);
static void userdisk_print(int verbose);
static int userdisk_print(int verbose);
struct devsw userboot_disk = {
"disk",
@ -116,27 +116,33 @@ userdisk_cleanup(void)
/*
* Print information about disks
*/
static void
static int
userdisk_print(int verbose)
{
struct disk_devdesc dev;
char line[80];
int i;
int i, ret = 0;
for (i = 0; i < userdisk_maxunit; i++) {
sprintf(line, " disk%d: Guest drive image\n", i);
pager_output(line);
snprintf(line, sizeof(line),
" disk%d: Guest drive image\n", i);
ret = pager_output(line);
if (ret != 0)
break;
dev.d_dev = &userboot_disk;
dev.d_unit = i;
dev.d_slice = -1;
dev.d_partition = -1;
if (disk_open(&dev, ud_info[i].mediasize,
ud_info[i].sectorsize, 0) == 0) {
sprintf(line, " disk%d", i);
disk_print(&dev, line, verbose);
snprintf(line, sizeof(line), " disk%d", i);
ret = disk_print(&dev, line, verbose);
disk_close(&dev);
if (ret != 0)
break;
}
}
return (ret);
}
/*

View File

@ -514,20 +514,23 @@ zfs_probe_dev(const char *devname, uint64_t *pool_guid)
/*
* Print information about ZFS pools
*/
static void
static int
zfs_dev_print(int verbose)
{
spa_t *spa;
char line[80];
int ret = 0;
if (verbose) {
spa_all_status();
return;
return (spa_all_status());
}
STAILQ_FOREACH(spa, &zfs_pools, spa_link) {
sprintf(line, " zfs:%s\n", spa->spa_name);
pager_output(line);
snprintf(line, sizeof(line), " zfs:%s\n", spa->spa_name);
ret = pager_output(line);
if (ret != 0)
break;
}
return (ret);
}
/*

View File

@ -780,7 +780,7 @@ state_name(vdev_state_t state)
#else
static void
static int
pager_printf(const char *fmt, ...)
{
char line[80];
@ -789,14 +789,14 @@ pager_printf(const char *fmt, ...)
va_start(args, fmt);
vsprintf(line, fmt, args);
va_end(args);
pager_output(line);
return (pager_output(line));
}
#endif
#define STATUS_FORMAT " %s %s\n"
static void
static int
print_state(int indent, const char *name, vdev_state_t state)
{
int i;
@ -806,40 +806,56 @@ print_state(int indent, const char *name, vdev_state_t state)
for (i = 0; i < indent; i++)
strcat(buf, " ");
strcat(buf, name);
pager_printf(STATUS_FORMAT, buf, state_name(state));
return (pager_printf(STATUS_FORMAT, buf, state_name(state)));
}
static void
static int
vdev_status(vdev_t *vdev, int indent)
{
vdev_t *kid;
print_state(indent, vdev->v_name, vdev->v_state);
int ret;
ret = print_state(indent, vdev->v_name, vdev->v_state);
if (ret != 0)
return (ret);
STAILQ_FOREACH(kid, &vdev->v_children, v_childlink) {
vdev_status(kid, indent + 1);
ret = vdev_status(kid, indent + 1);
if (ret != 0)
return (ret);
}
return (ret);
}
static void
static int
spa_status(spa_t *spa)
{
static char bootfs[ZFS_MAXNAMELEN];
uint64_t rootid;
vdev_t *vdev;
int good_kids, bad_kids, degraded_kids;
int good_kids, bad_kids, degraded_kids, ret;
vdev_state_t state;
pager_printf(" pool: %s\n", spa->spa_name);
ret = pager_printf(" pool: %s\n", spa->spa_name);
if (ret != 0)
return (ret);
if (zfs_get_root(spa, &rootid) == 0 &&
zfs_rlookup(spa, rootid, bootfs) == 0) {
if (bootfs[0] == '\0')
pager_printf("bootfs: %s\n", spa->spa_name);
ret = pager_printf("bootfs: %s\n", spa->spa_name);
else
pager_printf("bootfs: %s/%s\n", spa->spa_name, bootfs);
ret = pager_printf("bootfs: %s/%s\n", spa->spa_name,
bootfs);
if (ret != 0)
return (ret);
}
pager_printf("config:\n\n");
pager_printf(STATUS_FORMAT, "NAME", "STATE");
ret = pager_printf("config:\n\n");
if (ret != 0)
return (ret);
ret = pager_printf(STATUS_FORMAT, "NAME", "STATE");
if (ret != 0)
return (ret);
good_kids = 0;
degraded_kids = 0;
@ -859,24 +875,35 @@ spa_status(spa_t *spa)
else if ((good_kids + degraded_kids) > 0)
state = VDEV_STATE_DEGRADED;
print_state(0, spa->spa_name, state);
ret = print_state(0, spa->spa_name, state);
if (ret != 0)
return (ret);
STAILQ_FOREACH(vdev, &spa->spa_vdevs, v_childlink) {
vdev_status(vdev, 1);
ret = vdev_status(vdev, 1);
if (ret != 0)
return (ret);
}
return (ret);
}
static void
static int
spa_all_status(void)
{
spa_t *spa;
int first = 1;
int first = 1, ret = 0;
STAILQ_FOREACH(spa, &zfs_pools, spa_link) {
if (!first)
pager_printf("\n");
if (!first) {
ret = pager_printf("\n");
if (ret != 0)
return (ret);
}
first = 0;
spa_status(spa);
ret = spa_status(spa);
if (ret != 0)
return (ret);
}
return (ret);
}
static int