static int beri_sdcard_disk_print(int verbose) { struct disk_devdesc dev; char line[80]; int ret; printf("%s devices:", beri_sdcard_disk.dv_name); if ((ret = pager_output("\n")) != 0) return (ret); snprintf(line, sizeof(line), " sdcard%d Altera SD card drive\n", 0); ret = pager_output(line); if (ret != 0) return (ret); dev.dd.d_dev = &beri_sdcard_disk; dev.dd.d_unit = 0; dev.d_slice = D_SLICENONE; dev.d_partition = D_PARTNONE; if (disk_open(&dev, altera_sdcard_get_mediasize(), altera_sdcard_get_sectorsize()) == 0) { snprintf(line, sizeof(line), " sdcard%d", 0); ret = disk_print(&dev, line, verbose); disk_close(&dev); } return (ret); }
static int stor_print(int verbose) { struct disk_devdesc dev; static char line[80]; int i, ret = 0; if (stor_info_no == 0) return (ret); printf("%s devices:", uboot_storage.dv_name); if ((ret = pager_output("\n")) != 0) return (ret); 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; snprintf(line, sizeof(line), "\tdisk%d (%s)\n", i, ub_stor_type(SI(&dev).type)); if ((ret = pager_output(line)) != 0) break; if (stor_opendev(&dev) == 0) { sprintf(line, "\tdisk%d", i); ret = disk_print(&dev, line, verbose); disk_close(&dev); if (ret != 0) break; } } return (ret); }
static int command_more(int argc, char *argv[]) { int i; int res; char line[80]; res=0; pager_open(); for (i = 1; (i < argc) && (res == 0); i++) { sprintf(line, "*** FILE %s BEGIN ***\n", argv[i]); if (pager_output(line)) break; res = page_file(argv[i]); if (!res) { sprintf(line, "*** FILE %s END ***\n", argv[i]); res = pager_output(line); } } pager_close(); if (res == 0) return CMD_OK; else return CMD_ERROR; }
static int command_show(int argc, char *argv[]) { struct env_var *ev; char *cp; if (argc < 2) { /* * With no arguments, print everything. */ pager_open(); for (ev = environ; ev != NULL; ev = ev->ev_next) { pager_output(ev->ev_name); cp = getenv(ev->ev_name); if (cp != NULL) { pager_output("="); pager_output(cp); } if (pager_output("\n")) break; } pager_close(); } else { if ((cp = getenv(argv[1])) != NULL) { printf("%s\n", cp); } else { sprintf(command_errbuf, "variable '%s' not found", argv[1]); return(CMD_ERROR); } } return(CMD_OK); }
static int beri_cfi_disk_print(int verbose) { struct disk_devdesc dev; char line[80]; int ret; printf("%s devices:", beri_cfi_disk.dv_name); if ((ret = pager_output("\n")) != 0) return (ret); 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) { snprintf(line, sizeof(line), " cfi%d", 0); ret = disk_print(&dev, line, verbose); disk_close(&dev); } return (ret); }
int command_lskern(int argc, char *argv[]) { struct preloaded_file *fp; char lbuf[80]; int ch, verbose; verbose = 0; optind = 1; optreset = 1; pager_open(); for (fp = preloaded_files; fp; fp = fp->f_next) { snprintf(lbuf, sizeof(lbuf), " %p: %s (%s, 0x%lx)\n", (void *) fp->f_addr, fp->f_name, fp->f_type, (long) fp->f_size); pager_output(lbuf); if (fp->f_args != NULL) { pager_output(" args: "); pager_output(fp->f_args); pager_output("\n"); } } pager_close(); return(CMD_OK); }
static int net_print(int verbose) { struct netif_driver *drv; int i, d, cnt; int ret = 0; if (netif_drivers[0] == NULL) return (ret); printf("%s devices:", netdev.dv_name); if ((ret = pager_output("\n")) != 0) return (ret); 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:", netdev.dv_name, cnt++); if (verbose) { printf(" (%s%d)", drv->netif_bname, drv->netif_ifs[i].dif_unit); } if ((ret = pager_output("\n")) != 0) return (ret); } } return (ret); }
static int efipart_print(int verbose) { char line[80]; EFI_BLOCK_IO *blkio; EFI_HANDLE h; EFI_STATUS status; u_int unit; int ret = 0; for (unit = 0, h = efi_find_handle(&efipart_dev, 0); h != NULL; h = efi_find_handle(&efipart_dev, ++unit)) { 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)) { snprintf(line, sizeof(line), " %llu blocks", (unsigned long long)(blkio->Media->LastBlock + 1)); if ((ret = pager_output(line)) != 0) break; if (blkio->Media->RemovableMedia) if ((ret = pager_output(" (removable)")) != 0) break; } if ((ret = pager_output("\n")) != 0) break; } return (ret); }
/* * Print information about OHCI chips */ static int fw_print(int verbose) { char line[80]; int i, ret = 0; struct fwohci_softc *sc; printf("%s devices:", fwohci.dv_name); if ((ret = pager_output("\n")) != 0) return (ret); for (i = 0; i < MAX_OHCI; i ++) { sc = &fwinfo[i]; if (sc->state == FWOHCI_STATE_DEAD) break; 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 void efipart_print(int verbose) { char line[80]; EFI_BLOCK_IO *blkio; EFI_HANDLE h; EFI_STATUS status; u_int unit; 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); pager_output(line); status = BS->HandleProtocol(h, &blkio_guid, &blkio); if (!EFI_ERROR(status)) { sprintf(line, " %llu blocks", (unsigned long long)(blkio->Media->LastBlock + 1)); pager_output(line); if (blkio->Media->RemovableMedia) pager_output(" (removable)"); } pager_output("\n"); } }
static int efinet_dev_print(int verbose) { CHAR16 *text; EFI_HANDLE h; int unit, ret = 0; printf("%s devices:", efinet_dev.dv_name); if ((ret = pager_output("\n")) != 0) return (ret); 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); if (verbose) { text = efi_devpath_name(efi_lookup_devpath(h)); if (text != NULL) { printf(" %S", text); efi_free_devpath_name(text); } } if ((ret = pager_output("\n")) != 0) break; } return (ret); }
int command_commandlist(int argc, char *argv[]) { struct bootblk_command *cmdp; int res; char name[20]; int i; res = 0; pager_open(); res = pager_output("Available commands:\n"); for (i = 0, cmdp = commands; (cmdp->c_name != NULL) && (cmdp->c_desc != NULL ); i++, cmdp = commands + i) { if (res) break; if ((cmdp->c_name != NULL) && (cmdp->c_desc != NULL)) { sprintf(name, " %s ", cmdp->c_name); pager_output(name); pager_output(cmdp->c_desc); res = pager_output("\n"); } } pager_close(); return(CMD_OK); }
static int md_print(int verbose) { printf("%s devices:", md_dev.dv_name); if (pager_output("\n") != 0) return (1); printf("MD (%u bytes)", MD_IMAGE_SIZE); return (pager_output("\n")); }
static int host_dev_print(int verbose) { char line[80]; printf("%s devices:", host_dev.dv_name); if (pager_output("\n") != 0) return (1); sprintf(line, " host%d: Host filesystem\n", 0); pager_output(line); }
/* * Print out each valid partition in the disklabel of a FreeBSD slice. * For size calculations, we assume a 512 byte sector size. */ static int bd_printbsdslice(struct open_disk *od, daddr_t offset, char *prefix, int verbose) { char line[80]; char buf[BIOSDISK_SECSIZE]; struct disklabel *lp; int i; /* read disklabel */ if (bd_read(od, offset + LABELSECTOR, 1, buf)) return (0); lp =(struct disklabel *)(&buf[0]); if (lp->d_magic != DISKMAGIC) { sprintf(line, "%s: FFS bad disklabel\n", prefix); return (pager_output(line)); } /* Print partitions */ for (i = 0; i < lp->d_npartitions; i++) { /* * For each partition, make sure we know what type of fs it is. If * not, then skip it. However, since floppies often have bogus * fstypes, print the 'a' partition on a floppy even if it is marked * unused. */ if ((lp->d_partitions[i].p_fstype == FS_BSDFFS) || (lp->d_partitions[i].p_fstype == FS_SWAP) || (lp->d_partitions[i].p_fstype == FS_VINUM) || ((lp->d_partitions[i].p_fstype == FS_UNUSED) && (od->od_flags & BD_FLOPPY) && (i == 0))) { /* Only print out statistics in verbose mode */ if (verbose) sprintf(line, " %s%c: %s %s (%d - %d)\n", prefix, 'a' + i, (lp->d_partitions[i].p_fstype == FS_SWAP) ? "swap " : (lp->d_partitions[i].p_fstype == FS_VINUM) ? "vinum" : "FFS ", display_size(lp->d_partitions[i].p_size), lp->d_partitions[i].p_offset, lp->d_partitions[i].p_offset + lp->d_partitions[i].p_size); else sprintf(line, " %s%c: %s\n", prefix, 'a' + i, (lp->d_partitions[i].p_fstype == FS_SWAP) ? "swap" : (lp->d_partitions[i].p_fstype == FS_VINUM) ? "vinum" : "FFS"); if (pager_output(line)) return (1); } } return (0); }
/* * Print information about disks */ static void bd_print(int verbose) { int i; char line[80]; for (i = 0; i < nbdinfo; i++) { sprintf(line, " disk%d: SRM drive %s", i, bdinfo[i].bd_name); pager_output(line); /* XXX more detail? */ pager_output("\n"); } }
static int command_configuration(int argc, char *argv[]) { char line[80]; UINTN i; 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; printf(" "); guid = &ST->ConfigurationTable[i].VendorGuid; if (!memcmp(guid, &mps, sizeof(EFI_GUID))) printf("MPS Table"); else if (!memcmp(guid, &acpi, sizeof(EFI_GUID))) printf("ACPI Table"); else if (!memcmp(guid, &acpi20, sizeof(EFI_GUID))) printf("ACPI 2.0 Table"); else if (!memcmp(guid, &smbios, sizeof(EFI_GUID))) printf("SMBIOS Table %p", ST->ConfigurationTable[i].VendorTable); else if (!memcmp(guid, &dxe, sizeof(EFI_GUID))) printf("DXE Table"); else if (!memcmp(guid, &hoblist, sizeof(EFI_GUID))) printf("HOB List Table"); else if (!memcmp(guid, &memtype, sizeof(EFI_GUID))) printf("Memory Type Information Table"); else if (!memcmp(guid, &debugimg, sizeof(EFI_GUID))) printf("Debug Image Info Table"); else if (!memcmp(guid, &fdtdtb, sizeof(EFI_GUID))) printf("FDT Table"); else printf("Unknown Table (%s)", guid_to_string(guid)); snprintf(line, sizeof(line), " at %p\n", ST->ConfigurationTable[i].VendorTable); if (pager_output(line)) break; } pager_close(); return (CMD_OK); }
/* * Print information about disks */ static void bd_print(int verbose) { int i, j; char line[80]; struct i386_devdesc dev; struct open_disk *od; struct pc98_partition *dptr; for (i = 0; i < nbdinfo; i++) { sprintf(line, " disk%d: BIOS drive %c:\n", i, 'A' + i); pager_output(line); /* try to open the whole disk */ dev.d_unit = i; dev.d_kind.biosdisk.slice = -1; dev.d_kind.biosdisk.partition = -1; if (!bd_opendisk(&od, &dev)) { /* Do we have a partition table? */ if (od->od_flags & BD_PARTTABOK) { dptr = &od->od_slicetab[0]; /* Check for a "dedicated" disk */ for (j = 0; j < od->od_nslices; j++) { sprintf(line, " disk%ds%d", i, j + 1); bd_printslice(od, &dptr[j], line, verbose); } } bd_closedisk(od); } } }
void action_output(const char *fmt, ...) { va_list args; va_start(args, fmt); (void) vsnprintf(vmsgbuf, sizeof(vmsgbuf), fmt, args); va_end(args); if (sms_redirect()) { sms_info("%s", vmsgbuf); return; } else { #if !defined(WC3270) /*[*/ FILE *aout; #endif /*]*/ #if defined(C3270) /*[*/ any_error_output = True; screen_suspend(); # if defined(WC3270) /*[*/ pager_output(vmsgbuf); # else /*][*/ aout = start_pager(); # endif /*]*/ #else /*][*/ aout = stdout; #endif /*]*/ #if !defined(WC3270) /*[*/ (void) fprintf(aout, "%s\n", vmsgbuf); #endif /*]*/ macro_output = True; } }
/* * Display from (fd). */ int pager_file(const char *fname) { char buf[80]; size_t hmuch; int fd; int result; if ((fd = open(fname, O_RDONLY)) == -1) { printf("can't open '%s': %s\n", fname, strerror(errno)); return (-1); } for (;;) { hmuch = read(fd, buf, sizeof (buf) - 1); if (hmuch == -1) { result = -1; break; } if (hmuch == 0) { result = 0; break; } buf[hmuch] = 0; if (pager_output(buf)) { result = 1; break; } } (void) close(fd); return (result); }
/* * Print information about disks */ static int bd_print(int verbose) { int i, j, ret = 0; char line[80]; struct i386_devdesc dev; struct open_disk *od; struct pc98_partition *dptr; if (nbdinfo == 0) return (0); printf("%s devices:", biosdisk.dv_name); if ((ret = pager_output("\n")) != 0) return (ret); 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; dev.d_kind.biosdisk.slice = -1; dev.d_kind.biosdisk.partition = -1; if (!bd_opendisk(&od, &dev)) { /* Do we have a partition table? */ if (od->od_flags & BD_PARTTABOK) { dptr = &od->od_slicetab[0]; /* Check for a "dedicated" disk */ for (j = 0; j < od->od_nslices; j++) { 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; } } return (ret); }
static void host_dev_print(int verbose) { char line[80]; sprintf(line, " host%d: Host filesystem\n", 0); pager_output(line); }
static int efi_print_var(CHAR16 *varnamearg, EFI_GUID *matchguid, int lflag) { UINTN datasz, i; EFI_STATUS status; UINT32 attr; CHAR16 *data; char *str; uint32_t uuid_status; int is_ascii; datasz = 0; status = RS->GetVariable(varnamearg, matchguid, &attr, &datasz, NULL); if (status != EFI_BUFFER_TOO_SMALL) { printf("Can't get the variable: error %#lx\n", status); return (CMD_ERROR); } data = malloc(datasz); status = RS->GetVariable(varnamearg, matchguid, &attr, &datasz, data); if (status != EFI_SUCCESS) { printf("Can't get the variable: error %#lx\n", status); return (CMD_ERROR); } uuid_to_string((uuid_t *)matchguid, &str, &uuid_status); if (lflag) { printf("%s 0x%x %S", str, attr, varnamearg); } else { printf("%s 0x%x %S=", str, attr, varnamearg); is_ascii = 1; free(str); str = (char *)data; for (i = 0; i < datasz - 1; i++) { /* Quick hack to see if this ascii-ish string printable range plus tab, cr and lf */ if ((str[i] < 32 || str[i] > 126) && str[i] != 9 && str[i] != 10 && str[i] != 13) { is_ascii = 0; break; } } if (str[datasz - 1] != '\0') is_ascii = 0; if (is_ascii) printf("%s", str); else { for (i = 0; i < datasz / 2; i++) { if (isalnum(data[i]) || isspace(data[i])) printf("%c", data[i]); else printf("\\x%02x", data[i]); } } } free(data); if (pager_output("\n")) return (CMD_WARN); return (CMD_OK); }
static int command_lsmod(int argc, char *argv[]) { struct loaded_module *am; struct module_metadata *md; char lbuf[80]; int ch, verbose; verbose = 0; optind = 1; optreset = 1; while ((ch = getopt(argc, argv, "v")) != -1) { switch(ch) { case 'v': verbose = 1; break; case '?': default: /* getopt has already reported an error */ return(CMD_OK); } } pager_open(); for (am = loaded_modules; (am != NULL); am = am->m_next) { sprintf(lbuf, " %p: %s (%s, 0x%lx)\n", (void *) am->m_addr, am->m_name, am->m_type, (long) am->m_size); pager_output(lbuf); if (am->m_args != NULL) { pager_output(" args: "); pager_output(am->m_args); pager_output("\n"); } if (verbose) /* XXX could add some formatting smarts here to display some better */ for (md = am->m_metadata; md != NULL; md = md->md_next) { sprintf(lbuf, " 0x%04x, 0x%lx\n", md->md_type, (long) md->md_size); pager_output(lbuf); } } pager_close(); return(CMD_OK); }
static int efinet_dev_print(int verbose) { char line[80]; EFI_HANDLE h; int unit, ret; printf("%s devices:", efinet_dev.dv_name); if ((ret = pager_output("\n")) != 0) return (ret); for (unit = 0, h = efi_find_handle(&efinet_dev, 0); h != NULL; h = efi_find_handle(&efinet_dev, ++unit)) { sprintf(line, " %s%d:\n", efinet_dev.dv_name, unit); ret = pager_output(line); if (ret) break; } return (ret); }
static void efinet_dev_print(int verbose) { char line[80]; EFI_HANDLE h; int unit; for (unit = 0, h = efi_find_handle(&efinet_dev, 0); h != NULL; h = efi_find_handle(&efinet_dev, ++unit)) { sprintf(line, " %s%d:\n", efinet_dev.dv_name, unit); pager_output(line); } }
/* * Print information about disks */ static void efifs_dev_print(int verbose) { union { EFI_FILE_SYSTEM_INFO info; char buffer[1024]; } fi; char line[80]; EFI_FILE_IO_INTERFACE *fsif; EFI_FILE *volume; EFI_HANDLE h; EFI_STATUS status; UINTN sz; int i, unit; for (unit = 0, h = efi_find_handle(&efifs_dev, 0); h != NULL; h = efi_find_handle(&efifs_dev, ++unit)) { sprintf(line, " %s%d: ", efifs_dev.dv_name, unit); pager_output(line); status = BS->HandleProtocol(h, &sfs_guid, (VOID **)&fsif); if (EFI_ERROR(status)) goto err; status = fsif->OpenVolume(fsif, &volume); if (EFI_ERROR(status)) goto err; sz = sizeof(fi); status = volume->GetInfo(volume, &fs_guid, &sz, &fi); volume->Close(volume); if (EFI_ERROR(status)) goto err; if (fi.info.ReadOnly) pager_output("[RO] "); else pager_output(" "); for (i = 0; fi.info.VolumeLabel[i] != 0; i++) fi.buffer[i] = fi.info.VolumeLabel[i]; fi.buffer[i] = 0; if (fi.buffer[0] != 0) pager_output(fi.buffer); else pager_output("EFI filesystem"); pager_output("\n"); continue; err: sprintf(line, "[--] error %d: unable to obtain information\n", efi_status_to_errno(status)); pager_output(line); } }
static int command_lsdev(int argc, char *argv[]) { int verbose, ch, i; char line[80]; verbose = 0; optind = 1; optreset = 1; while ((ch = getopt(argc, argv, "v")) != -1) { switch(ch) { case 'v': verbose = 1; break; case '?': default: /* getopt has already reported an error */ return(CMD_OK); } } argv += (optind); argc -= (optind); pager_open(); for (i = 0; devsw[i] != NULL; i++) { if (devsw[i]->dv_print != NULL){ sprintf(line, "%s devices:\n", devsw[i]->dv_name); if (pager_output(line)) break; devsw[i]->dv_print(verbose); } else { sprintf(line, "%s: (unknown)\n", devsw[i]->dv_name); if (pager_output(line)) break; } } pager_close(); return(CMD_OK); }
/* * Please note: although we use the pager for the list of commands, * this routine is called from the ? FORTH function which then * unconditionally prints some commands. This will lead to anomalous * behavior. There's no 'pager_output' binding to FORTH to allow * things to work right, so I'm documenting the bug rather than * fixing it. */ static int command_commandlist(int argc, char *argv[]) { struct bootblk_command **cmdp; int res; char name[20]; res = 0; pager_open(); res = pager_output("Available commands:\n"); SET_FOREACH(cmdp, Xcommand_set) { if (res) break; if (((*cmdp)->c_name != NULL) && ((*cmdp)->c_desc != NULL)) { sprintf(name, " %-15s ", (*cmdp)->c_name); pager_output(name); pager_output((*cmdp)->c_desc); res = pager_output("\n"); } } pager_close(); return(CMD_OK); }
int command_lsdev(int argc, char *argv[]) { int verbose, ch, i; char line[80]; verbose = 0; optind = 1; optreset = 1; while ((ch = getopt(argc, argv, "v")) != -1) { switch(ch) { case 'v': verbose = 1; break; case '?': default: /* getopt has already reported an error */ return(CMD_OK); } } argv += (optind); argc -= (optind); pager_open(); sprintf(line, "Device Enumeration:\n"); pager_output(line); for (i = 0; i < ndevs; i++) { sprintf(line, "%s\n", devsw[i].dv_name); if (pager_output(line)) break; } pager_close(); return(CMD_OK); }