1 /* $OpenBSD: sparc64_softraid.c,v 1.8 2022/11/07 15:56:09 kn Exp $ */ 2 /* 3 * Copyright (c) 2012 Joel Sing <jsing@openbsd.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #include <sys/types.h> 19 #include <sys/disklabel.h> 20 #include <sys/ioctl.h> 21 #include <sys/stat.h> 22 23 #include <dev/biovar.h> 24 #include <dev/softraidvar.h> 25 26 #include <err.h> 27 #include <fcntl.h> 28 #include <stdio.h> 29 #include <string.h> 30 #include <util.h> 31 #include <unistd.h> 32 33 #include "installboot.h" 34 #include "sparc64_installboot.h" 35 36 void 37 sr_install_bootblk(int devfd, int vol, int disk) 38 { 39 struct bioc_disk bd; 40 char *realdev; 41 int diskfd; 42 char part; 43 44 diskfd = sr_open_chunk(devfd, vol, disk, &bd, &realdev, &part); 45 if (diskfd == -1) 46 return; 47 48 if (verbose) 49 fprintf(stderr, "%s%c: %s boot blocks on %s\n", bd.bd_vendor, 50 part, (nowrite ? "would install" : "installing"), realdev); 51 52 /* Write boot blocks to device. */ 53 md_installboot(diskfd, realdev); 54 55 close(diskfd); 56 } 57 58 void 59 sr_install_bootldr(int devfd, char *dev) 60 { 61 struct bioc_installboot bb; 62 63 /* 64 * Install boot loader into softraid boot loader storage area. 65 */ 66 memset(&bb, 0, sizeof(bb)); 67 bb.bb_bootblk = blkstore; 68 bb.bb_bootblk_size = blksize; 69 bb.bb_bootldr = ldrstore; 70 bb.bb_bootldr_size = ldrsize; 71 strncpy(bb.bb_dev, dev, sizeof(bb.bb_dev)); 72 if (verbose) 73 fprintf(stderr, "%s: %s boot loader on softraid volume\n", dev, 74 (nowrite ? "would install" : "installing")); 75 if (!nowrite) { 76 if (ioctl(devfd, BIOCINSTALLBOOT, &bb) == -1) 77 errx(1, "softraid installboot failed"); 78 sr_status(&bb.bb_bio.bio_status); 79 } 80 } 81