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