xref: /illumos-gate/usr/src/cmd/fs.d/pcfs/fsck/pcfs_bpb.h (revision 01d4d8e79088c1c743ce26509694aae9b9e08696)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1999 by Sun Microsystems, Inc.
24  * All rights reserved.
25  * Copyright 2024 MNX Cloud, Inc.
26  */
27 
28 #ifndef _PCFS_BPB_H
29 #define	_PCFS_BPB_H
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 extern size_t bpsec;
36 /*
37  * Common Bios Parameter Block definitions for the pcfs user-level utilities
38  *
39  * At press time these definitions are duplicated in mkfs_pcfs.h.  They really
40  * need to be separated out of mkfs_pcfs.h and then it should reference this
41  * file.
42  */
43 #define	MINBPS		512
44 #define	MAXBPS		4096
45 
46 #define	OPCODE1		0xE9
47 #define	OPCODE2		0xEB
48 #define	BOOTSECSIG	0xAA55
49 
50 /*
51  * Offset (in bytes) from address of boot sector to where we put
52  * the backup copy of that sector.  (FAT32 only)
53  */
54 #define	BKUP_BOOTSECT_OFFSET	0xC00
55 
56 #define	uppercase(c)	((c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 'A' : (c))
57 
58 #define	FAT12_TYPE_STRING	"FAT12   "
59 #define	FAT16_TYPE_STRING	"FAT16   "
60 #define	FAT32_TYPE_STRING	"FAT32   "
61 
62 #define	FAT12_ENTSPERSECT	341
63 #define	FAT16_ENTSPERSECT	256
64 #define	FAT32_ENTSPERSECT	128
65 
66 #ifndef	SUNIXOSBOOT
67 #define	SUNIXOSBOOT	190	/* Solaris UNIX boot partition */
68 #endif
69 
70 /*
71  *	MS-DOS Disk layout:
72  *
73  *	---------------------
74  *	|    Boot sector    |
75  *	|-------------------|
76  *	|   Reserved area   |
77  *	|-------------------|
78  *	|	FAT #1      |
79  *	|-------------------|
80  *	|	FAT #2      |
81  *	|-------------------|
82  *	|   Root directory  |
83  *	|-------------------|
84  *	|                   |
85  *	|     File area     |
86  *	|___________________|
87  */
88 #ifdef i386
89 #pragma	pack(1)
90 #endif
91 struct _orig_bios_param_blk {
92 	uint16_t bytes_per_sector;
93 	uchar_t	 sectors_per_cluster;
94 	uint16_t resv_sectors;
95 	uchar_t	 num_fats;
96 	uint16_t num_root_entries;
97 /*
98  *  The sectors_in_volume field will be zero on larger volumes (>32Mb)
99  *  and newer file systems (>=MSDOS4.0).  In these cases the
100  *  sectors_in_logical_volume field should be used instead.
101  */
102 	uint16_t sectors_in_volume;
103 	uchar_t	 media;
104 	uint16_t sectors_per_fat;
105 	uint16_t sectors_per_track;
106 	uint16_t heads;
107 /*
108  *  Number of sectors in the partition prior to the start of the logical disk
109  */
110 	uint32_t hidden_sectors;
111 	uint32_t sectors_in_logical_volume;
112 };
113 #ifdef i386
114 #pragma pack()
115 #endif
116 
117 #ifdef i386
118 #pragma	pack(1)
119 #endif
120 struct _bpb32_extensions {
121 	uint32_t big_sectors_per_fat;
122 	uint16_t ext_flags;
123 	uchar_t	 fs_vers_lo;
124 	uchar_t	 fs_vers_hi;
125 	uint32_t root_dir_clust;
126 	uint16_t fsinfosec;
127 	uint16_t backupboot;
128 	uint16_t reserved[6];
129 };
130 #ifdef i386
131 #pragma pack()
132 #endif
133 
134 #ifdef i386
135 #pragma	pack(1)
136 #endif
137 struct _bpb_extensions {
138 	uchar_t  phys_drive_num;
139 	uchar_t  reserved;
140 	uchar_t  ext_signature;
141 	uint32_t volume_id;
142 	uchar_t  volume_label[11];
143 	uchar_t  type[8];
144 };
145 #ifdef i386
146 #pragma pack()
147 #endif
148 
149 #ifdef i386
150 #pragma	pack(1)
151 #endif
152 struct _sun_bpb_extensions {
153 	uint16_t  bs_offset_high;
154 	uint16_t  bs_offset_low;
155 };
156 #ifdef i386
157 #pragma pack()
158 #endif
159 
160 /*
161  * bpb_t is a conglomeration of all the fields a bpb can have.  Every
162  * bpb will have the orig_bios struct, but only FAT32's will have bpb32,
163  * and only Solaris boot diskettes will have the sunbpb structure.
164  */
165 typedef struct _bios_param_blk {
166 	struct _orig_bios_param_blk bpb;
167 	struct _bpb32_extensions    bpb32;
168 	struct _bpb_extensions	    ebpb;
169 	struct _sun_bpb_extensions  sunbpb;
170 } bpb_t;
171 
172 #ifdef i386
173 #pragma	pack(1)
174 struct _bpb_head {
175 	uchar_t			    bs_jump_code[3];
176 	uchar_t			    bs_oem_name[8];
177 	struct _orig_bios_param_blk bs_bpb;
178 };
179 #pragma pack()
180 
181 #pragma	pack(1)
182 struct _boot_sector {
183 	struct _bpb_head	    bs_front;
184 	struct _bpb_extensions	    bs_ebpb;
185 	struct _sun_bpb_extensions  bs_sebpb;
186 	uchar_t			    bs_bootstrap[444];
187 	uchar_t			    bs_signature[2];
188 };
189 #pragma pack()
190 
191 #pragma	pack(1)
192 struct _boot_sector32 {
193 	struct _bpb_head	    bs_front;
194 	struct _bpb32_extensions    bs_bpb32;
195 	struct _bpb_extensions	    bs_ebpb;
196 	uchar_t			    bs_bootstrap[420];
197 	uchar_t			    bs_signature[2];
198 };
199 #pragma pack()
200 #else
201 #define	ORIG_BPB_START_INDEX	8	/* index into filler field */
202 #define	EXT_BPB_START_INDEX	33	/* index into filler field */
203 #define	BPB_32_START_INDEX	33	/* index into filler field */
204 #define	EXT_BPB_32_START_INDEX	61	/* index into filler field */
205 struct _boot_sector {
206 	uchar_t	 bs_jump_code[3];
207 	uchar_t  bs_filler[59];
208 	uchar_t  bs_sun_bpb[4];
209 	uchar_t	 bs_bootstrap[444];
210 	uchar_t  bs_signature[2];
211 };
212 
213 struct _boot_sector32 {
214 	uchar_t	 bs_jump_code[3];
215 	uchar_t  bs_filler[87];
216 	uchar_t	 bs_bootstrap[420];
217 	uchar_t  bs_signature[2];
218 };
219 #endif
220 
221 typedef union _ubso {
222 	struct _boot_sector	bs;
223 	struct _boot_sector32	bs32;
224 	struct mboot		mb;
225 	uchar_t			buf[MAXBPS];
226 } boot_sector_t;
227 
228 #ifdef __cplusplus
229 }
230 #endif
231 
232 #endif /* _PCFS_BPB_H */
233