1 /******************************************************************************
4 * Copyright (c) 2020, longpanda <admin@ventoy.net>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
25 * [1] EL TORITO扩展规范里定义的数据都是小字节序的
28 #ifndef __BISO_ELTORITO_H__
29 #define __BISO_ELTORITO_H__
32 * EL TORITO规范里对于Boot Record里面BootCatlog指向的扩展区域做了
33 * 结构定义,分成一条条的表项,每一条表项固定32个字节长,1个扇区
34 * 可以保存64条表项。BootCatlog可以占用多个扇区。
41 * 4 Section Extension Entry 1
42 * 5 Section Extension Entry 2
43 * 6 Section Extension Entry 3
47 * N+2 Section Extension Entry 1
48 * N+3 Section Extension Entry 2
49 * N+4 Section Extension Entry 3
53 #define BISO_ELTORITO_ENTRY_LEN 32
58 typedef struct tagBISO_TORITO_VALIDATION_ENTRY
60 UCHAR ucHeaderID
; /* Must be 01 */
67 * 0xEF: EFI System Partition
73 /* ID,一般用来保存CD-ROM的制造商信息 */
78 * 这个字段用来保证整个Validation Entry的数据
79 * 按照WORD(双字节)累加起来为0(截取之后)
83 /* 魔数字,检验使用,值必须为0x55和0xAA */
86 }BISO_TORITO_VALIDATION_ENTRY_S
;
88 /* 默认初始化表项(BIOS里面的 INT 13) */
89 typedef struct tagBISO_TORITO_INITIAL_ENTRY
91 /* BOOTID: 0x88:Bootable, 00:Not Bootable */
99 * 2: 1.44 meg diskette
100 * 3: 2.88 meg diskette
101 * 4: Hard Disk(drive 80)
107 /* 启动段,只对x86构架有效,为0默认使用7C0, 注意[1] */
108 UINT16 usLoadSegment
;
110 /* 是Boot Image里面Partition Table的第5个字节(System Type) */
115 /* 启动时每次往内存读多长, 注意[1] */
116 UINT16 usSectorCount
;
118 /* 启动文件所在的起始逻辑块编号,例如isolinux.bin文件的位置, 注意[1] */
122 }BISO_TORITO_INITIAL_ENTRY_S
;
125 * Section Header, 补充一系列可启动的Entry(比如UEFI启动)
126 * 如果默认的Initial/Default Entry不满足BIOS需求
127 * BIOS可以继续往下找,根据Section Header里面的ID
128 * 以及Section Entry里面的Criteria信息决定是否从
132 typedef struct tagBISO_TORITO_SECHDR_ENTRY
134 /* ucFlag: 0x90:表示后面还有Header, 0x91:表示最后一个Header */
142 * 0xEF: EFI System Partition
146 /* 跟在这个头的后面有多少个Section Entry */
147 UINT16 usSecEntryNum
;
151 }BISO_TORITO_SECHDR_ENTRY_S
;
154 typedef struct tagBISO_TORITO_SECTION_ENTRY
156 /* BOOTID: 88:Bootable, 00:Not Bootable */
163 * 1: 1.2 meg diskette
164 * 2: 1.44 meg diskette
165 * 3: 2.88 meg diskette
166 * 4: Hard Disk(drive 80)
169 * Bit5:Continuation Entry Follows
170 * Bit6:Image contains an ATAPI driver
171 * Bit7:Image contains SCSI driver
175 /* 启动段,只对x86构架有效,为0默认使用7C0, 注意[1] */
176 UINT16 usLoadSegment
;
178 /* 是Boot Image里面Partition Table的第5个字节(System Type) */
183 /* 启动时每次往内存读多长, 注意[1] */
184 UINT16 usSectorCount
;
186 /* 启动文件所在的起始逻辑块编号,例如isolinux.bin文件的位置, 注意[1] */
190 * 它的值描述了后面的aucCriteria的格式
192 * 1: Language and Version Information (IBM)
195 UCHAR ucCriteriaType
;
197 /* Criteria信息,如果这19个字节不够用,可以使用Section Extension Entry里的 */
198 UCHAR aucCriteria
[19];
199 }BISO_TORITO_SECTION_ENTRY_S
;
201 /* 扩展Section Entry */
202 typedef struct tagBISO_TORITO_SECEXT_ENTRY
209 * Bit5: 1表示后面还有Extension Record 0表示最后一个
214 UCHAR aucCriteria
[39];
215 }BISO_TORITO_SECEXT_ENTRY_S
;
221 * 如果已经超过了2048字节,则继续从文件中读
223 #define BISO_ELTORITO_ENTRY_STEP(pstSection, pstFile, aucBuf, stMBuf) \
227 if ((UCHAR *)pstSection >= aucBuf + BISO_SECTOR_SIZE)\
229 (VOID)BISO_MBUF_Append(&stMBuf, BISO_SECTOR_SIZE, aucBuf);\
230 _uiReadLen = (UINT)BISO_PLAT_ReadFile(pstFile, 1, BISO_SECTOR_SIZE, aucBuf);\
231 if (_uiReadLen != BISO_SECTOR_SIZE)\
233 BISO_DIAG("Read Len %u, sector len %u.", _uiReadLen, BISO_SECTOR_SIZE);\
234 BISO_MBUF_Free(&stMBuf);\
235 return BISO_ERR_READ_FILE;\
237 pstSection = (BISO_TORITO_SECTION_ENTRY_S *)aucBuf;\
241 ULONG
BISO_ELTORITO_ReadBootInfo(IN BISO_FILE_S
*pstFile
, OUT BISO_PARSER_S
*pstParser
);
242 VOID
BISO_ELTORITO_Dump(IN CONST BISO_PARSER_S
*pstParser
);
243 UINT
BISO_ELTORITO_GetBootEntryNum(IN CONST BISO_PARSER_S
*pstParser
);
245 #endif /* __BISO_ELTORITO_H__ */