Changeset 66578 in vbox
- Timestamp:
- Apr 14, 2017 3:13:03 PM (7 years ago)
- File:
-
- 1 edited
-
trunk/include/iprt/formats/fat.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/formats/fat.h
r66575 r66578 39 39 #define FATBPB_MEDIA_FLOPPY_5_DOT_25 UINT8_C(0xed) 40 40 #define FATBPB_MEDIA_FLOPPY_3_DOT_5 UINT8_C(0xf0) 41 /* incomplete, figure out as needed... */ 41 42 /** @} */ 42 43 43 typedef struct FATBPB 44 /** 45 * The DOS 2.0 BIOS parameter block (BPB). 46 * 47 * This was the first DOS version with a BPB. 48 */ 49 typedef struct FATBPB20 44 50 { 45 51 /** 0x0b / 0x00: The sector size in bytes. */ … … 54 60 uint16_t cMaxRootDirEntries; 55 61 /** 0x13 / 0x08: Total sector count, zero if 32-bit count is used. */ 56 uint16_t cOldTotalSectors; 57 /** 0x15 / 0x0a: Total sector count, zero if 32-bit count is used. */ 58 uint16_t bMedia; 59 } FATBPB; 60 62 uint16_t cTotalSectors16; 63 /** 0x15 / 0x0a: Media ID. */ 64 uint8_t bMedia; 65 /** 0x16 / 0x0b: Number of sectors per FAT (0 for FAT32). */ 66 uint16_t cSectorsPerFat; 67 } FATBPB20; 68 AssertCompileSize(FATBPB20, 0xd); 69 /** Pointer to a DOS 2.0 BPB. */ 70 typedef FATBPB20 *PFATBPB20; 71 /** Pointer to a const DOS 2.0 BPB. */ 72 typedef FATBPB20 const *PCFATBPB20; 73 74 75 /** 76 * The DOS 3.0 BPB changes that survived. 77 */ 78 typedef struct FATBPB30CMN 79 { 80 /** DOS v2.0 BPB. */ 81 FATBPB20 Bpb20; 82 /** 0x18 / 0x0d: Sectors per track. Zero means reserved and not used. */ 83 uint16_t cSectorsPerTrack; 84 /** 0x1a / 0x0f: Number of heads. Zero means reserved and not used. */ 85 uint16_t cTracksPerCylinder; 86 } FATBPB30CMN; 87 AssertCompileSize(FATBPB30CMN, 0x11); 88 89 /** 90 * The DOS 3.0 BPB. 91 */ 92 typedef struct FATBPB30 93 { 94 /** DOS v3.0 BPB bits that survived. */ 95 FATBPB30CMN Core30; 96 /** 0x1c / 0x11: Number of hidden sectors preceeding the volume. This is zero 97 * on unpartitioned media. */ 98 uint16_t cHiddenSectors; 99 } FATBPB30; 100 AssertCompileSize(FATBPB30, 0x13); 101 /** Pointer to a DOS 3.0 BPB. */ 102 typedef FATBPB30 *PFATBPB30; 103 /** Pointer to a const DOS 3.0 BPB. */ 104 typedef FATBPB30 const *PCFATBPB30; 105 106 /** 107 * The DOS 3.0 BPB, flattened structure. 108 */ 109 typedef struct FATBPB30FLAT 110 { 111 /** @name New in DOS 2.0 112 * @{ */ 113 /** 0x0b / 0x00: The sector size in bytes. */ 114 uint16_t cbSector; 115 /** 0x0d / 0x02: Number of sectors per cluster. */ 116 uint8_t cSectorsPerCluster; 117 /** 0x0e / 0x03: Number of reserved sectors before the first FAT. */ 118 uint16_t cReservedSectors; 119 /** 0x10 / 0x05: Number of FATs. */ 120 uint8_t cFats; 121 /** 0x11 / 0x06: Max size of the root directory (0 for FAT32). */ 122 uint16_t cMaxRootDirEntries; 123 /** 0x13 / 0x08: Total sector count, zero if 32-bit count is used. */ 124 uint16_t cTotalSectors16; 125 /** 0x15 / 0x0a: Media ID. */ 126 uint8_t bMedia; 127 /** 0x16 / 0x0b: Number of sectors per FAT (0 for FAT32). */ 128 uint16_t cSectorsPerFat; 129 /** @} */ 130 /** @name New in DOS 3.0 131 * @{ */ 132 /** 0x18 / 0x0d: Sectors per track. Zero means reserved and not used. */ 133 uint16_t cSectorsPerTrack; 134 /** 0x1a / 0x0f: Number of heads. Zero means reserved and not used. */ 135 uint16_t cTracksPerCylinder; 136 /** 0x1c / 0x11: Number of hidden sectors preceeding the volume. This is zero 137 * on unpartitioned media. */ 138 uint16_t cHiddenSectors; 139 /** @} */ 140 } FATBPB30FLAT; 141 AssertCompileSize(FATBPB30FLAT, 0x13); 142 /** Pointer to a flattened DOS 3.0 BPB. */ 143 typedef FATBPB30FLAT *PFATBPB30FLAT; 144 /** Pointer to a const flattened DOS 3.0 BPB. */ 145 typedef FATBPB30FLAT const *PCFATBPB30FLAT; 146 147 148 /** 149 * The DOS 3.2 BPB. 150 */ 151 typedef struct FATBPB32 152 { 153 /** DOS v3.0 BPB. */ 154 FATBPB30 Bpb30; 155 /** 0x1e / 0x13: Number of sectors, including the hidden ones. This is ZERO 156 * in DOS 3.31+. */ 157 uint16_t cAnotherTotalSectors; 158 } FATBPB32; 159 AssertCompileSize(FATBPB32, 0x15); 160 /** Pointer to a DOS 3.2 BPB. */ 161 typedef FATBPB32 *PFATBPB32; 162 /** Pointer to const a DOS 3.2 BPB. */ 163 typedef FATBPB32 const *PCFATBPB32; 164 165 /** 166 * The DOS 3.2 BPB, flattened structure. 167 */ 168 typedef struct FATBPB32FLAT 169 { 170 /** @name New in DOS 2.0 171 * @{ */ 172 /** 0x0b / 0x00: The sector size in bytes. */ 173 uint16_t cbSector; 174 /** 0x0d / 0x02: Number of sectors per cluster. */ 175 uint8_t cSectorsPerCluster; 176 /** 0x0e / 0x03: Number of reserved sectors before the first FAT. */ 177 uint16_t cReservedSectors; 178 /** 0x10 / 0x05: Number of FATs. */ 179 uint8_t cFats; 180 /** 0x11 / 0x06: Max size of the root directory (0 for FAT32). */ 181 uint16_t cMaxRootDirEntries; 182 /** 0x13 / 0x08: Total sector count, zero if 32-bit count is used. */ 183 uint16_t cTotalSectors16; 184 /** 0x15 / 0x0a: Media ID. */ 185 uint8_t bMedia; 186 /** 0x16 / 0x0b: Number of sectors per FAT (0 for FAT32). */ 187 uint16_t cSectorsPerFat; 188 /** @} */ 189 /** @name New in DOS 3.0 190 * @{ */ 191 /** 0x18 / 0x0d: Sectors per track. Zero means reserved and not used. */ 192 uint16_t cSectorsPerTrack; 193 /** 0x1a / 0x0f: Number of heads. Zero means reserved and not used. */ 194 uint16_t cTracksPerCylinder; 195 /** 0x1c / 0x11: Number of hidden sectors preceeding the volume. This is zero 196 * on unpartitioned media. */ 197 uint16_t cHiddenSectors; 198 /** @} */ 199 /** @name New in DOS 3.2 200 * @{ */ 201 /** 0x1e / 0x13: Number of sectors, including the hidden ones. This is ZERO 202 * in DOS 3.31+. */ 203 uint16_t cAnotherTotalSectors; 204 /** @} */ 205 } FATBPB32FLAT; 206 AssertCompileSize(FATBPB32FLAT, 0x15); 207 /** Pointer to a flattened DOS 3.2 BPB. */ 208 typedef FATBPB32FLAT *PFATBPB32FLAT; 209 /** Pointer to a const flattened DOS 3.2 BPB. */ 210 typedef FATBPB32FLAT const *PCFATBPB32FLAT; 211 212 213 /** 214 * The DOS 3.31 BPB. 215 */ 216 typedef struct FATBPB331 217 { 218 /** DOS v3.0 BPB bits that survived. */ 219 FATBPB30CMN Core30; 220 /** 0x1c / 0x11: Number of hidden sectors preceeding the volume. This is zero 221 * on unpartitioned media. Values higher than 65535 are complicated due to 222 * the field overlapping FATBPB32::cAnotherTotalSectors */ 223 uint32_t cHiddenSectors; 224 /** 0x20 / 0x15: Total logical sectors. Used if count >= 64K, otherwise 225 * FATBPB20::cTotalSectors16 is used. Zero if 64-bit value used with FAT32. */ 226 uint32_t cTotalSectors32; 227 } FATBPB331; 228 AssertCompileSize(FATBPB331, 0x19); 229 /** Pointer to a DOS 3.31 BPB. */ 230 typedef FATBPB331 *PFATBPB331; 231 /** Pointer to a const DOS 3.31 BPB. */ 232 typedef FATBPB331 const *PCFATBPB331; 233 234 /** 235 * The DOS 3.31 BPB, flattened structure. 236 */ 237 typedef struct FATBPB331FLAT 238 { 239 /** @name New in DOS 2.0 240 * @{ */ 241 /** 0x0b / 0x00: The sector size in bytes. */ 242 uint16_t cbSector; 243 /** 0x0d / 0x02: Number of sectors per cluster. */ 244 uint8_t cSectorsPerCluster; 245 /** 0x0e / 0x03: Number of reserved sectors before the first FAT. */ 246 uint16_t cReservedSectors; 247 /** 0x10 / 0x05: Number of FATs. */ 248 uint8_t cFats; 249 /** 0x11 / 0x06: Max size of the root directory (0 for FAT32). */ 250 uint16_t cMaxRootDirEntries; 251 /** 0x13 / 0x08: Total sector count, zero if 32-bit count is used. */ 252 uint16_t cTotalSectors16; 253 /** 0x15 / 0x0a: Media ID. */ 254 uint8_t bMedia; 255 /** 0x16 / 0x0b: Number of sectors per FAT (0 for FAT32). */ 256 uint16_t cSectorsPerFat; 257 /** @} */ 258 /** @name New in DOS 3.0 259 * @{ */ 260 /** 0x18 / 0x0d: Sectors per track. Zero means reserved and not used. */ 261 uint16_t cSectorsPerTrack; 262 /** 0x1a / 0x0f: Number of heads. Zero means reserved and not used. */ 263 uint16_t cTracksPerCylinder; 264 /** @} */ 265 /** @name New in DOS 3.31 266 * @{ */ 267 /** 0x1c / 0x11: Number of hidden sectors preceeding the volume. This is zero 268 * on unpartitioned media. Values higher than 65535 are complicated due to 269 * the field overlapping FATBPB32::cAnotherTotalSectors */ 270 uint32_t cHiddenSectors; 271 /** 0x20 / 0x15: Total logical sectors. Used if count >= 64K, otherwise 272 * FATBPB20::cTotalSectors16 is used. Zero if 64-bit value used with FAT32. */ 273 uint32_t cTotalSectors32; 274 /** @} */ 275 } FATBPB331FLAT; 276 AssertCompileSize(FATBPB331FLAT, 0x19); 277 /** Pointer to a flattened DOS 3.31 BPB. */ 278 typedef FATBPB331FLAT *PFATBPB331FLAT; 279 /** Pointer to a const flattened DOS 3.31 BPB. */ 280 typedef FATBPB331FLAT *PFATBPB331FLAT; 281 282 283 /** 284 * Extended BIOS parameter block (EBPB). 285 */ 286 typedef struct FATEBPB 287 { 288 /** The BPB. */ 289 FATBPB331FLAT Bpb; 290 291 /** 0x24 / 0x19: BIOS INT13 pysical drive number. */ 292 uint8_t bInt13Drive; 293 /** 0x25 / 0x1a: Reserved. NT used bit 0 for indicating dirty FS, and bit 1 294 * for surface scan. */ 295 uint8_t bReserved; 296 /** 0x26 / 0x1b: Extended boot signature, FATEBPB_SIGNATURE or 297 * FATEBPB_SIGNATURE_OLD. */ 298 uint8_t bExtSignature; 299 /** 0x27 / 0x1c: The volume serial number. */ 300 uint32_t uSerialNumber; 301 /** 0x2b / 0x20: The volume label (space padded). 302 * @remarks Not available with FATEBPB_SIGNATURE_OLD */ 303 char achLabel[11]; 304 /** 0x36 / 0x2b: The file system type (space padded). 305 * @remarks Not available with FATEBPB_SIGNATURE_OLD */ 306 char achType[8]; 307 } FATEBPB; 308 AssertCompileSize(FATEBPB, 0x33); 309 /** Pointer to an extended BIOS parameter block. */ 310 typedef FATEBPB *PFATEBPB; 311 /** Pointer to a const extended BIOS parameter block. */ 312 typedef FATEBPB const *PCFATEBPB; 313 314 /** FATEBPB::bExtSignature value. */ 315 #define FATEBPB_SIGNATURE UINT8_C(0x29) 316 /** FATEBPB::bExtSignature value used by OS/2 1.0-1.1 and PC DOS 3.4. These 317 * does not have the volume and file system type. */ 318 #define FATEBPB_SIGNATURE_OLD UINT8_C(0x28) 319 320 /**FATEBPB::achType value for FAT12. */ 321 #define FATEBPB_TYPE_FAT12 "FAT12 " 322 /**FATEBPB::achType value for FAT16. */ 323 #define FATEBPB_TYPE_FAT16 "FAT16 " 324 /**FATEBPB::achType value for FAT12/FAT16. */ 325 #define FATEBPB_TYPE_FAT "FAT32 " 326 327 328 /** 329 * FAT32 Extended BIOS parameter block (EBPB). 330 */ 331 typedef struct FAT32EBPB 332 { 333 /** The BPB. */ 334 FATBPB331FLAT Bpb; 335 336 /** 0x24 / 0x19: Number of sectors per FAT. 337 * @note To avoid confusion with the FATEBPB signature, values which result in 338 * 0x00280000 or 0x00290000 when masked by 0x00ff0000 must not be used. */ 339 uint32_t cSectorsPerFat32; 340 /** 0x28 / 0x1d: Flags pertaining to FAT mirroring and other stuff. */ 341 uint16_t fFlags; 342 /** 0x2a / 0x1f: FAT32 version number (FAT32EBPB_VERSION_0_0). */ 343 uint16_t uVersion; 344 /** 0x2c / 0x21: Cluster number of the root directory. */ 345 uint32_t uRootDirCluster; 346 /** 0x30 / 0x25: Logical sector number of the information sector. */ 347 uint16_t uInfoSectorNo; 348 /** 0x32 / 0x27: Logical sector number of boot sector copy. */ 349 uint16_t uBootSectorCopySectorNo; 350 /** 0x34 / 0x29: Reserved, zero (or 0xf6) filled, preserve. */ 351 uint8_t abReserved[12]; 352 353 /** 0x40 / 0x35: BIOS INT13 pysical drive number 354 * @remarks Same as FATEBPB::bInt13Drive. */ 355 uint8_t bInt13Drive; 356 /** 0x41 / 0x36: Reserved. 357 * @remarks Same as FATEBPB::bReserved. */ 358 uint8_t bReserved; 359 /** 0x42 / 0x37: Extended boot signature (FATEBPB_SIGNATURE, or 360 * FATEBPB_SIGNATURE_OLD in some special cases). 361 * @remarks Same as FATEBPB::bExtSignature. */ 362 uint8_t bExtSignature; 363 /** 0x43 / 0x38: The volume serial number. 364 * @remarks Same as FATEBPB::uSerialNumber. */ 365 uint32_t uSerialNumber; 366 /** 0x47 / 0x3c: The volume label (space padded). 367 * @remarks Not available with FATEBPB_SIGNATURE_OLD 368 * @remarks Same as FATEBPB::achLabel. */ 369 char achLabel[11]; 370 /** 0x52 / 0x47: The file system type (space padded), or 64-bit logical sector 371 * count if both other count fields are zero. In the latter case, the type is 372 * moved to the OEM name field (FATBOOTSECTOR::achOemName). 373 * 374 * @remarks Not available with FATEBPB_SIGNATURE_OLD 375 * @remarks Same as FATEBPB::achType. */ 376 union 377 { 378 char achType[8]; 379 uint64_t cTotalSectors64; 380 } u; 381 } FAT32EBPB; 382 AssertCompileSize(FAT32EBPB, 0x4f); 383 /** Pointer to a FAT32 extended BIOS parameter block. */ 384 typedef FAT32EBPB *PFAT32EBPB; 385 /** Pointer to a const FAT32 extended BIOS parameter block. */ 386 typedef FAT32EBPB const *PCFAT32EBPB; 387 388 /** FAT32 version 0.0 (FAT32EBPB::uVersion). */ 389 #define FAT32EBPB_VERSION_0_0 UINT16_C(0x0000) 390 391 392 /** 393 * FAT boot sector layout. 394 */ 61 395 typedef struct FATBOOTSECTOR 62 396 { … … 69 403 union 70 404 { 71 405 FATBPB20 Bpb20; 406 FATBPB32FLAT Bpb30; 407 FATBPB32FLAT Bpb32; 408 FATBPB331FLAT Bpb331; 409 FATEBPB Ebpb; 410 FAT32EBPB Fat32Ebpb; 72 411 } Bpb; 412 /** 0x05a: Bootloader code/data/stuff. */ 413 uint8_t abStuff[0x1a3]; 414 /** 0x1fd: Old drive number location (DOS 3.2-3.31). */ 415 uint8_t bOldInt13Drive; 416 /** 0x1fe: DOS signature (FATBOOTSECTOR_SIGNATURE). */ 417 uint16_t uSignature; 73 418 } FATBOOTSECTOR; 419 AssertCompileSize(FATBOOTSECTOR, 0x200); 420 /** Pointer to a FAT boot sector. */ 74 421 typedef FATBOOTSECTOR *PFATBOOTSECTOR; 422 /** Pointer to a const FAT boot sector. */ 75 423 typedef FATBOOTSECTOR const *PCFATBOOTSECTOR; 76 424 425 /** Boot sector signature (FATBOOTSECTOR::uSignature). */ 426 #define FATBOOTSECTOR_SIGNATURE UINT16_C(0xaa55) 427 77 428 #pragma pack() 78 429
Note:
See TracChangeset
for help on using the changeset viewer.

