]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - sys/boot/i386/zfsboot/zfsboot.c
MFC r235155: i386 boot: consolidate MAXBDDEV definition
[FreeBSD/stable/8.git] / sys / boot / i386 / zfsboot / zfsboot.c
1 /*-
2  * Copyright (c) 1998 Robert Nordier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms are freely
6  * permitted provided that the above copyright notice and this
7  * paragraph and the following disclaimer are duplicated in all
8  * such forms.
9  *
10  * This software is provided "AS IS" and without any express or
11  * implied warranties, including, without limitation, the implied
12  * warranties of merchantability and fitness for a particular
13  * purpose.
14  */
15
16 #include <sys/cdefs.h>
17 __FBSDID("$FreeBSD$");
18
19 #include <sys/param.h>
20 #include <sys/errno.h>
21 #include <sys/diskmbr.h>
22 #ifdef GPT
23 #include <sys/gpt.h>
24 #endif
25 #include <sys/reboot.h>
26 #include <sys/queue.h>
27
28 #include <machine/bootinfo.h>
29 #include <machine/elf.h>
30 #include <machine/pc/bios.h>
31
32 #include <stdarg.h>
33 #include <stddef.h>
34
35 #include <a.out.h>
36
37 #include <btxv86.h>
38
39 #include "lib.h"
40 #include "rbx.h"
41 #include "drv.h"
42 #include "util.h"
43 #include "cons.h"
44 #include "bootargs.h"
45
46 #define PATH_DOTCONFIG  "/boot.config"
47 #define PATH_CONFIG     "/boot/config"
48 #define PATH_BOOT3      "/boot/zfsloader"
49 #define PATH_KERNEL     "/boot/kernel/kernel"
50
51 #define ARGS            0x900
52 #define NOPT            14
53 #define NDEV            3
54
55 #define BIOS_NUMDRIVES          0x475
56 #define DRV_HARD        0x80
57 #define DRV_MASK        0x7f
58
59 #define TYPE_AD         0
60 #define TYPE_DA         1
61 #define TYPE_MAXHARD    TYPE_DA
62 #define TYPE_FD         2
63
64 extern uint32_t _end;
65
66 #ifdef GPT
67 static const uuid_t freebsd_zfs_uuid = GPT_ENT_TYPE_FREEBSD_ZFS;
68 #endif
69 static const char optstr[NOPT] = "DhaCcdgmnpqrsv"; /* Also 'P', 'S' */
70 static const unsigned char flags[NOPT] = {
71     RBX_DUAL,
72     RBX_SERIAL,
73     RBX_ASKNAME,
74     RBX_CDROM,
75     RBX_CONFIG,
76     RBX_KDB,
77     RBX_GDB,
78     RBX_MUTE,
79     RBX_NOINTR,
80     RBX_PAUSE,
81     RBX_QUIET,
82     RBX_DFLTROOT,
83     RBX_SINGLE,
84     RBX_VERBOSE
85 };
86 uint32_t opts;
87
88 static const char *const dev_nm[NDEV] = {"ad", "da", "fd"};
89 static const unsigned char dev_maj[NDEV] = {30, 4, 2};
90
91 static char cmd[512];
92 static char cmddup[512];
93 static char kname[1024];
94 static int comspeed = SIOSPD;
95 static struct bootinfo bootinfo;
96 static uint32_t bootdev;
97
98 vm_offset_t     high_heap_base;
99 uint32_t        bios_basemem, bios_extmem, high_heap_size;
100
101 static struct bios_smap smap;
102
103 /*
104  * The minimum amount of memory to reserve in bios_extmem for the heap.
105  */
106 #define HEAP_MIN        (3 * 1024 * 1024)
107
108 static char *heap_next;
109 static char *heap_end;
110
111 /* Buffers that must not span a 64k boundary. */
112 #define READ_BUF_SIZE   8192
113 struct dmadat {
114         char rdbuf[READ_BUF_SIZE];      /* for reading large things */
115         char secbuf[READ_BUF_SIZE];     /* for MBR/disklabel */
116 };
117 static struct dmadat *dmadat;
118
119 void exit(int);
120 static void load(void);
121 static int parse(void);
122 static void bios_getmem(void);
123
124 static void *
125 malloc(size_t n)
126 {
127         char *p = heap_next;
128         if (p + n > heap_end) {
129                 printf("malloc failure\n");
130                 for (;;)
131                     ;
132                 return 0;
133         }
134         heap_next += n;
135         return p;
136 }
137
138 static char *
139 strdup(const char *s)
140 {
141         char *p = malloc(strlen(s) + 1);
142         strcpy(p, s);
143         return p;
144 }
145
146 #include "zfsimpl.c"
147
148 /*
149  * Read from a dnode (which must be from a ZPL filesystem).
150  */
151 static int
152 zfs_read(spa_t *spa, const dnode_phys_t *dnode, off_t *offp, void *start, size_t size)
153 {
154         const znode_phys_t *zp = (const znode_phys_t *) dnode->dn_bonus;
155         size_t n;
156         int rc;
157
158         n = size;
159         if (*offp + n > zp->zp_size)
160                 n = zp->zp_size - *offp;
161         
162         rc = dnode_read(spa, dnode, *offp, start, n);
163         if (rc)
164                 return (-1);
165         *offp += n;
166
167         return (n);
168 }
169
170 /*
171  * Current ZFS pool
172  */
173 spa_t *spa;
174
175 /*
176  * A wrapper for dskread that doesn't have to worry about whether the
177  * buffer pointer crosses a 64k boundary.
178  */
179 static int
180 vdev_read(vdev_t *vdev, void *priv, off_t off, void *buf, size_t bytes)
181 {
182         char *p;
183         daddr_t lba;
184         unsigned int nb;
185         struct dsk *dsk = (struct dsk *) priv;
186
187         if ((off & (DEV_BSIZE - 1)) || (bytes & (DEV_BSIZE - 1)))
188                 return -1;
189
190         p = buf;
191         lba = off / DEV_BSIZE;
192         lba += dsk->start;
193         while (bytes > 0) {
194                 nb = bytes / DEV_BSIZE;
195                 if (nb > READ_BUF_SIZE / DEV_BSIZE)
196                         nb = READ_BUF_SIZE / DEV_BSIZE;
197                 if (drvread(dsk, dmadat->rdbuf, lba, nb))
198                         return -1;
199                 memcpy(p, dmadat->rdbuf, nb * DEV_BSIZE);
200                 p += nb * DEV_BSIZE;
201                 lba += nb;
202                 bytes -= nb * DEV_BSIZE;
203         }
204
205         return 0;
206 }
207
208 static int
209 xfsread(const dnode_phys_t *dnode, off_t *offp, void *buf, size_t nbyte)
210 {
211     if ((size_t)zfs_read(spa, dnode, offp, buf, nbyte) != nbyte) {
212         printf("Invalid %s\n", "format");
213         return -1;
214     }
215     return 0;
216 }
217
218 static void
219 bios_getmem(void)
220 {
221     uint64_t size;
222
223     /* Parse system memory map */
224     v86.ebx = 0;
225     do {
226         v86.ctl = V86_FLAGS;
227         v86.addr = 0x15;                /* int 0x15 function 0xe820*/
228         v86.eax = 0xe820;
229         v86.ecx = sizeof(struct bios_smap);
230         v86.edx = SMAP_SIG;
231         v86.es = VTOPSEG(&smap);
232         v86.edi = VTOPOFF(&smap);
233         v86int();
234         if ((v86.efl & 1) || (v86.eax != SMAP_SIG))
235             break;
236         /* look for a low-memory segment that's large enough */
237         if ((smap.type == SMAP_TYPE_MEMORY) && (smap.base == 0) &&
238             (smap.length >= (512 * 1024)))
239             bios_basemem = smap.length;
240         /* look for the first segment in 'extended' memory */
241         if ((smap.type == SMAP_TYPE_MEMORY) && (smap.base == 0x100000)) {
242             bios_extmem = smap.length;
243         }
244
245         /*
246          * Look for the largest segment in 'extended' memory beyond
247          * 1MB but below 4GB.
248          */
249         if ((smap.type == SMAP_TYPE_MEMORY) && (smap.base > 0x100000) &&
250             (smap.base < 0x100000000ull)) {
251             size = smap.length;
252
253             /*
254              * If this segment crosses the 4GB boundary, truncate it.
255              */
256             if (smap.base + size > 0x100000000ull)
257                 size = 0x100000000ull - smap.base;
258
259             if (size > high_heap_size) {
260                 high_heap_size = size;
261                 high_heap_base = smap.base;
262             }
263         }
264     } while (v86.ebx != 0);
265
266     /* Fall back to the old compatibility function for base memory */
267     if (bios_basemem == 0) {
268         v86.ctl = 0;
269         v86.addr = 0x12;                /* int 0x12 */
270         v86int();
271         
272         bios_basemem = (v86.eax & 0xffff) * 1024;
273     }
274
275     /* Fall back through several compatibility functions for extended memory */
276     if (bios_extmem == 0) {
277         v86.ctl = V86_FLAGS;
278         v86.addr = 0x15;                /* int 0x15 function 0xe801*/
279         v86.eax = 0xe801;
280         v86int();
281         if (!(v86.efl & 1)) {
282             bios_extmem = ((v86.ecx & 0xffff) + ((v86.edx & 0xffff) * 64)) * 1024;
283         }
284     }
285     if (bios_extmem == 0) {
286         v86.ctl = 0;
287         v86.addr = 0x15;                /* int 0x15 function 0x88*/
288         v86.eax = 0x8800;
289         v86int();
290         bios_extmem = (v86.eax & 0xffff) * 1024;
291     }
292
293     /*
294      * If we have extended memory and did not find a suitable heap
295      * region in the SMAP, use the last 3MB of 'extended' memory as a
296      * high heap candidate.
297      */
298     if (bios_extmem >= HEAP_MIN && high_heap_size < HEAP_MIN) {
299         high_heap_size = HEAP_MIN;
300         high_heap_base = bios_extmem + 0x100000 - HEAP_MIN;
301     }
302 }    
303
304 /*
305  * Try to detect a device supported by the legacy int13 BIOS
306  */
307 static int
308 int13probe(int drive)
309 {
310     v86.ctl = V86_FLAGS;
311     v86.addr = 0x13;
312     v86.eax = 0x800;
313     v86.edx = drive;
314     v86int();
315     
316     if (!(v86.efl & 0x1) &&                             /* carry clear */
317         ((v86.edx & 0xff) != (drive & DRV_MASK))) {     /* unit # OK */
318         if ((v86.ecx & 0x3f) == 0) {                    /* absurd sector size */
319                 return(0);                              /* skip device */
320         }
321         return (1);
322     }
323     return(0);
324 }
325
326 /*
327  * We call this when we find a ZFS vdev - ZFS consumes the dsk
328  * structure so we must make a new one.
329  */
330 static struct dsk *
331 copy_dsk(struct dsk *dsk)
332 {
333     struct dsk *newdsk;
334
335     newdsk = malloc(sizeof(struct dsk));
336     *newdsk = *dsk;
337     return (newdsk);
338 }
339
340 static void
341 probe_drive(struct dsk *dsk, spa_t **spap)
342 {
343 #ifdef GPT
344     struct gpt_hdr hdr;
345     struct gpt_ent *ent;
346     daddr_t slba, elba;
347     unsigned part, entries_per_sec;
348 #endif
349     struct dos_partition *dp;
350     char *sec;
351     unsigned i;
352
353     /*
354      * If we find a vdev on the whole disk, stop here. Otherwise dig
355      * out the MBR and probe each slice in turn for a vdev.
356      */
357     if (vdev_probe(vdev_read, dsk, spap) == 0)
358         return;
359
360     sec = dmadat->secbuf;
361     dsk->start = 0;
362
363 #ifdef GPT
364     /*
365      * First check for GPT.
366      */
367     if (drvread(dsk, sec, 1, 1)) {
368         return;
369     }
370     memcpy(&hdr, sec, sizeof(hdr));
371     if (memcmp(hdr.hdr_sig, GPT_HDR_SIG, sizeof(hdr.hdr_sig)) != 0 ||
372         hdr.hdr_lba_self != 1 || hdr.hdr_revision < 0x00010000 ||
373         hdr.hdr_entsz < sizeof(*ent) || DEV_BSIZE % hdr.hdr_entsz != 0) {
374         goto trymbr;
375     }
376
377     /*
378      * Probe all GPT partitions for the presense of ZFS pools. We
379      * return the spa_t for the first we find (if requested). This
380      * will have the effect of booting from the first pool on the
381      * disk.
382      */
383     entries_per_sec = DEV_BSIZE / hdr.hdr_entsz;
384     slba = hdr.hdr_lba_table;
385     elba = slba + hdr.hdr_entries / entries_per_sec;
386     while (slba < elba) {
387         dsk->start = 0;
388         if (drvread(dsk, sec, slba, 1))
389             return;
390         for (part = 0; part < entries_per_sec; part++) {
391             ent = (struct gpt_ent *)(sec + part * hdr.hdr_entsz);
392             if (memcmp(&ent->ent_type, &freebsd_zfs_uuid,
393                      sizeof(uuid_t)) == 0) {
394                 dsk->start = ent->ent_lba_start;
395                 if (vdev_probe(vdev_read, dsk, spap) == 0) {
396                     /*
397                      * We record the first pool we find (we will try
398                      * to boot from that one).
399                      */
400                     spap = NULL;
401
402                     /*
403                      * This slice had a vdev. We need a new dsk
404                      * structure now since the vdev now owns this one.
405                      */
406                     dsk = copy_dsk(dsk);
407                 }
408             }
409         }
410         slba++;
411     }
412     return;
413 trymbr:
414 #endif
415
416     if (drvread(dsk, sec, DOSBBSECTOR, 1))
417         return;
418     dp = (void *)(sec + DOSPARTOFF);
419
420     for (i = 0; i < NDOSPART; i++) {
421         if (!dp[i].dp_typ)
422             continue;
423         dsk->start = dp[i].dp_start;
424         if (vdev_probe(vdev_read, dsk, spap) == 0) {
425             /*
426              * We record the first pool we find (we will try to boot
427              * from that one.
428              */
429             spap = 0;
430
431             /*
432              * This slice had a vdev. We need a new dsk structure now
433              * since the vdev now owns this one.
434              */
435             dsk = copy_dsk(dsk);
436         }
437     }
438 }
439
440 int
441 main(void)
442 {
443     int autoboot, i;
444     dnode_phys_t dn;
445     off_t off;
446     struct dsk *dsk;
447
448     dmadat = (void *)(roundup2(__base + (int32_t)&_end, 0x10000) - __base);
449
450     bios_getmem();
451
452     if (high_heap_size > 0) {
453         heap_end = PTOV(high_heap_base + high_heap_size);
454         heap_next = PTOV(high_heap_base);
455     } else {
456         heap_next = (char *) dmadat + sizeof(*dmadat);
457         heap_end = (char *) PTOV(bios_basemem);
458     }
459
460     dsk = malloc(sizeof(struct dsk));
461     dsk->drive = *(uint8_t *)PTOV(ARGS);
462     dsk->type = dsk->drive & DRV_HARD ? TYPE_AD : TYPE_FD;
463     dsk->unit = dsk->drive & DRV_MASK;
464     dsk->slice = *(uint8_t *)PTOV(ARGS + 1) + 1;
465     dsk->part = 0;
466     dsk->start = 0;
467     dsk->init = 0;
468
469     bootinfo.bi_version = BOOTINFO_VERSION;
470     bootinfo.bi_size = sizeof(bootinfo);
471     bootinfo.bi_basemem = bios_basemem / 1024;
472     bootinfo.bi_extmem = bios_extmem / 1024;
473     bootinfo.bi_memsizes_valid++;
474     bootinfo.bi_bios_dev = dsk->drive;
475
476     bootdev = MAKEBOOTDEV(dev_maj[dsk->type],
477                           dsk->slice, dsk->unit, dsk->part),
478
479     /* Process configuration file */
480
481     autoboot = 1;
482
483     zfs_init();
484
485     /*
486      * Probe the boot drive first - we will try to boot from whatever
487      * pool we find on that drive.
488      */
489     probe_drive(dsk, &spa);
490
491     /*
492      * Probe the rest of the drives that the bios knows about. This
493      * will find any other available pools and it may fill in missing
494      * vdevs for the boot pool.
495      */
496     for (i = 0; i < *(unsigned char *)PTOV(BIOS_NUMDRIVES); i++) {
497         if ((i | DRV_HARD) == *(uint8_t *)PTOV(ARGS))
498             continue;
499
500         if (!int13probe(i | DRV_HARD))
501             break;
502
503         dsk = malloc(sizeof(struct dsk));
504         dsk->drive = i | DRV_HARD;
505         dsk->type = dsk->drive & TYPE_AD;
506         dsk->unit = i;
507         dsk->slice = 0;
508         dsk->part = 0;
509         dsk->start = 0;
510         dsk->init = 0;
511         probe_drive(dsk, NULL);
512     }
513
514     /*
515      * If we didn't find a pool on the boot drive, default to the
516      * first pool we found, if any.
517      */
518     if (!spa) {
519         spa = STAILQ_FIRST(&zfs_pools);
520         if (!spa) {
521             printf("%s: No ZFS pools located, can't boot\n", BOOTPROG);
522             for (;;)
523                 ;
524         }
525     }
526
527     zfs_mount_pool(spa);
528
529     if (zfs_lookup(spa, PATH_CONFIG, &dn) == 0 ||
530         zfs_lookup(spa, PATH_DOTCONFIG, &dn) == 0) {
531         off = 0;
532         zfs_read(spa, &dn, &off, cmd, sizeof(cmd));
533     }
534
535     if (*cmd) {
536         /*
537          * Note that parse() is destructive to cmd[] and we also want
538          * to honor RBX_QUIET option that could be present in cmd[].
539          */
540         memcpy(cmddup, cmd, sizeof(cmd));
541         if (parse())
542             autoboot = 0;
543         if (!OPT_CHECK(RBX_QUIET))
544             printf("%s: %s", PATH_CONFIG, cmddup);
545         /* Do not process this command twice */
546         *cmd = 0;
547     }
548
549     /*
550      * Try to exec stage 3 boot loader. If interrupted by a keypress,
551      * or in case of failure, try to load a kernel directly instead.
552      */
553
554     if (autoboot && !*kname) {
555         memcpy(kname, PATH_BOOT3, sizeof(PATH_BOOT3));
556         if (!keyhit(3)) {
557             load();
558             memcpy(kname, PATH_KERNEL, sizeof(PATH_KERNEL));
559         }
560     }
561
562     /* Present the user with the boot2 prompt. */
563
564     for (;;) {
565         if (!autoboot || !OPT_CHECK(RBX_QUIET))
566             printf("\nFreeBSD/x86 boot\n"
567                    "Default: %s:%s\n"
568                    "boot: ",
569                    spa->spa_name, kname);
570         if (ioctrl & IO_SERIAL)
571             sio_flush();
572         if (!autoboot || keyhit(5))
573             getstr(cmd, sizeof(cmd));
574         else if (!autoboot || !OPT_CHECK(RBX_QUIET))
575             putchar('\n');
576         autoboot = 0;
577         if (parse())
578             putchar('\a');
579         else
580             load();
581     }
582 }
583
584 /* XXX - Needed for btxld to link the boot2 binary; do not remove. */
585 void
586 exit(int x)
587 {
588 }
589
590 static void
591 load(void)
592 {
593     union {
594         struct exec ex;
595         Elf32_Ehdr eh;
596     } hdr;
597     static Elf32_Phdr ep[2];
598     static Elf32_Shdr es[2];
599     caddr_t p;
600     dnode_phys_t dn;
601     off_t off;
602     uint32_t addr, x;
603     int fmt, i, j;
604
605     if (zfs_lookup(spa, kname, &dn)) {
606         return;
607     }
608     off = 0;
609     if (xfsread(&dn, &off, &hdr, sizeof(hdr)))
610         return;
611     if (N_GETMAGIC(hdr.ex) == ZMAGIC)
612         fmt = 0;
613     else if (IS_ELF(hdr.eh))
614         fmt = 1;
615     else {
616         printf("Invalid %s\n", "format");
617         return;
618     }
619     if (fmt == 0) {
620         addr = hdr.ex.a_entry & 0xffffff;
621         p = PTOV(addr);
622         off = PAGE_SIZE;
623         if (xfsread(&dn, &off, p, hdr.ex.a_text))
624             return;
625         p += roundup2(hdr.ex.a_text, PAGE_SIZE);
626         if (xfsread(&dn, &off, p, hdr.ex.a_data))
627             return;
628         p += hdr.ex.a_data + roundup2(hdr.ex.a_bss, PAGE_SIZE);
629         bootinfo.bi_symtab = VTOP(p);
630         memcpy(p, &hdr.ex.a_syms, sizeof(hdr.ex.a_syms));
631         p += sizeof(hdr.ex.a_syms);
632         if (hdr.ex.a_syms) {
633             if (xfsread(&dn, &off, p, hdr.ex.a_syms))
634                 return;
635             p += hdr.ex.a_syms;
636             if (xfsread(&dn, &off, p, sizeof(int)))
637                 return;
638             x = *(uint32_t *)p;
639             p += sizeof(int);
640             x -= sizeof(int);
641             if (xfsread(&dn, &off, p, x))
642                 return;
643             p += x;
644         }
645     } else {
646         off = hdr.eh.e_phoff;
647         for (j = i = 0; i < hdr.eh.e_phnum && j < 2; i++) {
648             if (xfsread(&dn, &off, ep + j, sizeof(ep[0])))
649                 return;
650             if (ep[j].p_type == PT_LOAD)
651                 j++;
652         }
653         for (i = 0; i < 2; i++) {
654             p = PTOV(ep[i].p_paddr & 0xffffff);
655             off = ep[i].p_offset;
656             if (xfsread(&dn, &off, p, ep[i].p_filesz))
657                 return;
658         }
659         p += roundup2(ep[1].p_memsz, PAGE_SIZE);
660         bootinfo.bi_symtab = VTOP(p);
661         if (hdr.eh.e_shnum == hdr.eh.e_shstrndx + 3) {
662             off = hdr.eh.e_shoff + sizeof(es[0]) *
663                 (hdr.eh.e_shstrndx + 1);
664             if (xfsread(&dn, &off, &es, sizeof(es)))
665                 return;
666             for (i = 0; i < 2; i++) {
667                 memcpy(p, &es[i].sh_size, sizeof(es[i].sh_size));
668                 p += sizeof(es[i].sh_size);
669                 off = es[i].sh_offset;
670                 if (xfsread(&dn, &off, p, es[i].sh_size))
671                     return;
672                 p += es[i].sh_size;
673             }
674         }
675         addr = hdr.eh.e_entry & 0xffffff;
676     }
677     bootinfo.bi_esymtab = VTOP(p);
678     bootinfo.bi_kernelname = VTOP(kname);
679     __exec((caddr_t)addr, RB_BOOTINFO | (opts & RBX_MASK),
680            bootdev,
681            KARGS_FLAGS_ZFS,
682            (uint32_t) spa->spa_guid,
683            (uint32_t) (spa->spa_guid >> 32),
684            VTOP(&bootinfo));
685 }
686
687 static int
688 parse(void)
689 {
690     char *arg = cmd;
691     char *ep, *p, *q;
692     const char *cp;
693     //unsigned int drv;
694     int c, i, j;
695
696     while ((c = *arg++)) {
697         if (c == ' ' || c == '\t' || c == '\n')
698             continue;
699         for (p = arg; *p && *p != '\n' && *p != ' ' && *p != '\t'; p++);
700         ep = p;
701         if (*p)
702             *p++ = 0;
703         if (c == '-') {
704             while ((c = *arg++)) {
705                 if (c == 'P') {
706                     if (*(uint8_t *)PTOV(0x496) & 0x10) {
707                         cp = "yes";
708                     } else {
709                         opts |= OPT_SET(RBX_DUAL) | OPT_SET(RBX_SERIAL);
710                         cp = "no";
711                     }
712                     printf("Keyboard: %s\n", cp);
713                     continue;
714                 } else if (c == 'S') {
715                     j = 0;
716                     while ((unsigned int)(i = *arg++ - '0') <= 9)
717                         j = j * 10 + i;
718                     if (j > 0 && i == -'0') {
719                         comspeed = j;
720                         break;
721                     }
722                     /* Fall through to error below ('S' not in optstr[]). */
723                 }
724                 for (i = 0; c != optstr[i]; i++)
725                     if (i == NOPT - 1)
726                         return -1;
727                 opts ^= OPT_SET(flags[i]);
728             }
729             ioctrl = OPT_CHECK(RBX_DUAL) ? (IO_SERIAL|IO_KEYBOARD) :
730                      OPT_CHECK(RBX_SERIAL) ? IO_SERIAL : IO_KEYBOARD;
731             if (ioctrl & IO_SERIAL)
732                 sio_init(115200 / comspeed);
733         } if (c == '?') {
734             dnode_phys_t dn;
735
736             if (zfs_lookup(spa, arg, &dn) == 0) {
737                 zap_list(spa, &dn);
738             }
739             return -1;
740         } else {
741             arg--;
742
743             /*
744              * Report pool status if the comment is 'status'. Lets
745              * hope no-one wants to load /status as a kernel.
746              */
747             if (!strcmp(arg, "status")) {
748                 spa_all_status();
749                 return -1;
750             }
751
752             /*
753              * If there is a colon, switch pools.
754              */
755             q = (char *) strchr(arg, ':');
756             if (q) {
757                 spa_t *newspa;
758
759                 *q++ = 0;
760                 newspa = spa_find_by_name(arg);
761                 if (newspa) {
762                     spa = newspa;
763                     zfs_mount_pool(spa);
764                 } else {
765                     printf("\nCan't find ZFS pool %s\n", arg);
766                     return -1;
767                 }
768                 arg = q;
769             }
770             if ((i = ep - arg)) {
771                 if ((size_t)i >= sizeof(kname))
772                     return -1;
773                 memcpy(kname, arg, i + 1);
774             }
775         }
776         arg = p;
777     }
778     return 0;
779 }