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