14784aef9SWarner Losh /*- 2e4eef188SWarner Losh * Copyright (c) 2018 M. Warner Losh <imp@freebd.org> 34784aef9SWarner Losh * 44784aef9SWarner Losh * Redistribution and use in source and binary forms, with or without 54784aef9SWarner Losh * modification, are permitted provided that the following conditions 64784aef9SWarner Losh * are met: 74784aef9SWarner Losh * 1. Redistributions of source code must retain the above copyright 84784aef9SWarner Losh * notice, this list of conditions and the following disclaimer. 94784aef9SWarner Losh * 2. Redistributions in binary form must reproduce the above copyright 104784aef9SWarner Losh * notice, this list of conditions and the following disclaimer in the 114784aef9SWarner Losh * documentation and/or other materials provided with the distribution. 124784aef9SWarner Losh * 134784aef9SWarner Losh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 144784aef9SWarner Losh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 154784aef9SWarner Losh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 164784aef9SWarner Losh * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 174784aef9SWarner Losh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 184784aef9SWarner Losh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 194784aef9SWarner Losh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 204784aef9SWarner Losh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 214784aef9SWarner Losh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 224784aef9SWarner Losh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 234784aef9SWarner Losh * SUCH DAMAGE. 244784aef9SWarner Losh */ 254784aef9SWarner Losh 264784aef9SWarner Losh #include <sys/cdefs.h> 274784aef9SWarner Losh __FBSDID("$FreeBSD$"); 284784aef9SWarner Losh 294784aef9SWarner Losh /* 304784aef9SWarner Losh * MD bootstrap main() and assorted miscellaneous 314784aef9SWarner Losh * commands. 324784aef9SWarner Losh */ 334784aef9SWarner Losh 344784aef9SWarner Losh #include <stand.h> 354784aef9SWarner Losh #include <stddef.h> 364784aef9SWarner Losh #include <sys/disk.h> 374784aef9SWarner Losh #include <sys/reboot.h> 384784aef9SWarner Losh 394784aef9SWarner Losh #include "bootstrap.h" 404784aef9SWarner Losh 414784aef9SWarner Losh #ifdef LOADER_ZFS_SUPPORT 42*007b82d7SWarner Losh #include "libzfs.h" 434784aef9SWarner Losh #endif 444784aef9SWarner Losh 454784aef9SWarner Losh COMMAND_SET(lszfs, "lszfs", "list child datasets of a zfs dataset", 464784aef9SWarner Losh command_lszfs); 474784aef9SWarner Losh 484784aef9SWarner Losh static int 494784aef9SWarner Losh command_lszfs(int argc, char *argv[]) 504784aef9SWarner Losh { 514784aef9SWarner Losh int err; 524784aef9SWarner Losh 534784aef9SWarner Losh if (argc != 2) { 544784aef9SWarner Losh command_errmsg = "a single dataset must be supplied"; 554784aef9SWarner Losh return (CMD_ERROR); 564784aef9SWarner Losh } 574784aef9SWarner Losh 584784aef9SWarner Losh err = zfs_list(argv[1]); 594784aef9SWarner Losh if (err != 0) { 604784aef9SWarner Losh command_errmsg = strerror(err); 614784aef9SWarner Losh return (CMD_ERROR); 624784aef9SWarner Losh } 634784aef9SWarner Losh return (CMD_OK); 644784aef9SWarner Losh } 654784aef9SWarner Losh 664784aef9SWarner Losh COMMAND_SET(reloadbe, "reloadbe", "refresh the list of ZFS Boot Environments", 674784aef9SWarner Losh command_reloadbe); 684784aef9SWarner Losh 694784aef9SWarner Losh static int 704784aef9SWarner Losh command_reloadbe(int argc, char *argv[]) 714784aef9SWarner Losh { 724784aef9SWarner Losh int err; 734784aef9SWarner Losh char *root; 744784aef9SWarner Losh 754784aef9SWarner Losh if (argc > 2) { 764784aef9SWarner Losh command_errmsg = "wrong number of arguments"; 774784aef9SWarner Losh return (CMD_ERROR); 784784aef9SWarner Losh } 794784aef9SWarner Losh 804784aef9SWarner Losh if (argc == 2) { 814784aef9SWarner Losh err = zfs_bootenv(argv[1]); 824784aef9SWarner Losh } else { 834784aef9SWarner Losh root = getenv("zfs_be_root"); 844784aef9SWarner Losh if (root == NULL) { 854784aef9SWarner Losh /* There does not appear to be a ZFS pool here, exit without error */ 864784aef9SWarner Losh return (CMD_OK); 874784aef9SWarner Losh } 884784aef9SWarner Losh err = zfs_bootenv(root); 894784aef9SWarner Losh } 904784aef9SWarner Losh 914784aef9SWarner Losh if (err != 0) { 924784aef9SWarner Losh command_errmsg = strerror(err); 934784aef9SWarner Losh return (CMD_ERROR); 944784aef9SWarner Losh } 954784aef9SWarner Losh 964784aef9SWarner Losh return (CMD_OK); 974784aef9SWarner Losh } 984784aef9SWarner Losh 994784aef9SWarner Losh uint64_t 1004784aef9SWarner Losh ldi_get_size(void *priv) 1014784aef9SWarner Losh { 1024784aef9SWarner Losh int fd = (uintptr_t) priv; 1034784aef9SWarner Losh uint64_t size; 1044784aef9SWarner Losh 1054784aef9SWarner Losh ioctl(fd, DIOCGMEDIASIZE, &size); 1064784aef9SWarner Losh return (size); 1074784aef9SWarner Losh } 108