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