1 /* 2 * $NetBSD: cd9660_eltorito.h,v 1.6 2017/01/24 11:22:43 nonaka Exp $ 3 */ 4 5 /* 6 * SPDX-License-Identifier: BSD-2-Clause-NetBSD 7 * 8 * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan 9 * Perez-Rathke and Ram Vedam. All rights reserved. 10 * 11 * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys, 12 * Alan Perez-Rathke and Ram Vedam. 13 * 14 * Redistribution and use in source and binary forms, with or 15 * without modification, are permitted provided that the following 16 * conditions are met: 17 * 1. Redistributions of source code must retain the above copyright 18 * notice, this list of conditions and the following disclaimer. 19 * 2. Redistributions in binary form must reproduce the above 20 * copyright notice, this list of conditions and the following 21 * disclaimer in the documentation and/or other materials provided 22 * with the distribution. 23 * 24 * THIS SOFTWARE IS PROVIDED BY DANIEL WATT, WALTER DEIGNAN, RYAN 25 * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR 26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 * DISCLAIMED. IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN 29 * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT, 30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 32 * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 33 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 34 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 36 * OF SUCH DAMAGE. 37 */ 38 39 #ifndef _CD9660_ELTORITO_H_ 40 #define _CD9660_ELTORITO_H_ 41 42 #include <sys/types.h> 43 #include <sys/queue.h> 44 45 /* Boot defines */ 46 #define ET_ID "EL TORITO SPECIFICATION" 47 #define ET_SYS_X86 0 48 #define ET_SYS_PPC 1 49 #define ET_SYS_MAC 2 50 #define ET_SYS_EFI 0xef /* Platform ID at section header entry */ 51 52 #define ET_BOOT_ENTRY_SIZE 0x20 53 54 #define ET_BOOTABLE 0x88 55 #define ET_NOT_BOOTABLE 0 56 57 #define ET_MEDIA_NOEM 0 58 #define ET_MEDIA_12FDD 1 59 #define ET_MEDIA_144FDD 2 60 #define ET_MEDIA_288FDD 3 61 #define ET_MEDIA_HDD 4 62 63 #define ET_INDICATOR_HEADERMORE 0x90 64 #define ET_INDICATOR_HEADERLAST 0x91 65 #define ET_INDICATOR_EXTENSION 0x44 66 67 /* Boot Structures */ 68 69 #define ISODCL(from, to) (to - from + 1) 70 71 typedef struct _boot_volume_descriptor { 72 uchar_t boot_record_indicator [ISODCL(0x00, 0x00)]; 73 uchar_t identifier [ISODCL(0x01, 0x05)]; 74 uchar_t version [ISODCL(0x06, 0x06)]; 75 uchar_t boot_system_identifier [ISODCL(0x07, 0x26)]; 76 uchar_t unused1 [ISODCL(0x27, 0x46)]; 77 uchar_t boot_catalog_pointer [ISODCL(0x47, 0x4A)]; 78 uchar_t unused2 [ISODCL(0x4B, 0x7FF)]; 79 } boot_volume_descriptor; 80 81 typedef struct _boot_catalog_validation_entry { 82 uchar_t header_id [ISODCL(0x00, 0x00)]; 83 uchar_t platform_id [ISODCL(0x01, 0x01)]; 84 uchar_t reserved1 [ISODCL(0x02, 0x03)]; 85 uchar_t manufacturer [ISODCL(0x04, 0x1B)]; 86 uchar_t checksum [ISODCL(0x1C, 0x1D)]; 87 uchar_t key [ISODCL(0x1E, 0x1F)]; 88 } boot_catalog_validation_entry; 89 90 typedef struct _boot_catalog_initial_entry { 91 uchar_t boot_indicator [ISODCL(0x00, 0x00)]; 92 uchar_t media_type [ISODCL(0x01, 0x01)]; 93 uchar_t load_segment [ISODCL(0x02, 0x03)]; 94 uchar_t system_type [ISODCL(0x04, 0x04)]; 95 uchar_t unused_1 [ISODCL(0x05, 0x05)]; 96 uchar_t sector_count [ISODCL(0x06, 0x07)]; 97 uchar_t load_rba [ISODCL(0x08, 0x0B)]; 98 uchar_t unused_2 [ISODCL(0x0C, 0x1F)]; 99 } boot_catalog_initial_entry; 100 101 #define ET_SECTION_HEADER_MORE 0x90 102 #define ET_SECTION_HEADER_LAST 0x91 103 104 typedef struct _boot_catalog_section_header { 105 uchar_t header_indicator [ISODCL(0x00, 0x00)]; 106 uchar_t platform_id [ISODCL(0x01, 0x01)]; 107 uchar_t num_section_entries [ISODCL(0x02, 0x03)]; 108 uchar_t id_string [ISODCL(0x04, 0x1F)]; 109 } boot_catalog_section_header; 110 111 typedef struct _boot_catalog_section_entry { 112 uchar_t boot_indicator [ISODCL(0x00, 0x00)]; 113 uchar_t media_type [ISODCL(0x01, 0x01)]; 114 uchar_t load_segment [ISODCL(0x02, 0x03)]; 115 uchar_t system_type [ISODCL(0x04, 0x04)]; 116 uchar_t unused_1 [ISODCL(0x05, 0x05)]; 117 uchar_t sector_count [ISODCL(0x06, 0x07)]; 118 uchar_t load_rba [ISODCL(0x08, 0x0B)]; 119 uchar_t selection_criteria [ISODCL(0x0C, 0x0C)]; 120 uchar_t vendor_criteria [ISODCL(0x0D, 0x1F)]; 121 } boot_catalog_section_entry; 122 123 typedef struct _boot_catalog_section_entry_extension { 124 uchar_t extension_indicator [ISODCL(0x00, 0x00)]; 125 uchar_t flags [ISODCL(0x01, 0x01)]; 126 uchar_t vendor_criteria [ISODCL(0x02, 0x1F)]; 127 } boot_catalog_section_entry_extension; 128 129 #define ET_ENTRY_VE 1 130 #define ET_ENTRY_IE 2 131 #define ET_ENTRY_SH 3 132 #define ET_ENTRY_SE 4 133 #define ET_ENTRY_EX 5 134 135 struct boot_catalog_entry { 136 char entry_type; 137 union { 138 boot_catalog_validation_entry VE; 139 boot_catalog_initial_entry IE; 140 boot_catalog_section_header SH; 141 boot_catalog_section_entry SE; 142 boot_catalog_section_entry_extension EX; 143 } entry_data; 144 145 LIST_ENTRY(boot_catalog_entry) ll_struct; 146 }; 147 148 /* Temporary structure */ 149 struct cd9660_boot_image { 150 char *filename; 151 int size; 152 int sector; /* copied to LoadRBA */ 153 int num_sectors; 154 unsigned int loadSegment; 155 uchar_t targetMode; 156 uchar_t system; 157 uchar_t bootable; 158 uchar_t platform_id; /* for section header entry */ 159 /* 160 * If the boot image exists in the filesystem 161 * already, this is a pointer to that node. For the sake 162 * of simplicity in future versions, this pointer is only 163 * to the node in the primary volume. This SHOULD be done 164 * via a hashtable lookup. 165 */ 166 struct _cd9660node *boot_image_node; 167 TAILQ_ENTRY(cd9660_boot_image) image_list; 168 int serialno; 169 }; 170 171 void cd9660_721(uint16_t, unsigned char *); 172 173 static __inline uint16_t 174 isonum_721(const unsigned char *p) 175 { 176 177 return (p[0] | p[1] << 8); 178 } 179 180 static __inline uint32_t 181 isonum_731(const unsigned char *p) 182 { 183 184 return (p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24); 185 } 186 187 #endif /* _CD9660_ELTORITO_H_ */ 188