summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryasuoka <yasuoka@openbsd.org>2016-08-31 15:11:22 +0000
committeryasuoka <yasuoka@openbsd.org>2016-08-31 15:11:22 +0000
commit055ff051724489a90c9bfea6bb2996b58701a830 (patch)
treed84306b2f29f3e26a766b84008938e8966b1a909
parentSplit gre(4) into two interfaces: gre(4) and mobileip(4). (diff)
downloadwireguard-openbsd-055ff051724489a90c9bfea6bb2996b58701a830.tar.xz
wireguard-openbsd-055ff051724489a90c9bfea6bb2996b58701a830.zip
Enable cd9660 in efiboot.
-rw-r--r--sys/arch/amd64/stand/efiboot/Makefile.common4
-rw-r--r--sys/arch/amd64/stand/efiboot/conf.c7
-rw-r--r--sys/arch/amd64/stand/efiboot/efidev.c69
3 files changed, 73 insertions, 7 deletions
diff --git a/sys/arch/amd64/stand/efiboot/Makefile.common b/sys/arch/amd64/stand/efiboot/Makefile.common
index e1cb63387fb..da2646d6664 100644
--- a/sys/arch/amd64/stand/efiboot/Makefile.common
+++ b/sys/arch/amd64/stand/efiboot/Makefile.common
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.common,v 1.5 2016/05/11 08:30:58 kettenis Exp $
+# $OpenBSD: Makefile.common,v 1.6 2016/08/31 15:11:22 yasuoka Exp $
S= ${.CURDIR}/../../../../..
SADIR= ${.CURDIR}/../..
@@ -36,7 +36,7 @@ SRCS+= alloc.c ctime.c exit.c getchar.c memcmp.c memcpy.c memset.c printf.c \
strtol.c strtoll.c
SRCS+= close.c closeall.c cons.c cread.c dev.c disklabel.c dkcksum.c fstat.c \
lseek.c open.c read.c readdir.c stat.c
-SRCS+= ufs.c
+SRCS+= ufs.c cd9660.c
.if ${SOFTRAID:L} == "yes"
SRCS+= aes_xts.c explicit_bzero.c hmac_sha1.c pbkdf2.c rijndael.c sha1.c
.endif
diff --git a/sys/arch/amd64/stand/efiboot/conf.c b/sys/arch/amd64/stand/efiboot/conf.c
index 7893c40c379..282da3adab8 100644
--- a/sys/arch/amd64/stand/efiboot/conf.c
+++ b/sys/arch/amd64/stand/efiboot/conf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: conf.c,v 1.3 2016/02/19 21:30:06 naddy Exp $ */
+/* $OpenBSD: conf.c,v 1.4 2016/08/31 15:11:22 yasuoka Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
@@ -31,6 +31,7 @@
#include <sys/disklabel.h>
#include <libsa.h>
#include <lib/libsa/ufs.h>
+#include <lib/libsa/cd9660.h>
#include <dev/cons.h>
#include "disk.h"
@@ -63,13 +64,13 @@ int nibprobes = nitems(probe_list);
struct fs_ops file_system[] = {
{ ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek,
ufs_stat, ufs_readdir },
+ { cd9660_open, cd9660_close, cd9660_read, cd9660_write, cd9660_seek,
+ cd9660_stat, cd9660_readdir },
#ifdef notdef
{ fat_open, fat_close, fat_read, fat_write, fat_seek,
fat_stat, fat_readdir },
{ nfs_open, nfs_close, nfs_read, nfs_write, nfs_seek,
nfs_stat, nfs_readdir },
- { cd9660_open, cd9660_close, cd9660_read, cd9660_write, cd9660_seek,
- cd9660_stat, cd9660_readdir },
#endif
};
int nfsys = nitems(file_system);
diff --git a/sys/arch/amd64/stand/efiboot/efidev.c b/sys/arch/amd64/stand/efiboot/efidev.c
index b0cac089f14..e34d47360d0 100644
--- a/sys/arch/amd64/stand/efiboot/efidev.c
+++ b/sys/arch/amd64/stand/efiboot/efidev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: efidev.c,v 1.18 2016/05/06 03:13:52 yasuoka Exp $ */
+/* $OpenBSD: efidev.c,v 1.19 2016/08/31 15:11:22 yasuoka Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
@@ -32,6 +32,7 @@
#include <sys/reboot.h>
#include <sys/disklabel.h>
#include <lib/libz/zlib.h>
+#include <isofs/cd9660/iso.h>
#include "libsa.h"
#include "disk.h"
@@ -61,6 +62,7 @@ int bios_bootdev;
static EFI_STATUS
efid_io(int, efi_diskinfo_t, u_int, int, void *);
static int efid_diskio(int, struct diskinfo *, u_int, int, void *);
+static int efi_getdisklabel_cd9660(efi_diskinfo_t, struct disklabel *);
static u_int findopenbsd(efi_diskinfo_t, const char **);
static u_int findopenbsd_gpt(efi_diskinfo_t, const char **);
static int gpt_chk_mbr(struct dos_partition *, u_int64_t);
@@ -425,8 +427,11 @@ efi_getdisklabel(efi_diskinfo_t ed, struct disklabel *label)
return ("Disk I/O Error");
/* Check MBR signature. */
- if (buf[510] != 0x55 || buf[511] != 0xaa)
+ if (buf[510] != 0x55 || buf[511] != 0xaa) {
+ if (efi_getdisklabel_cd9660(ed, label) == 0)
+ return (NULL);
return ("invalid MBR signature");
+ }
memcpy(dosparts, buf+DOSPARTOFF, sizeof(dosparts));
@@ -462,6 +467,66 @@ efi_getdisklabel(efi_diskinfo_t ed, struct disklabel *label)
return (getdisklabel(buf, label));
}
+static int
+efi_getdisklabel_cd9660(efi_diskinfo_t ed, struct disklabel *label)
+{
+ int off;
+ uint8_t buf[DEV_BSIZE];
+ EFI_STATUS status;
+
+ for (off = 0; off < 100; off++) {
+ status = efid_io(F_READ, ed,
+ EFI_BLKSPERSEC(ed) * (16 + off), 1, buf);
+ if (EFI_ERROR(status))
+ return (-1);
+ if (bcmp(buf + 1, ISO_STANDARD_ID, 5) != 0 ||
+ buf[0] == ISO_VD_END)
+ return (-1);
+ if (buf[0] == ISO_VD_PRIMARY)
+ break;
+ }
+ if (off >= 100)
+ return (-1);
+
+ /* Create an imaginary disk label */
+ label->d_secsize = 2048;
+ label->d_ntracks = 1;
+ label->d_nsectors = 100;
+ label->d_ncylinders = 1;
+ label->d_secpercyl = label->d_ntracks * label->d_nsectors;
+ if (label->d_secpercyl == 0) {
+ label->d_secpercyl = 100;
+ /* as long as it's not 0, since readdisklabel divides by it */
+ }
+
+ strncpy(label->d_typename, "ATAPI CD-ROM", sizeof(label->d_typename));
+ label->d_type = DTYPE_ATAPI;
+
+ strncpy(label->d_packname, "fictitious", sizeof(label->d_packname));
+ DL_SETDSIZE(label, 100);
+
+ label->d_bbsize = 2048;
+ label->d_sbsize = 2048;
+
+ /* 'a' partition covering the "whole" disk */
+ DL_SETPOFFSET(&label->d_partitions[0], 0);
+ DL_SETPSIZE(&label->d_partitions[0], 100);
+ label->d_partitions[0].p_fstype = FS_UNUSED;
+
+ /* The raw partition is special */
+ DL_SETPOFFSET(&label->d_partitions[RAW_PART], 0);
+ DL_SETPSIZE(&label->d_partitions[RAW_PART], 100);
+ label->d_partitions[RAW_PART].p_fstype = FS_UNUSED;
+
+ label->d_npartitions = MAXPARTITIONS;
+
+ label->d_magic = DISKMAGIC;
+ label->d_magic2 = DISKMAGIC;
+ label->d_checksum = dkcksum(label);
+
+ return (0);
+}
+
int
efiopen(struct open_file *f, ...)
{