xref: /illumos-gate/usr/src/cmd/fs.d/pcfs/common/pcfs_bpb.h (revision 4c75c86ed9514c627ddb82a345adecc7c1e43b91)
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 /*
36  * Common Bios Parameter Block definitions for the pcfs user-level utilities
37  */
38 #define	MINBPS		512
39 #define	MAXBPS		4096
40 
41 #define	OPCODE1		0xE9
42 #define	OPCODE2		0xEB
43 #define	BOOTSECSIG	0xAA55
44 
45 /*
46  * Offset (in bytes) from address of boot sector to where we put
47  * the backup copy of that sector.  (FAT32 only)
48  */
49 #define	BKUP_BOOTSECT_OFFSET	0xC00
50 
51 #define	uppercase(c)	((c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 'A' : (c))
52 
53 #define	FAT12_TYPE_STRING	"FAT12   "
54 #define	FAT16_TYPE_STRING	"FAT16   "
55 #define	FAT32_TYPE_STRING	"FAT32   "
56 
57 #define	FAT12_ENTSPERSECT	341
58 #define	FAT16_ENTSPERSECT	256
59 #define	FAT32_ENTSPERSECT	128
60 
61 #ifndef	SUNIXOSBOOT
62 #define	SUNIXOSBOOT	190	/* Solaris UNIX boot partition */
63 #endif
64 
65 /*
66  *	MS-DOS Disk layout:
67  *
68  *	---------------------
69  *	|    Boot sector    |
70  *	|-------------------|
71  *	|   Reserved area   |
72  *	|-------------------|
73  *	|	FAT #1      |
74  *	|-------------------|
75  *	|	FAT #2      |
76  *	|-------------------|
77  *	|   Root directory  |
78  *	|-------------------|
79  *	|                   |
80  *	|     File area     |
81  *	|___________________|
82  */
83 #ifdef _LITTLE_ENDIAN
84 #pragma	pack(1)
85 #endif
86 struct _orig_bios_param_blk {
87 	uint16_t bytes_per_sector;
88 	uchar_t	 sectors_per_cluster;
89 	uint16_t resv_sectors;
90 	uchar_t	 num_fats;
91 	uint16_t num_root_entries;
92 /*
93  *  The sectors_in_volume field will be zero on larger volumes (>32Mb)
94  *  and newer file systems (>=MSDOS4.0).  In these cases the
95  *  sectors_in_logical_volume field should be used instead.
96  */
97 	uint16_t sectors_in_volume;
98 	uchar_t	 media;
99 	uint16_t sectors_per_fat;
100 	uint16_t sectors_per_track;
101 	uint16_t heads;
102 /*
103  *  Number of sectors in the partition prior to the start of the logical disk
104  */
105 	uint32_t hidden_sectors;
106 	uint32_t sectors_in_logical_volume;
107 };
108 #ifdef _LITTLE_ENDIAN
109 #pragma pack()
110 #endif
111 
112 #ifdef _LITTLE_ENDIAN
113 #pragma	pack(1)
114 #endif
115 struct _bpb32_extensions {
116 	uint32_t big_sectors_per_fat;
117 	uint16_t ext_flags;
118 	uchar_t	 fs_vers_lo;
119 	uchar_t	 fs_vers_hi;
120 	uint32_t root_dir_clust;
121 	uint16_t fsinfosec;
122 	uint16_t backupboot;
123 	uint16_t reserved[6];
124 };
125 #ifdef _LITTLE_ENDIAN
126 #pragma pack()
127 #endif
128 
129 #ifdef _LITTLE_ENDIAN
130 #pragma	pack(1)
131 #endif
132 struct _bpb_extensions {
133 	uchar_t  phys_drive_num;
134 	uchar_t  reserved;
135 	uchar_t  ext_signature;
136 	uint32_t volume_id;
137 	uchar_t  volume_label[11];
138 	uchar_t  type[8];
139 };
140 #ifdef _LITTLE_ENDIAN
141 #pragma pack()
142 #endif
143 
144 #ifdef _LITTLE_ENDIAN
145 #pragma	pack(1)
146 #endif
147 struct _sun_bpb_extensions {
148 	uint16_t  bs_offset_high;
149 	uint16_t  bs_offset_low;
150 };
151 #ifdef _LITTLE_ENDIAN
152 #pragma pack()
153 #endif
154 
155 /*
156  * bpb_t is a conglomeration of all the fields a bpb can have.  Every
157  * bpb will have the orig_bios struct, but only FAT32's will have bpb32,
158  * and only Solaris boot diskettes will have the sunbpb structure.
159  */
160 typedef struct _bios_param_blk {
161 	struct _orig_bios_param_blk bpb;
162 	struct _bpb32_extensions    bpb32;
163 	struct _bpb_extensions	    ebpb;
164 	struct _sun_bpb_extensions  sunbpb;
165 } bpb_t;
166 
167 #ifdef _LITTLE_ENDIAN
168 #pragma	pack(1)
169 struct _bpb_head {
170 	uchar_t			    bs_jump_code[3];
171 	uchar_t			    bs_oem_name[8];
172 	struct _orig_bios_param_blk bs_bpb;
173 };
174 #pragma pack()
175 
176 #pragma	pack(1)
177 struct _boot_sector {
178 	struct _bpb_head	    bs_front;
179 	struct _bpb_extensions	    bs_ebpb;
180 	struct _sun_bpb_extensions  bs_sebpb;
181 	uchar_t			    bs_bootstrap[444];
182 	uchar_t			    bs_signature[2];
183 };
184 #pragma pack()
185 
186 #pragma	pack(1)
187 struct _boot_sector32 {
188 	struct _bpb_head	    bs_front;
189 	struct _bpb32_extensions    bs_bpb32;
190 	struct _bpb_extensions	    bs_ebpb;
191 	uchar_t			    bs_bootstrap[420];
192 	uchar_t			    bs_signature[2];
193 };
194 #pragma pack()
195 #else
196 #define	ORIG_BPB_START_INDEX	8	/* index into filler field */
197 #define	EXT_BPB_START_INDEX	33	/* index into filler field */
198 #define	BPB_32_START_INDEX	33	/* index into filler field */
199 #define	EXT_BPB_32_START_INDEX	61	/* index into filler field */
200 struct _boot_sector {
201 	uchar_t	 bs_jump_code[3];
202 	uchar_t  bs_filler[59];
203 	uchar_t  bs_sun_bpb[4];
204 	uchar_t	 bs_bootstrap[444];
205 	uchar_t  bs_signature[2];
206 };
207 
208 struct _boot_sector32 {
209 	uchar_t	 bs_jump_code[3];
210 	uchar_t  bs_filler[87];
211 	uchar_t	 bs_bootstrap[420];
212 	uchar_t  bs_signature[2];
213 };
214 #endif
215 
216 typedef union _ubso {
217 	struct _boot_sector	bs;
218 	struct _boot_sector32	bs32;
219 	struct mboot		mb;
220 	uchar_t			buf[MAXBPS];
221 } boot_sector_t;
222 
223 #ifdef __cplusplus
224 }
225 #endif
226 
227 #endif /* _PCFS_BPB_H */
228