bpb.h revision 33548
1/*	$Id: bpb.h,v 1.5 1997/02/22 09:40:44 peter Exp $ */
2/*	$NetBSD: bpb.h,v 1.7 1997/11/17 15:36:24 ws Exp $	*/
3
4/*
5 * Written by Paul Popelka (paulp@uts.amdahl.com)
6 *
7 * You can do anything you want with this software, just don't say you wrote
8 * it, and don't remove this notice.
9 *
10 * This software is provided "as is".
11 *
12 * The author supplies this software to be publicly redistributed on the
13 * understanding that the author is not responsible for the correct
14 * functioning of this software in any circumstances and is not liable for
15 * any damages caused by this software.
16 *
17 * October 1992
18 */
19
20/*
21 * BIOS Parameter Block (BPB) for DOS 3.3
22 */
23struct bpb33 {
24	u_int16_t	bpbBytesPerSec;	/* bytes per sector */
25	u_int8_t	bpbSecPerClust;	/* sectors per cluster */
26	u_int16_t	bpbResSectors;	/* number of reserved sectors */
27	u_int8_t	bpbFATs;	/* number of FATs */
28	u_int16_t	bpbRootDirEnts;	/* number of root directory entries */
29	u_int16_t	bpbSectors;	/* total number of sectors */
30	u_int8_t	bpbMedia;	/* media descriptor */
31	u_int16_t	bpbFATsecs;	/* number of sectors per FAT */
32	u_int16_t	bpbSecPerTrack;	/* sectors per track */
33	u_int16_t	bpbHeads;	/* number of heads */
34	u_int16_t	bpbHiddenSecs;	/* number of hidden sectors */
35};
36
37/*
38 * BPB for DOS 5.0 The difference is bpbHiddenSecs is a short for DOS 3.3,
39 * and bpbHugeSectors is not in the 3.3 bpb.
40 */
41struct bpb50 {
42	u_int16_t	bpbBytesPerSec;	/* bytes per sector */
43	u_int8_t	bpbSecPerClust;	/* sectors per cluster */
44	u_int16_t	bpbResSectors;	/* number of reserved sectors */
45	u_int8_t	bpbFATs;	/* number of FATs */
46	u_int16_t	bpbRootDirEnts;	/* number of root directory entries */
47	u_int16_t	bpbSectors;	/* total number of sectors */
48	u_int8_t	bpbMedia;	/* media descriptor */
49	u_int16_t	bpbFATsecs;	/* number of sectors per FAT */
50	u_int16_t	bpbSecPerTrack;	/* sectors per track */
51	u_int16_t	bpbHeads;	/* number of heads */
52	u_int32_t	bpbHiddenSecs;	/* # of hidden sectors */
53	u_int32_t	bpbHugeSectors;	/* # of sectors if bpbSectors == 0 */
54};
55
56/*
57 * BPB for DOS 7.10 (FAT32).  This one has a few extensions to bpb50.
58 */
59struct bpb710 {
60	u_int16_t	bpbBytesPerSec;	/* bytes per sector */
61	u_int8_t	bpbSecPerClust;	/* sectors per cluster */
62	u_int16_t	bpbResSectors;	/* number of reserved sectors */
63	u_int8_t	bpbFATs;	/* number of FATs */
64	u_int16_t	bpbRootDirEnts;	/* number of root directory entries */
65	u_int16_t	bpbSectors;	/* total number of sectors */
66	u_int8_t	bpbMedia;	/* media descriptor */
67	u_int16_t	bpbFATsecs;	/* number of sectors per FAT */
68	u_int16_t	bpbSecPerTrack;	/* sectors per track */
69	u_int16_t	bpbHeads;	/* number of heads */
70	u_int32_t	bpbHiddenSecs;	/* # of hidden sectors */
71	u_int32_t	bpbHugeSectors;	/* # of sectors if bpbSectors == 0 */
72	u_int32_t	bpbBigFATsecs;	/* like bpbFATsecs for FAT32 */
73	u_int16_t	bpbExtFlags;	/* extended flags: */
74#define	FATNUM		0xf		/* mask for numbering active FAT */
75#define	FATMIRROR	0x80		/* FAT is mirrored (like it always was) */
76	u_int16_t	bpbFSVers;	/* filesystem version */
77#define	FSVERS		0		/* currently only 0 is understood */
78	u_int32_t	bpbRootClust;	/* start cluster for root directory */
79	u_int16_t	bpbFSInfo;	/* filesystem info structure sector */
80	u_int16_t	bpbBackup;	/* backup boot sector */
81	/* There is a 12 byte filler here, but we ignore it */
82};
83
84#ifdef	atari
85/*
86 * BPB for gemdos filesystems. Atari leaves the obsolete stuff undefined.
87 * Currently there is no need for a separate BPB structure.
88 */
89#if 0
90struct bpb_a {
91	u_int16_t	bpbBytesPerSec;	/* bytes per sector		*/
92	u_int8_t	bpbSecPerClust;	/* sectors per cluster		*/
93	u_int16_t	bpbResSectors;	/* number of reserved sectors	*/
94	u_int8_t	bpbFATs;	/* number of FATs		*/
95	u_int16_t	bpbRootDirEnts;	/* number of root directory entries */
96	u_int16_t	bpbSectors;	/* total number of sectors	*/
97	u_int8_t	bpbUseless1;	/* meaningless on gemdos fs	*/
98	u_int16_t	bpbFATsecs;	/* number of sectors per FAT	*/
99	u_int16_t	bpbUseless2;	/* meaningless for harddisk fs	*/
100	u_int16_t	bpbUseless3;	/* meaningless for harddisk fs	*/
101	u_int16_t	bpbHiddenSecs;	/* the TOS-BIOS ignores this	*/
102};
103#endif
104#endif	/* atari */
105
106/*
107 * The following structures represent how the bpb's look on disk.  shorts
108 * and longs are just character arrays of the appropriate length.  This is
109 * because the compiler forces shorts and longs to align on word or
110 * halfword boundaries.
111 *
112 * XXX The little-endian code here assumes that the processor can access
113 * 16-bit and 32-bit quantities on byte boundaries.  If this is not true,
114 * use the macros for the big-endian case.
115 */
116#include <machine/endian.h>
117#if (BYTE_ORDER == LITTLE_ENDIAN) 			/* && defined(UNALIGNED_ACCESS) */
118#define	getushort(x)	*((u_int16_t *)(x))
119#define	getulong(x)	*((u_int32_t *)(x))
120#define	putushort(p, v)	(*((u_int16_t *)(p)) = (v))
121#define	putulong(p, v)	(*((u_int32_t *)(p)) = (v))
122#else
123#define getushort(x)	(((u_int8_t *)(x))[0] + (((u_int8_t *)(x))[1] << 8))
124#define getulong(x)	(((u_int8_t *)(x))[0] + (((u_int8_t *)(x))[1] << 8) \
125			 + (((u_int8_t *)(x))[2] << 16)	\
126			 + (((u_int8_t *)(x))[3] << 24))
127#define putushort(p, v)	(((u_int8_t *)(p))[0] = (v),	\
128			 ((u_int8_t *)(p))[1] = (v) >> 8)
129#define putulong(p, v)	(((u_int8_t *)(p))[0] = (v),	\
130			 ((u_int8_t *)(p))[1] = (v) >> 8, \
131			 ((u_int8_t *)(p))[2] = (v) >> 16,\
132			 ((u_int8_t *)(p))[3] = (v) >> 24)
133#endif
134
135/*
136 * BIOS Parameter Block (BPB) for DOS 3.3
137 */
138struct byte_bpb33 {
139	int8_t bpbBytesPerSec[2];	/* bytes per sector */
140	int8_t bpbSecPerClust;		/* sectors per cluster */
141	int8_t bpbResSectors[2];	/* number of reserved sectors */
142	int8_t bpbFATs;			/* number of FATs */
143	int8_t bpbRootDirEnts[2];	/* number of root directory entries */
144	int8_t bpbSectors[2];		/* total number of sectors */
145	int8_t bpbMedia;		/* media descriptor */
146	int8_t bpbFATsecs[2];		/* number of sectors per FAT */
147	int8_t bpbSecPerTrack[2];	/* sectors per track */
148	int8_t bpbHeads[2];		/* number of heads */
149	int8_t bpbHiddenSecs[2];	/* number of hidden sectors */
150};
151
152/*
153 * BPB for DOS 5.0 The difference is bpbHiddenSecs is a short for DOS 3.3,
154 * and bpbHugeSectors is not in the 3.3 bpb.
155 */
156struct byte_bpb50 {
157	int8_t bpbBytesPerSec[2];	/* bytes per sector */
158	int8_t bpbSecPerClust;		/* sectors per cluster */
159	int8_t bpbResSectors[2];	/* number of reserved sectors */
160	int8_t bpbFATs;			/* number of FATs */
161	int8_t bpbRootDirEnts[2];	/* number of root directory entries */
162	int8_t bpbSectors[2];		/* total number of sectors */
163	int8_t bpbMedia;		/* media descriptor */
164	int8_t bpbFATsecs[2];		/* number of sectors per FAT */
165	int8_t bpbSecPerTrack[2];	/* sectors per track */
166	int8_t bpbHeads[2];		/* number of heads */
167	int8_t bpbHiddenSecs[4];	/* number of hidden sectors */
168	int8_t bpbHugeSectors[4];	/* # of sectors if bpbSectors == 0 */
169};
170
171/*
172 * BPB for DOS 7.10 (FAT32).  This one has a few extensions to bpb50.
173 */
174struct byte_bpb710 {
175	u_int8_t bpbBytesPerSec[2];	/* bytes per sector */
176	u_int8_t bpbSecPerClust;	/* sectors per cluster */
177	u_int8_t bpbResSectors[2];	/* number of reserved sectors */
178	u_int8_t bpbFATs;		/* number of FATs */
179	u_int8_t bpbRootDirEnts[2];	/* number of root directory entries */
180	u_int8_t bpbSectors[2];		/* total number of sectors */
181	u_int8_t bpbMedia;		/* media descriptor */
182	u_int8_t bpbFATsecs[2];		/* number of sectors per FAT */
183	u_int8_t bpbSecPerTrack[2];	/* sectors per track */
184	u_int8_t bpbHeads[2];		/* number of heads */
185	u_int8_t bpbHiddenSecs[4];	/* # of hidden sectors */
186	u_int8_t bpbHugeSectors[4];	/* # of sectors if bpbSectors == 0 */
187	u_int8_t bpbBigFATsecs[4];	/* like bpbFATsecs for FAT32 */
188	u_int8_t bpbExtFlags[2];	/* extended flags: */
189	u_int8_t bpbFSVers[2];		/* filesystem version */
190	u_int8_t bpbRootClust[4];	/* start cluster for root directory */
191	u_int8_t bpbFSInfo[2];		/* filesystem info structure sector */
192	u_int8_t bpbBackup[2];		/* backup boot sector */
193	/* There is a 12 byte filler here, but we ignore it */
194};
195
196/*
197 * FAT32 FSInfo block.
198 */
199struct fsinfo {
200	u_int8_t fsisig1[4];
201	u_int8_t fsifill1[480];
202	u_int8_t fsisig2[4];
203	u_int8_t fsinfree[4];
204	u_int8_t fsinxtfree[4];
205	u_int8_t fsifill2[12];
206	u_int8_t fsisig3[4];
207	u_int8_t fsifill3[508];
208	u_int8_t fsisig4[4];
209};
210