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