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