1952a6212SJordan K. Hubbard /* $NetBSD: bpb.h,v 1.7 1997/11/17 15:36:24 ws Exp $ */ 227a0bc89SDoug Rabson 3d167cf6fSWarner Losh /*- 427a0bc89SDoug Rabson * Written by Paul Popelka (paulp@uts.amdahl.com) 527a0bc89SDoug Rabson * 627a0bc89SDoug Rabson * You can do anything you want with this software, just don't say you wrote 727a0bc89SDoug Rabson * it, and don't remove this notice. 827a0bc89SDoug Rabson * 927a0bc89SDoug Rabson * This software is provided "as is". 1027a0bc89SDoug Rabson * 1127a0bc89SDoug Rabson * The author supplies this software to be publicly redistributed on the 1227a0bc89SDoug Rabson * understanding that the author is not responsible for the correct 1327a0bc89SDoug Rabson * functioning of this software in any circumstances and is not liable for 1427a0bc89SDoug Rabson * any damages caused by this software. 1527a0bc89SDoug Rabson * 1627a0bc89SDoug Rabson * October 1992 1727a0bc89SDoug Rabson */ 1827a0bc89SDoug Rabson 1948d1bcf8SKonstantin Belousov #ifndef _FS_MSDOSFS_BPB_H_ 2048d1bcf8SKonstantin Belousov #define _FS_MSDOSFS_BPB_H_ 2148d1bcf8SKonstantin Belousov 2227a0bc89SDoug Rabson /* 2327a0bc89SDoug Rabson * BIOS Parameter Block (BPB) for DOS 3.3 2427a0bc89SDoug Rabson */ 2527a0bc89SDoug Rabson struct bpb33 { 26*23c53312SEd Maste uint16_t bpbBytesPerSec; /* bytes per sector */ 27*23c53312SEd Maste uint8_t bpbSecPerClust; /* sectors per cluster */ 28*23c53312SEd Maste uint16_t bpbResSectors; /* number of reserved sectors */ 29*23c53312SEd Maste uint8_t bpbFATs; /* number of FATs */ 30*23c53312SEd Maste uint16_t bpbRootDirEnts; /* number of root directory entries */ 31*23c53312SEd Maste uint16_t bpbSectors; /* total number of sectors */ 32*23c53312SEd Maste uint8_t bpbMedia; /* media descriptor */ 33*23c53312SEd Maste uint16_t bpbFATsecs; /* number of sectors per FAT */ 34*23c53312SEd Maste uint16_t bpbSecPerTrack; /* sectors per track */ 35*23c53312SEd Maste uint16_t bpbHeads; /* number of heads */ 36*23c53312SEd Maste uint16_t bpbHiddenSecs; /* number of hidden sectors */ 3727a0bc89SDoug Rabson }; 3827a0bc89SDoug Rabson 3927a0bc89SDoug Rabson /* 4027a0bc89SDoug Rabson * BPB for DOS 5.0 The difference is bpbHiddenSecs is a short for DOS 3.3, 4127a0bc89SDoug Rabson * and bpbHugeSectors is not in the 3.3 bpb. 4227a0bc89SDoug Rabson */ 4327a0bc89SDoug Rabson struct bpb50 { 44*23c53312SEd Maste uint16_t bpbBytesPerSec; /* bytes per sector */ 45*23c53312SEd Maste uint8_t bpbSecPerClust; /* sectors per cluster */ 46*23c53312SEd Maste uint16_t bpbResSectors; /* number of reserved sectors */ 47*23c53312SEd Maste uint8_t bpbFATs; /* number of FATs */ 48*23c53312SEd Maste uint16_t bpbRootDirEnts; /* number of root directory entries */ 49*23c53312SEd Maste uint16_t bpbSectors; /* total number of sectors */ 50*23c53312SEd Maste uint8_t bpbMedia; /* media descriptor */ 51*23c53312SEd Maste uint16_t bpbFATsecs; /* number of sectors per FAT */ 52*23c53312SEd Maste uint16_t bpbSecPerTrack; /* sectors per track */ 53*23c53312SEd Maste uint16_t bpbHeads; /* number of heads */ 54*23c53312SEd Maste uint32_t bpbHiddenSecs; /* # of hidden sectors */ 55*23c53312SEd Maste uint32_t bpbHugeSectors; /* # of sectors if bpbSectors == 0 */ 5627a0bc89SDoug Rabson }; 5727a0bc89SDoug Rabson 5827a0bc89SDoug Rabson /* 59952a6212SJordan K. Hubbard * BPB for DOS 7.10 (FAT32). This one has a few extensions to bpb50. 60952a6212SJordan K. Hubbard */ 61952a6212SJordan K. Hubbard struct bpb710 { 62*23c53312SEd Maste uint16_t bpbBytesPerSec; /* bytes per sector */ 63*23c53312SEd Maste uint8_t bpbSecPerClust; /* sectors per cluster */ 64*23c53312SEd Maste uint16_t bpbResSectors; /* number of reserved sectors */ 65*23c53312SEd Maste uint8_t bpbFATs; /* number of FATs */ 66*23c53312SEd Maste uint16_t bpbRootDirEnts; /* number of root directory entries */ 67*23c53312SEd Maste uint16_t bpbSectors; /* total number of sectors */ 68*23c53312SEd Maste uint8_t bpbMedia; /* media descriptor */ 69*23c53312SEd Maste uint16_t bpbFATsecs; /* number of sectors per FAT */ 70*23c53312SEd Maste uint16_t bpbSecPerTrack; /* sectors per track */ 71*23c53312SEd Maste uint16_t bpbHeads; /* number of heads */ 72*23c53312SEd Maste uint32_t bpbHiddenSecs; /* # of hidden sectors */ 73*23c53312SEd Maste uint32_t bpbHugeSectors; /* # of sectors if bpbSectors == 0 */ 74*23c53312SEd Maste uint32_t bpbBigFATsecs; /* like bpbFATsecs for FAT32 */ 75*23c53312SEd Maste uint16_t bpbExtFlags; /* extended flags: */ 76952a6212SJordan K. Hubbard #define FATNUM 0xf /* mask for numbering active FAT */ 77952a6212SJordan K. Hubbard #define FATMIRROR 0x80 /* FAT is mirrored (like it always was) */ 78*23c53312SEd Maste uint16_t bpbFSVers; /* filesystem version */ 79952a6212SJordan K. Hubbard #define FSVERS 0 /* currently only 0 is understood */ 80*23c53312SEd Maste uint32_t bpbRootClust; /* start cluster for root directory */ 81*23c53312SEd Maste uint16_t bpbFSInfo; /* filesystem info structure sector */ 82*23c53312SEd Maste uint16_t bpbBackup; /* backup boot sector */ 83*23c53312SEd Maste uint8_t bpbReserved[12]; /* reserved for future expansion */ 84952a6212SJordan K. Hubbard }; 85952a6212SJordan K. Hubbard 86952a6212SJordan K. Hubbard /* 8727a0bc89SDoug Rabson * The following structures represent how the bpb's look on disk. shorts 8827a0bc89SDoug Rabson * and longs are just character arrays of the appropriate length. This is 8927a0bc89SDoug Rabson * because the compiler forces shorts and longs to align on word or 9027a0bc89SDoug Rabson * halfword boundaries. 9127a0bc89SDoug Rabson */ 92ff4ad0c4SBruce Evans 9394632b9fSMarcel Moolenaar #include <sys/endian.h> 94ff4ad0c4SBruce Evans 9594632b9fSMarcel Moolenaar #define getushort(x) le16dec(x) 9694632b9fSMarcel Moolenaar #define getulong(x) le32dec(x) 9794632b9fSMarcel Moolenaar #define putushort(p, v) le16enc(p, v) 9894632b9fSMarcel Moolenaar #define putulong(p, v) le32enc(p, v) 9927a0bc89SDoug Rabson 10027a0bc89SDoug Rabson /* 10127a0bc89SDoug Rabson * BIOS Parameter Block (BPB) for DOS 3.3 10227a0bc89SDoug Rabson */ 10327a0bc89SDoug Rabson struct byte_bpb33 { 104952a6212SJordan K. Hubbard int8_t bpbBytesPerSec[2]; /* bytes per sector */ 105952a6212SJordan K. Hubbard int8_t bpbSecPerClust; /* sectors per cluster */ 106952a6212SJordan K. Hubbard int8_t bpbResSectors[2]; /* number of reserved sectors */ 107952a6212SJordan K. Hubbard int8_t bpbFATs; /* number of FATs */ 108952a6212SJordan K. Hubbard int8_t bpbRootDirEnts[2]; /* number of root directory entries */ 109952a6212SJordan K. Hubbard int8_t bpbSectors[2]; /* total number of sectors */ 110952a6212SJordan K. Hubbard int8_t bpbMedia; /* media descriptor */ 111952a6212SJordan K. Hubbard int8_t bpbFATsecs[2]; /* number of sectors per FAT */ 112952a6212SJordan K. Hubbard int8_t bpbSecPerTrack[2]; /* sectors per track */ 113952a6212SJordan K. Hubbard int8_t bpbHeads[2]; /* number of heads */ 114952a6212SJordan K. Hubbard int8_t bpbHiddenSecs[2]; /* number of hidden sectors */ 11527a0bc89SDoug Rabson }; 11627a0bc89SDoug Rabson 11727a0bc89SDoug Rabson /* 11827a0bc89SDoug Rabson * BPB for DOS 5.0 The difference is bpbHiddenSecs is a short for DOS 3.3, 11927a0bc89SDoug Rabson * and bpbHugeSectors is not in the 3.3 bpb. 12027a0bc89SDoug Rabson */ 12127a0bc89SDoug Rabson struct byte_bpb50 { 122952a6212SJordan K. Hubbard int8_t bpbBytesPerSec[2]; /* bytes per sector */ 123952a6212SJordan K. Hubbard int8_t bpbSecPerClust; /* sectors per cluster */ 124952a6212SJordan K. Hubbard int8_t bpbResSectors[2]; /* number of reserved sectors */ 125952a6212SJordan K. Hubbard int8_t bpbFATs; /* number of FATs */ 126952a6212SJordan K. Hubbard int8_t bpbRootDirEnts[2]; /* number of root directory entries */ 127952a6212SJordan K. Hubbard int8_t bpbSectors[2]; /* total number of sectors */ 128952a6212SJordan K. Hubbard int8_t bpbMedia; /* media descriptor */ 129952a6212SJordan K. Hubbard int8_t bpbFATsecs[2]; /* number of sectors per FAT */ 130952a6212SJordan K. Hubbard int8_t bpbSecPerTrack[2]; /* sectors per track */ 131952a6212SJordan K. Hubbard int8_t bpbHeads[2]; /* number of heads */ 132952a6212SJordan K. Hubbard int8_t bpbHiddenSecs[4]; /* number of hidden sectors */ 133952a6212SJordan K. Hubbard int8_t bpbHugeSectors[4]; /* # of sectors if bpbSectors == 0 */ 134952a6212SJordan K. Hubbard }; 135952a6212SJordan K. Hubbard 136952a6212SJordan K. Hubbard /* 137952a6212SJordan K. Hubbard * BPB for DOS 7.10 (FAT32). This one has a few extensions to bpb50. 138952a6212SJordan K. Hubbard */ 139952a6212SJordan K. Hubbard struct byte_bpb710 { 140*23c53312SEd Maste uint8_t bpbBytesPerSec[2]; /* bytes per sector */ 141*23c53312SEd Maste uint8_t bpbSecPerClust; /* sectors per cluster */ 142*23c53312SEd Maste uint8_t bpbResSectors[2]; /* number of reserved sectors */ 143*23c53312SEd Maste uint8_t bpbFATs; /* number of FATs */ 144*23c53312SEd Maste uint8_t bpbRootDirEnts[2]; /* number of root directory entries */ 145*23c53312SEd Maste uint8_t bpbSectors[2]; /* total number of sectors */ 146*23c53312SEd Maste uint8_t bpbMedia; /* media descriptor */ 147*23c53312SEd Maste uint8_t bpbFATsecs[2]; /* number of sectors per FAT */ 148*23c53312SEd Maste uint8_t bpbSecPerTrack[2]; /* sectors per track */ 149*23c53312SEd Maste uint8_t bpbHeads[2]; /* number of heads */ 150*23c53312SEd Maste uint8_t bpbHiddenSecs[4]; /* # of hidden sectors */ 151*23c53312SEd Maste uint8_t bpbHugeSectors[4]; /* # of sectors if bpbSectors == 0 */ 152*23c53312SEd Maste uint8_t bpbBigFATsecs[4]; /* like bpbFATsecs for FAT32 */ 153*23c53312SEd Maste uint8_t bpbExtFlags[2]; /* extended flags: */ 154*23c53312SEd Maste uint8_t bpbFSVers[2]; /* filesystem version */ 155*23c53312SEd Maste uint8_t bpbRootClust[4]; /* start cluster for root directory */ 156*23c53312SEd Maste uint8_t bpbFSInfo[2]; /* filesystem info structure sector */ 157*23c53312SEd Maste uint8_t bpbBackup[2]; /* backup boot sector */ 158*23c53312SEd Maste uint8_t bpbReserved[12]; /* reserved for future expansion */ 159952a6212SJordan K. Hubbard }; 160952a6212SJordan K. Hubbard 161952a6212SJordan K. Hubbard /* 162952a6212SJordan K. Hubbard * FAT32 FSInfo block. 163952a6212SJordan K. Hubbard */ 164952a6212SJordan K. Hubbard struct fsinfo { 165*23c53312SEd Maste uint8_t fsisig1[4]; 166*23c53312SEd Maste uint8_t fsifill1[480]; 167*23c53312SEd Maste uint8_t fsisig2[4]; 168*23c53312SEd Maste uint8_t fsinfree[4]; 169*23c53312SEd Maste uint8_t fsinxtfree[4]; 170*23c53312SEd Maste uint8_t fsifill2[12]; 171*23c53312SEd Maste uint8_t fsisig3[4]; 17227a0bc89SDoug Rabson }; 17348d1bcf8SKonstantin Belousov #endif /* !_FS_MSDOSFS_BPB_H_ */ 174