1 1.8 dholland /* $NetBSD: bpb.h,v 1.8 2016/01/22 22:53:36 dholland 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.4 christos #ifndef _MSDOSFS_BPB_H_ 20 1.4 christos #define _MSDOSFS_BPB_H_ 21 1.4 christos 22 1.1 jdolecek /* 23 1.1 jdolecek * BIOS Parameter Block (BPB) for DOS 3.3 24 1.1 jdolecek */ 25 1.1 jdolecek struct bpb33 { 26 1.8 dholland uint16_t bpbBytesPerSec; /* bytes per sector */ 27 1.8 dholland uint8_t bpbSecPerClust; /* sectors per cluster */ 28 1.8 dholland uint16_t bpbResSectors; /* number of reserved sectors */ 29 1.8 dholland uint8_t bpbFATs; /* number of FATs */ 30 1.8 dholland uint16_t bpbRootDirEnts; /* number of root directory entries */ 31 1.8 dholland uint16_t bpbSectors; /* total number of sectors */ 32 1.8 dholland uint8_t bpbMedia; /* media descriptor */ 33 1.8 dholland uint16_t bpbFATsecs; /* number of sectors per FAT */ 34 1.8 dholland uint16_t bpbSecPerTrack; /* sectors per track */ 35 1.8 dholland uint16_t bpbHeads; /* number of heads */ 36 1.8 dholland uint16_t bpbHiddenSecs; /* number of hidden sectors */ 37 1.1 jdolecek }; 38 1.1 jdolecek 39 1.1 jdolecek /* 40 1.1 jdolecek * BPB for DOS 5.0 The difference is bpbHiddenSecs is a short for DOS 3.3, 41 1.1 jdolecek * and bpbHugeSectors is not in the 3.3 bpb. 42 1.1 jdolecek */ 43 1.1 jdolecek struct bpb50 { 44 1.8 dholland uint16_t bpbBytesPerSec; /* bytes per sector */ 45 1.8 dholland uint8_t bpbSecPerClust; /* sectors per cluster */ 46 1.8 dholland uint16_t bpbResSectors; /* number of reserved sectors */ 47 1.8 dholland uint8_t bpbFATs; /* number of FATs */ 48 1.8 dholland uint16_t bpbRootDirEnts; /* number of root directory entries */ 49 1.8 dholland uint16_t bpbSectors; /* total number of sectors */ 50 1.8 dholland uint8_t bpbMedia; /* media descriptor */ 51 1.8 dholland uint16_t bpbFATsecs; /* number of sectors per FAT */ 52 1.8 dholland uint16_t bpbSecPerTrack; /* sectors per track */ 53 1.8 dholland uint16_t bpbHeads; /* number of heads */ 54 1.8 dholland uint32_t bpbHiddenSecs; /* # of hidden sectors */ 55 1.8 dholland uint32_t bpbHugeSectors; /* # of sectors if bpbSectors == 0 */ 56 1.1 jdolecek }; 57 1.1 jdolecek 58 1.1 jdolecek /* 59 1.1 jdolecek * BPB for DOS 7.10 (FAT32). This one has a few extensions to bpb50. 60 1.1 jdolecek */ 61 1.1 jdolecek struct bpb710 { 62 1.8 dholland uint16_t bpbBytesPerSec; /* bytes per sector */ 63 1.8 dholland uint8_t bpbSecPerClust; /* sectors per cluster */ 64 1.8 dholland uint16_t bpbResSectors; /* number of reserved sectors */ 65 1.8 dholland uint8_t bpbFATs; /* number of FATs */ 66 1.8 dholland uint16_t bpbRootDirEnts; /* number of root directory entries */ 67 1.8 dholland uint16_t bpbSectors; /* total number of sectors */ 68 1.8 dholland uint8_t bpbMedia; /* media descriptor */ 69 1.8 dholland uint16_t bpbFATsecs; /* number of sectors per FAT */ 70 1.8 dholland uint16_t bpbSecPerTrack; /* sectors per track */ 71 1.8 dholland uint16_t bpbHeads; /* number of heads */ 72 1.8 dholland uint32_t bpbHiddenSecs; /* # of hidden sectors */ 73 1.8 dholland uint32_t bpbHugeSectors; /* # of sectors if bpbSectors == 0 */ 74 1.8 dholland uint32_t bpbBigFATsecs; /* like bpbFATsecs for FAT32 */ 75 1.8 dholland uint16_t bpbExtFlags; /* extended flags: */ 76 1.1 jdolecek #define FATNUM 0xf /* mask for numbering active FAT */ 77 1.1 jdolecek #define FATMIRROR 0x80 /* FAT is mirrored (like it always was) */ 78 1.8 dholland uint16_t bpbFSVers; /* filesystem version */ 79 1.1 jdolecek #define FSVERS 0 /* currently only 0 is understood */ 80 1.8 dholland uint32_t bpbRootClust; /* start cluster for root directory */ 81 1.8 dholland uint16_t bpbFSInfo; /* filesystem info structure sector */ 82 1.8 dholland uint16_t bpbBackup; /* backup boot sector */ 83 1.8 dholland uint8_t bpbReserved[12]; /* Reserved for future expansion */ 84 1.1 jdolecek }; 85 1.1 jdolecek 86 1.1 jdolecek #ifdef atari 87 1.1 jdolecek /* 88 1.7 jakllsch * BPB for GEMDOS filesystems. Atari leaves the obsolete stuff undefined. 89 1.1 jdolecek * Currently there is no need for a separate BPB structure. 90 1.1 jdolecek */ 91 1.1 jdolecek #if 0 92 1.1 jdolecek struct bpb_a { 93 1.8 dholland uint16_t bpbBytesPerSec; /* bytes per sector */ 94 1.8 dholland uint8_t bpbSecPerClust; /* sectors per cluster */ 95 1.8 dholland uint16_t bpbResSectors; /* number of reserved sectors */ 96 1.8 dholland uint8_t bpbFATs; /* number of FATs */ 97 1.8 dholland uint16_t bpbRootDirEnts; /* number of root directory entries */ 98 1.8 dholland uint16_t bpbSectors; /* total number of sectors */ 99 1.8 dholland uint8_t bpbUseless1; /* meaningless on GEMDOS FS */ 100 1.8 dholland uint16_t bpbFATsecs; /* number of sectors per FAT */ 101 1.8 dholland uint16_t bpbUseless2; /* meaningless for harddisk fs */ 102 1.8 dholland uint16_t bpbUseless3; /* meaningless for harddisk fs */ 103 1.8 dholland uint16_t bpbHiddenSecs; /* the TOS-BIOS ignores this */ 104 1.1 jdolecek }; 105 1.1 jdolecek #endif 106 1.1 jdolecek #endif /* atari */ 107 1.1 jdolecek 108 1.1 jdolecek /* 109 1.1 jdolecek * The following structures represent how the bpb's look on disk. shorts 110 1.1 jdolecek * and longs are just character arrays of the appropriate length. This is 111 1.1 jdolecek * because the compiler forces shorts and longs to align on word or 112 1.1 jdolecek * halfword boundaries. 113 1.6 cbiere */ 114 1.6 cbiere 115 1.6 cbiere #include <sys/endian.h> 116 1.6 cbiere 117 1.6 cbiere #define getushort(p) le16dec(p) 118 1.6 cbiere #define getulong(p) le32dec(p) 119 1.6 cbiere #define putushort(p, v) le16enc((p), (v)) 120 1.6 cbiere #define putulong(p, v) le32enc((p), (v)) 121 1.1 jdolecek 122 1.1 jdolecek /* 123 1.1 jdolecek * BIOS Parameter Block (BPB) for DOS 3.3 124 1.1 jdolecek */ 125 1.1 jdolecek struct byte_bpb33 { 126 1.1 jdolecek int8_t bpbBytesPerSec[2]; /* bytes per sector */ 127 1.1 jdolecek int8_t bpbSecPerClust; /* sectors per cluster */ 128 1.1 jdolecek int8_t bpbResSectors[2]; /* number of reserved sectors */ 129 1.1 jdolecek int8_t bpbFATs; /* number of FATs */ 130 1.1 jdolecek int8_t bpbRootDirEnts[2]; /* number of root directory entries */ 131 1.1 jdolecek int8_t bpbSectors[2]; /* total number of sectors */ 132 1.1 jdolecek int8_t bpbMedia; /* media descriptor */ 133 1.1 jdolecek int8_t bpbFATsecs[2]; /* number of sectors per FAT */ 134 1.1 jdolecek int8_t bpbSecPerTrack[2]; /* sectors per track */ 135 1.1 jdolecek int8_t bpbHeads[2]; /* number of heads */ 136 1.1 jdolecek int8_t bpbHiddenSecs[2]; /* number of hidden sectors */ 137 1.1 jdolecek }; 138 1.1 jdolecek 139 1.1 jdolecek /* 140 1.1 jdolecek * BPB for DOS 5.0 The difference is bpbHiddenSecs is a short for DOS 3.3, 141 1.1 jdolecek * and bpbHugeSectors is not in the 3.3 bpb. 142 1.1 jdolecek */ 143 1.1 jdolecek struct byte_bpb50 { 144 1.1 jdolecek int8_t bpbBytesPerSec[2]; /* bytes per sector */ 145 1.1 jdolecek int8_t bpbSecPerClust; /* sectors per cluster */ 146 1.1 jdolecek int8_t bpbResSectors[2]; /* number of reserved sectors */ 147 1.1 jdolecek int8_t bpbFATs; /* number of FATs */ 148 1.1 jdolecek int8_t bpbRootDirEnts[2]; /* number of root directory entries */ 149 1.1 jdolecek int8_t bpbSectors[2]; /* total number of sectors */ 150 1.1 jdolecek int8_t bpbMedia; /* media descriptor */ 151 1.1 jdolecek int8_t bpbFATsecs[2]; /* number of sectors per FAT */ 152 1.1 jdolecek int8_t bpbSecPerTrack[2]; /* sectors per track */ 153 1.1 jdolecek int8_t bpbHeads[2]; /* number of heads */ 154 1.1 jdolecek int8_t bpbHiddenSecs[4]; /* number of hidden sectors */ 155 1.1 jdolecek int8_t bpbHugeSectors[4]; /* # of sectors if bpbSectors == 0 */ 156 1.1 jdolecek }; 157 1.1 jdolecek 158 1.1 jdolecek /* 159 1.1 jdolecek * BPB for DOS 7.10 (FAT32). This one has a few extensions to bpb50. 160 1.1 jdolecek */ 161 1.1 jdolecek struct byte_bpb710 { 162 1.8 dholland uint8_t bpbBytesPerSec[2]; /* bytes per sector */ 163 1.8 dholland uint8_t bpbSecPerClust; /* sectors per cluster */ 164 1.8 dholland uint8_t bpbResSectors[2]; /* number of reserved sectors */ 165 1.8 dholland uint8_t bpbFATs; /* number of FATs */ 166 1.8 dholland uint8_t bpbRootDirEnts[2]; /* number of root directory entries */ 167 1.8 dholland uint8_t bpbSectors[2]; /* total number of sectors */ 168 1.8 dholland uint8_t bpbMedia; /* media descriptor */ 169 1.8 dholland uint8_t bpbFATsecs[2]; /* number of sectors per FAT */ 170 1.8 dholland uint8_t bpbSecPerTrack[2]; /* sectors per track */ 171 1.8 dholland uint8_t bpbHeads[2]; /* number of heads */ 172 1.8 dholland uint8_t bpbHiddenSecs[4]; /* # of hidden sectors */ 173 1.8 dholland uint8_t bpbHugeSectors[4]; /* # of sectors if bpbSectors == 0 */ 174 1.8 dholland uint8_t bpbBigFATsecs[4]; /* like bpbFATsecs for FAT32 */ 175 1.8 dholland uint8_t bpbExtFlags[2]; /* extended flags: */ 176 1.8 dholland uint8_t bpbFSVers[2]; /* filesystem version */ 177 1.8 dholland uint8_t bpbRootClust[4]; /* start cluster for root directory */ 178 1.8 dholland uint8_t bpbFSInfo[2]; /* filesystem info structure sector */ 179 1.8 dholland uint8_t bpbBackup[2]; /* backup boot sector */ 180 1.8 dholland uint8_t bpbReserved[12]; /* Reserved for future expansion */ 181 1.1 jdolecek }; 182 1.1 jdolecek 183 1.1 jdolecek /* 184 1.1 jdolecek * FAT32 FSInfo block. 185 1.1 jdolecek */ 186 1.1 jdolecek struct fsinfo { 187 1.8 dholland uint8_t fsisig1[4]; 188 1.8 dholland uint8_t fsifill1[480]; 189 1.8 dholland uint8_t fsisig2[4]; 190 1.8 dholland uint8_t fsinfree[4]; 191 1.8 dholland uint8_t fsinxtfree[4]; 192 1.8 dholland uint8_t fsifill2[12]; 193 1.8 dholland uint8_t fsisig3[4]; 194 1.8 dholland uint8_t fsifill3[508]; 195 1.8 dholland uint8_t fsisig4[4]; 196 1.1 jdolecek }; 197 1.4 christos #endif /* _MSDOSFS_BPB_H_ */ 198