diff options
-rw-r--r-- | distrib/sets/lists/base/md.sparc64 | 1 | ||||
-rw-r--r-- | distrib/sets/lists/man/mi | 1 | ||||
-rw-r--r-- | distrib/sparc64/bsd.rd/Makefile | 3 | ||||
-rw-r--r-- | distrib/sparc64/bsd.rd/list | 3 | ||||
-rw-r--r-- | distrib/sparc64/common/Makefile.inc | 4 | ||||
-rw-r--r-- | distrib/sparc64/common/install.md | 11 | ||||
-rw-r--r-- | distrib/sparc64/miniroot/Makefile | 4 | ||||
-rw-r--r-- | distrib/sparc64/ramdisk/Makefile | 6 | ||||
-rw-r--r-- | distrib/sparc64/ramdisk/list | 3 | ||||
-rw-r--r-- | distrib/sparc64/ramdiskB/Makefile | 6 | ||||
-rw-r--r-- | distrib/sparc64/ramdiskB/list | 3 | ||||
-rw-r--r-- | sys/arch/sparc64/stand/Makefile | 4 | ||||
-rw-r--r-- | sys/arch/sparc64/stand/installboot/Makefile | 23 | ||||
-rw-r--r-- | sys/arch/sparc64/stand/installboot/installboot.8 | 105 | ||||
-rw-r--r-- | sys/arch/sparc64/stand/installboot/installboot.c | 281 |
15 files changed, 22 insertions, 436 deletions
diff --git a/distrib/sets/lists/base/md.sparc64 b/distrib/sets/lists/base/md.sparc64 index 0f36854bb26..51f747ad54e 100644 --- a/distrib/sets/lists/base/md.sparc64 +++ b/distrib/sets/lists/base/md.sparc64 @@ -2181,7 +2181,6 @@ ./usr/libexec/sudo_noexec.so ./usr/local/libdata/perl5/site_perl/sparc64-openbsd ./usr/mdec/bootblk -./usr/mdec/installboot ./usr/mdec/ofwboot ./usr/mdec/ofwboot.net ./usr/sbin/ZZZ diff --git a/distrib/sets/lists/man/mi b/distrib/sets/lists/man/mi index abe151776f4..f5b1d3cddbe 100644 --- a/distrib/sets/lists/man/mi +++ b/distrib/sets/lists/man/mi @@ -2637,7 +2637,6 @@ ./usr/share/man/man8/sparc64/apmd.8 ./usr/share/man/man8/sparc64/boot_sparc64.8 ./usr/share/man/man8/sparc64/eeprom.8 -./usr/share/man/man8/sparc64/installboot.8 ./usr/share/man/man8/sparc64/ldomctl.8 ./usr/share/man/man8/sparc64/ldomd.8 ./usr/share/man/man8/sparc64/zzz.8 diff --git a/distrib/sparc64/bsd.rd/Makefile b/distrib/sparc64/bsd.rd/Makefile index fbb93bdef81..07af017d921 100644 --- a/distrib/sparc64/bsd.rd/Makefile +++ b/distrib/sparc64/bsd.rd/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.27 2013/10/18 14:04:05 deraadt Exp $ +# $OpenBSD: Makefile,v 1.28 2014/11/22 15:02:27 deraadt Exp $ TOP= ${.CURDIR}/.. @@ -20,7 +20,6 @@ REALIMAGE!= echo /var/tmp/image.${PID} STRIP?= strip GZIPCMD?= gzip GZIPFLAGS?= -9fn -INSTALLBOOT?= /usr/mdec/installboot -v MTREE= ${UTILS}/mtree.conf RAMDISK= RAMDISK diff --git a/distrib/sparc64/bsd.rd/list b/distrib/sparc64/bsd.rd/list index f838d22a51a..3d74a1f8314 100644 --- a/distrib/sparc64/bsd.rd/list +++ b/distrib/sparc64/bsd.rd/list @@ -1,4 +1,4 @@ -# $OpenBSD: list,v 1.48 2014/07/20 02:37:35 deraadt Exp $ +# $OpenBSD: list,v 1.49 2014/11/22 15:02:27 deraadt Exp $ # $NetBSD: list,v 1.4.4.1 1996/06/20 20:30:26 pk Exp $ SRCDIRS distrib/special @@ -58,6 +58,7 @@ LINK instbin usr/bin/gzip usr/bin/gunzip usr/bin/gzcat LINK instbin usr/bin/less usr/bin/more LINK instbin usr/bin/sed LINK instbin usr/bin/signify +LINK instbin usr/bin/installboot LINK instbin sbin/bioctl SCRIPT ${DESTDIR}/dev/MAKEDEV dev/MAKEDEV diff --git a/distrib/sparc64/common/Makefile.inc b/distrib/sparc64/common/Makefile.inc index 6a565211e71..f511bfaf7da 100644 --- a/distrib/sparc64/common/Makefile.inc +++ b/distrib/sparc64/common/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.15 2013/10/18 14:04:05 deraadt Exp $ +# $OpenBSD: Makefile.inc,v 1.16 2014/11/22 15:02:27 deraadt Exp $ TOP= ${.CURDIR}/.. @@ -36,7 +36,7 @@ ${FS}: bsd.rd TOPDIR=${TOP} CURDIR=${.CURDIR} OBJDIR=${.OBJDIR} \ TARGDIR=${MOUNT_POINT} UTILS=${UTILS} \ RELEASEDIR=${RELEASEDIR} sh ${UTILS}/runlist.sh ${LISTFLOPPY} - /usr/mdec/installboot -v ${DESTDIR}/usr/mdec/bootblk ${VND_CRDEV} + installboot -v ${VND} @echo "" @df -i ${MOUNT_POINT} @echo "" diff --git a/distrib/sparc64/common/install.md b/distrib/sparc64/common/install.md index 0ff310a5fa5..e8789d457dd 100644 --- a/distrib/sparc64/common/install.md +++ b/distrib/sparc64/common/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.41 2014/08/15 09:45:54 rpe Exp $ +# $OpenBSD: install.md,v 1.42 2014/11/22 15:02:27 deraadt Exp $ # $NetBSD: install.md,v 1.3.2.5 1996/08/26 15:45:28 gwr Exp $ # # @@ -41,10 +41,11 @@ NCPU=$(sysctl -n hw.ncpufound) ((NCPU > 1)) && { DEFAULTSETS="bsd bsd.rd bsd.mp"; SANESETS="bsd bsd.mp"; } md_installboot() { - # Use cat to avoid holes created by cp(1) - cat /mnt/usr/mdec/ofwboot > /mnt/ofwboot - sync - /mnt/usr/mdec/installboot /mnt/usr/mdec/bootblk /dev/r${1}c + if ! installboot -r /mnt ${1}; then + echo "\nFailed to install bootblocks." + echo "You will not be able to boot OpenBSD from ${1}." + exit + fi } md_prep_disklabel() { diff --git a/distrib/sparc64/miniroot/Makefile b/distrib/sparc64/miniroot/Makefile index 04c14cb9bec..ac0c3355c6d 100644 --- a/distrib/sparc64/miniroot/Makefile +++ b/distrib/sparc64/miniroot/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.6 2011/04/18 16:52:10 thib Exp $ +# $OpenBSD: Makefile,v 1.7 2014/11/22 15:02:27 deraadt Exp $ TOP= ${.CURDIR}/.. @@ -40,7 +40,7 @@ ofwboot: ${DESTDIR}/usr/mdec/ofwboot /mnt/ofwboot installboot: - /usr/mdec/installboot -v ${DESTDIR}/usr/mdec/bootblk /dev/vnd0c + installboot -v vnd0 blank_filesystem: dd if=/dev/zero of=${TARGET} bs=512 count=5760 diff --git a/distrib/sparc64/ramdisk/Makefile b/distrib/sparc64/ramdisk/Makefile index a4481460201..5475f28f0d8 100644 --- a/distrib/sparc64/ramdisk/Makefile +++ b/distrib/sparc64/ramdisk/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.28 2013/10/15 22:46:54 deraadt Exp $ +# $OpenBSD: Makefile,v 1.29 2014/11/22 15:02:27 deraadt Exp $ TOP= ${.CURDIR}/.. @@ -15,7 +15,6 @@ MTREE= ${UTILS}/mtree.conf FLOPPY= floppy${REV}.fs FLOPPYSIZE?= 2880 FLOPPYTYPE?= floppy -INSTALLBOOT?= /usr/mdec/installboot VND?= vnd0 VND_DEV= /dev/${VND}a @@ -64,8 +63,7 @@ ${FLOPPY}: bsd.gz ${BOOT} /usr/ mount ${VND_DEV} ${MOUNT_POINT} cp ${DESTDIR}/usr/mdec/ofwboot ${MOUNT_POINT}/ cp bsd.gz ${MOUNT_POINT}/bsd - ${INSTALLBOOT} -v ${DESTDIR}/usr/mdec/bootblk \ - `echo ${VND_RDEV} | sed -e 's/a$$/c/'` + installboot -v ${VND} @echo "" @df -i ${MOUNT_POINT} @echo "" diff --git a/distrib/sparc64/ramdisk/list b/distrib/sparc64/ramdisk/list index dd213d177ee..64ff775b825 100644 --- a/distrib/sparc64/ramdisk/list +++ b/distrib/sparc64/ramdisk/list @@ -1,4 +1,4 @@ -# $OpenBSD: list,v 1.44 2014/07/20 02:37:35 deraadt Exp $ +# $OpenBSD: list,v 1.45 2014/11/22 15:02:27 deraadt Exp $ SRCDIRS distrib/special SRCDIRS bin sbin @@ -53,6 +53,7 @@ LINK instbin usr/bin/gzip usr/bin/gunzip usr/bin/gzcat LINK instbin usr/bin/less usr/bin/more LINK instbin usr/bin/sed LINK instbin usr/bin/signify +LINK instbin usr/bin/installboot SCRIPT ${DESTDIR}/dev/MAKEDEV dev/MAKEDEV SPECIAL cd dev; sh MAKEDEV ramdisk diff --git a/distrib/sparc64/ramdiskB/Makefile b/distrib/sparc64/ramdiskB/Makefile index 4738a268fbe..d321e67309b 100644 --- a/distrib/sparc64/ramdiskB/Makefile +++ b/distrib/sparc64/ramdiskB/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.21 2013/10/15 22:46:54 deraadt Exp $ +# $OpenBSD: Makefile,v 1.22 2014/11/22 15:02:28 deraadt Exp $ TOP= ${.CURDIR}/.. @@ -15,7 +15,6 @@ MTREE= ${UTILS}/mtree.conf FLOPPY= floppyB${REV}.fs FLOPPYSIZE?= 2880 FLOPPYTYPE?= floppy -INSTALLBOOT?= /usr/mdec/installboot VND?= vnd0 VND_DEV= /dev/${VND}a @@ -64,8 +63,7 @@ ${FLOPPY}: bsd.gz ${BOOT} /usr/ mount ${VND_DEV} ${MOUNT_POINT} cp ${DESTDIR}/usr/mdec/ofwboot ${MOUNT_POINT}/ cp bsd.gz ${MOUNT_POINT}/bsd - ${INSTALLBOOT} -v ${DESTDIR}/usr/mdec/bootblk \ - `echo ${VND_RDEV} | sed -e 's/a$$/c/'` + installboot -v ${VND} @echo "" @df -i ${MOUNT_POINT} @echo "" diff --git a/distrib/sparc64/ramdiskB/list b/distrib/sparc64/ramdiskB/list index 06d0ad2fe03..b689ca38ff6 100644 --- a/distrib/sparc64/ramdiskB/list +++ b/distrib/sparc64/ramdiskB/list @@ -1,4 +1,4 @@ -# $OpenBSD: list,v 1.38 2014/07/20 02:37:35 deraadt Exp $ +# $OpenBSD: list,v 1.39 2014/11/22 15:02:28 deraadt Exp $ SRCDIRS distrib/special SRCDIRS bin sbin @@ -51,6 +51,7 @@ LINK instbin usr/bin/gzip usr/bin/gunzip usr/bin/gzcat LINK instbin usr/bin/less usr/bin/more LINK instbin usr/bin/sed LINK instbin usr/bin/signify +LINK instbin usr/bin/installboot SCRIPT ${DESTDIR}/dev/MAKEDEV dev/MAKEDEV SPECIAL cd dev; sh MAKEDEV ramdisk diff --git a/sys/arch/sparc64/stand/Makefile b/sys/arch/sparc64/stand/Makefile index bd51f1a6f1c..0ee171da59b 100644 --- a/sys/arch/sparc64/stand/Makefile +++ b/sys/arch/sparc64/stand/Makefile @@ -1,10 +1,8 @@ -# $OpenBSD: Makefile,v 1.5 2007/11/25 18:25:33 deraadt Exp $ +# $OpenBSD: Makefile,v 1.6 2014/11/22 15:02:28 deraadt Exp $ .if ${MACHINE} == "sparc64" SUBDIR= bootblk libsa libz ofwboot ofwboot.net .endif -SUBDIR+= installboot - .include <bsd.subdir.mk> diff --git a/sys/arch/sparc64/stand/installboot/Makefile b/sys/arch/sparc64/stand/installboot/Makefile deleted file mode 100644 index c33955d04db..00000000000 --- a/sys/arch/sparc64/stand/installboot/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -# $OpenBSD: Makefile,v 1.9 2014/07/06 12:13:18 miod Exp $ -# $NetBSD: Makefile,v 1.13 2000/08/16 08:24:01 mrg Exp $ - -.include <bsd.own.mk> - -MAN= installboot.8 -MANSUBDIR=sparc64 - -.if ${MACHINE} == "sparc64" -PROG= installboot -SRCS= installboot.c -LDADD= -lutil -DPADD= ${LIBUTIL} -CFLAGS+= -Wall -.else -NOPROG= -.endif - -LDSTATIC?= -static - -STANDALONE= - -.include <bsd.prog.mk> diff --git a/sys/arch/sparc64/stand/installboot/installboot.8 b/sys/arch/sparc64/stand/installboot/installboot.8 deleted file mode 100644 index d08ab774d88..00000000000 --- a/sys/arch/sparc64/stand/installboot/installboot.8 +++ /dev/null @@ -1,105 +0,0 @@ -.\" $OpenBSD: installboot.8,v 1.12 2013/09/29 21:30:50 jmc Exp $ -.\" $NetBSD: installboot.8,v 1.1 1995/09/30 21:32:14 pk Exp $ -.\" -.\" Copyright (c) 1995 Paul Kranenburg -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by Paul Kranenburg. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.Dd $Mdocdate: September 29 2013 $ -.Dt INSTALLBOOT 8 sparc64 -.Os -.Sh NAME -.Nm installboot -.Nd install a bootstrap on an FFS filesystem partition -.Sh SYNOPSIS -.Nm installboot -.Op Fl nv -.Ar bootblk -.Ar device -.Sh DESCRIPTION -.Nm installboot -prepares an FFS filesystem partition for boot-strapping from the PROM. -The sparc64 boot process is split into two parts: a small first-stage bootblock -that is written into the superblock area of a partition -.Po -and hence is limited in size to SBSIZE - DEV_BSIZE bytes -.Pc , -and a second-stage boot program that resides in the filesystem proper. -The first-stage bootblock is loaded into memory by the PROM. -After it receives control, it loads the second-stage boot program -.Ar ofwboot -from the filesystem. -The second-stage boot program uses the device driver interface to -the PROM and the stand-alone filesystem code in -.Dq libsa.a -to locate and load the kernel. -The first-stage bootblock and second-stage boot program can be found in -.Pa /usr/mdec/bootblk -and -.Pa /usr/mdec/ofwboot -respectively. -The second-stage boot program commonly resides in the root directory as -.Pa /ofwboot . -.Pp -The options are as follows: -.Bl -tag -width flag -.It Fl n -Do not actually write anything on the disk. -.It Fl v -Verbose mode. -.El -.Pp -The arguments are: -.Bl -tag -width bootblk -.It Ar bootblk -The name of the file containing the first-stage bootblock. -.It Ar device -The name of the raw device in which the first-stage boot program -is to be installed. -This should correspond to the block device on which the file system containing -.Ar ofwboot -is mounted. -.El -.Sh EXAMPLES -The following commands will install the first-stage bootblock in the -root filesystem -.Pq assumed to be mounted on Dq sd0a -using the file -.Pa /ofwboot -as the second-stage boot program: -.Bd -literal -offset indent -# cp /usr/mdec/ofwboot /ofwboot -# /usr/mdec/installboot /usr/mdec/bootblk sd0a -.Ed -.Sh SEE ALSO -.Xr disklabel 8 , -.Xr init 8 -.Sh HISTORY -The -.Nm installboot -first appeared in -.Nx 1.1 . diff --git a/sys/arch/sparc64/stand/installboot/installboot.c b/sys/arch/sparc64/stand/installboot/installboot.c deleted file mode 100644 index 43170522c88..00000000000 --- a/sys/arch/sparc64/stand/installboot/installboot.c +++ /dev/null @@ -1,281 +0,0 @@ -/* $OpenBSD: installboot.c,v 1.18 2014/07/06 12:13:18 miod Exp $ */ -/* $NetBSD: installboot.c,v 1.8 2001/02/19 22:48:59 cgd Exp $ */ - -/*- - * Copyright (c) 2012 Joel Sing <jsing@openbsd.org> - * Copyright (c) 1998 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Paul Kranenburg. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <sys/param.h> -#include <sys/disklabel.h> -#include <sys/dkio.h> -#include <sys/ioctl.h> -#include <sys/mman.h> -#include <sys/stat.h> -#include <sys/time.h> - -#include <dev/biovar.h> -#include <dev/softraidvar.h> - -#include <ufs/ffs/fs.h> - -#include <err.h> -#include <fcntl.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <util.h> - -int verbose, nowrite; -char *dev, *blkstore; -size_t blksize; - -static void usage(void); -int main(int, char *[]); -static void write_bootblk(int); - -static int sr_volume(int, int *, int *); -static void sr_installboot(int); -static void sr_install_bootblk(int, int, int); - -static void -usage(void) -{ - extern char *__progname; - - fprintf(stderr, "usage: %s [-nv] bootblk device\n", __progname); - exit(1); -} - -int -main(int argc, char *argv[]) -{ - char *blkfile, *realdev; - int vol = -1, ndisks = 0, disk; - int c, devfd, blkfd; - struct stat sb; - - while ((c = getopt(argc, argv, "nv")) != -1) { - switch (c) { - case 'n': - /* Do not actually write the bootblock to disk. */ - nowrite = 1; - break; - case 'v': - /* Chat */ - verbose = 1; - break; - default: - usage(); - } - } - - if (argc - optind < 2) - usage(); - - blkfile = argv[optind++]; - dev = argv[optind]; - - if (verbose) - printf("bootblk: %s\n", blkfile); - - if ((blkfd = open(blkfile, O_RDONLY)) < 0) - err(1, "open: %s", blkfile); - - if (fstat(blkfd, &sb) == -1) - err(1, "fstat: %s", blkfile); - if (sb.st_size == 0) - errx(1, "%s is empty", blkfile); - - blksize = howmany(sb.st_size, DEV_BSIZE) * DEV_BSIZE; - if (blksize > SBSIZE - DEV_BSIZE) - errx(1, "boot blocks too big"); - if ((blkstore = malloc(blksize)) == NULL) - err(1, "malloc: %s", blkfile); - bzero(blkstore, blksize); - if (read(blkfd, blkstore, sb.st_size) != sb.st_size) - err(1, "read: %s", blkfile); - - if ((devfd = opendev(dev, (nowrite ? O_RDONLY : O_RDWR), - OPENDEV_PART, &realdev)) < 0) - err(1, "open: %s", realdev); - if (verbose) - printf("device: %s\n", realdev); - - if (sr_volume(devfd, &vol, &ndisks)) { - - /* Install boot loader in softraid volume. */ - sr_installboot(devfd); - - /* Install bootblk on each disk that is part of this volume. */ - for (disk = 0; disk < ndisks; disk++) - sr_install_bootblk(devfd, vol, disk); - - } else { - - /* Write boot blocks to device. */ - write_bootblk(devfd); - - } - - close(devfd); - - return 0; -} - -static void -write_bootblk(int devfd) -{ - /* - * Write bootblock into the superblock. - */ - - if (nowrite) - return; - - if (lseek(devfd, DEV_BSIZE, SEEK_SET) != DEV_BSIZE) - err(1, "lseek boot block"); - - /* Sync filesystems (to clean in-memory superblock?) */ - sync(); - - if (write(devfd, blkstore, blksize) != blksize) - err(1, "write boot block"); -} - -static int -sr_volume(int devfd, int *vol, int *disks) -{ - struct bioc_inq bi; - struct bioc_vol bv; - int rv, i; - - /* Get volume information. */ - memset(&bi, 0, sizeof(bi)); - rv = ioctl(devfd, BIOCINQ, &bi); - if (rv == -1) - return 0; - - /* XXX - softraid volumes will always have a "softraid0" controller. */ - if (strncmp(bi.bi_dev, "softraid0", sizeof("softraid0"))) - return 0; - - /* Locate specific softraid volume. */ - for (i = 0; i < bi.bi_novol; i++) { - - memset(&bv, 0, sizeof(bv)); - bv.bv_volid = i; - rv = ioctl(devfd, BIOCVOL, &bv); - if (rv == -1) - err(1, "BIOCVOL"); - - if (strncmp(dev, bv.bv_dev, sizeof(bv.bv_dev)) == 0) { - *vol = i; - *disks = bv.bv_nodisk; - break; - } - - } - - if (verbose) - fprintf(stderr, "%s: softraid volume with %i disk(s)\n", - dev, *disks); - - return 1; -} - -static void -sr_installboot(int devfd) -{ - struct bioc_installboot bb; - int rv; - - /* - * Install boot loader into softraid boot loader storage area. - */ - bb.bb_bootldr = "XXX"; - bb.bb_bootldr_size = sizeof("XXX"); - bb.bb_bootblk = blkstore; - bb.bb_bootblk_size = blksize; - strncpy(bb.bb_dev, dev, sizeof(bb.bb_dev)); - if (!nowrite) { - if (verbose) - fprintf(stderr, "%s: installing boot loader on " - "softraid volume\n", dev); - rv = ioctl(devfd, BIOCINSTALLBOOT, &bb); - if (rv != 0) - errx(1, "softraid installboot failed"); - } -} - -static void -sr_install_bootblk(int devfd, int vol, int disk) -{ - struct bioc_disk bd; - char *realdev; - char part; - int diskfd; - int rv; - - /* Get device name for this disk/chunk. */ - memset(&bd, 0, sizeof(bd)); - bd.bd_volid = vol; - bd.bd_diskid = disk; - rv = ioctl(devfd, BIOCDISK, &bd); - if (rv == -1) - err(1, "BIOCDISK"); - - /* Check disk status. */ - if (bd.bd_status != BIOC_SDONLINE && bd.bd_status != BIOC_SDREBUILD) { - fprintf(stderr, "softraid chunk %u not online - skipping...\n", - disk); - return; - } - - if (strlen(bd.bd_vendor) < 1) - errx(1, "invalid disk name"); - part = bd.bd_vendor[strlen(bd.bd_vendor) - 1]; - if (part < 'a' || part >= 'a' + MAXPARTITIONS) - errx(1, "invalid partition %c\n", part); - bd.bd_vendor[strlen(bd.bd_vendor) - 1] = '\0'; - - /* Open device. */ - if ((diskfd = opendev(bd.bd_vendor, (nowrite ? O_RDONLY : O_RDWR), - OPENDEV_PART, &realdev)) < 0) - err(1, "open: %s", realdev); - - if (verbose) - fprintf(stderr, "%s%c: installing boot blocks on %s\n", - bd.bd_vendor, part, realdev); - - /* Write boot blocks to device. */ - write_bootblk(diskfd); - - close(diskfd); -} |