-/* $OpenBSD: efi_softraid.c,v 1.3 2022/10/05 09:58:43 kn Exp $ */
+/* $OpenBSD: efi_softraid.c,v 1.4 2022/11/07 15:56:09 kn Exp $ */
/*
* Copyright (c) 2012 Joel Sing <jsing@openbsd.org>
* Copyright (c) 2022 Klemens Nanni <kn@openbsd.org>
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/types.h>
-#include <sys/disklabel.h>
-#include <sys/ioctl.h>
-
#include <dev/biovar.h>
-#include <dev/softraidvar.h>
-#include <err.h>
-#include <fcntl.h>
#include <stdio.h>
-#include <string.h>
-#include <util.h>
#include <unistd.h>
#include "installboot.h"
int diskfd;
char part;
- /* Get device name for this disk/chunk. */
- memset(&bd, 0, sizeof(bd));
- bd.bd_volid = vol;
- bd.bd_diskid = disk;
- if (ioctl(devfd, BIOCDISK, &bd) == -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;
- }
-
- /* Keydisks always have a size of zero. */
- if (bd.bd_size == 0) {
- fprintf(stderr, "softraid chunk %u is keydisk - skipping...\n",
- disk);
+ diskfd = sr_open_chunk(devfd, vol, disk, &bd, &realdev, &part);
+ if (diskfd == -1)
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)) == -1)
- err(1, "open: %s", realdev);
if (verbose)
fprintf(stderr, "%s%c: %s boot blocks on %s\n", bd.bd_vendor,
-/* $OpenBSD: i386_softraid.c,v 1.20 2022/10/05 09:58:43 kn Exp $ */
+/* $OpenBSD: i386_softraid.c,v 1.21 2022/11/07 15:56:09 kn Exp $ */
/*
* Copyright (c) 2012 Joel Sing <jsing@openbsd.org>
* Copyright (c) 2010 Otto Moerbeek <otto@drijf.net>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <util.h>
#include "installboot.h"
#include "i386_installboot.h"
char part, efipart;
int diskfd;
- /* Get device name for this disk/chunk. */
- memset(&bd, 0, sizeof(bd));
- bd.bd_volid = vol;
- bd.bd_diskid = disk;
- if (ioctl(devfd, BIOCDISK, &bd) == -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);
+ diskfd = sr_open_chunk(devfd, vol, disk, &bd, &dev, &part);
+ if (diskfd == -1)
return;
- }
-
- /* Keydisks always have a size of zero. */
- if (bd.bd_size == 0) {
- fprintf(stderr, "softraid chunk %u is keydisk - 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 this device and check its disklabel. */
- if ((diskfd = opendev(bd.bd_vendor, (nowrite? O_RDONLY:O_RDWR),
- OPENDEV_PART, &dev)) == -1)
- err(1, "open: %s", dev);
/* Get and check disklabel. */
if (ioctl(diskfd, DIOCGDINFO, &dl) == -1)
-/* $OpenBSD: installboot.h,v 1.14 2022/02/03 10:25:14 visa Exp $ */
+/* $OpenBSD: installboot.h,v 1.15 2022/11/07 15:56:09 kn Exp $ */
/*
* Copyright (c) 2012, 2013 Joel Sing <jsing@openbsd.org>
*
void md_installboot(int, char *);
#ifdef SOFTRAID
+int sr_open_chunk(int, int, int, struct bioc_disk *, char **, char *);
void sr_installboot(int, char *);
void sr_install_bootblk(int, int, int);
void sr_install_bootldr(int, char *);
-/* $OpenBSD: softraid.c,v 1.5 2020/06/08 19:17:12 kn Exp $ */
+/* $OpenBSD: softraid.c,v 1.6 2022/11/07 15:56:09 kn Exp $ */
/*
* Copyright (c) 2012 Joel Sing <jsing@openbsd.org>
*
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <sys/types.h>
+#include <sys/disklabel.h>
#include <sys/dkio.h>
#include <sys/ioctl.h>
#include <dev/biovar.h>
#include <err.h>
+#include <fcntl.h>
#include <stdio.h>
#include <string.h>
+#include <util.h>
#include "installboot.h"
exit(1);
}
}
+
+int
+sr_open_chunk(int devfd, int vol, int disk, struct bioc_disk *bd,
+ char **realdev, char *part)
+{
+ int diskfd;
+
+ /* Get device name for this disk/chunk. */
+ memset(bd, 0, sizeof(*bd));
+ bd->bd_volid = vol;
+ bd->bd_diskid = disk;
+ if (ioctl(devfd, BIOCDISK, bd) == -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 -1;
+ }
+
+ /* Keydisks always have a size of zero. */
+ if (bd->bd_size == 0) {
+ fprintf(stderr, "softraid chunk %u is keydisk - skipping...\n",
+ disk);
+ return -1;
+ }
+
+ 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)) == -1)
+ err(1, "open: %s", *realdev);
+
+ return diskfd;
+}
-/* $OpenBSD: sparc64_softraid.c,v 1.7 2022/10/05 09:58:43 kn Exp $ */
+/* $OpenBSD: sparc64_softraid.c,v 1.8 2022/11/07 15:56:09 kn Exp $ */
/*
* Copyright (c) 2012 Joel Sing <jsing@openbsd.org>
*
int diskfd;
char part;
- /* Get device name for this disk/chunk. */
- memset(&bd, 0, sizeof(bd));
- bd.bd_volid = vol;
- bd.bd_diskid = disk;
- if (ioctl(devfd, BIOCDISK, &bd) == -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;
- }
-
- /* Keydisks always have a size of zero. */
- if (bd.bd_size == 0) {
- fprintf(stderr, "softraid chunk %u is keydisk - skipping...\n",
- disk);
+ diskfd = sr_open_chunk(devfd, vol, disk, &bd, &realdev, &part);
+ if (diskfd == -1)
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)) == -1)
- err(1, "open: %s", realdev);
if (verbose)
fprintf(stderr, "%s%c: %s boot blocks on %s\n", bd.bd_vendor,