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