1*be3a49eeSEdward Tomasz Napierala /*- 2*be3a49eeSEdward Tomasz Napierala * Copyright (c) 2006 Tobias Reifenberger 3*be3a49eeSEdward Tomasz Napierala * All rights reserved. 4*be3a49eeSEdward Tomasz Napierala * 5*be3a49eeSEdward Tomasz Napierala * Redistribution and use in source and binary forms, with or without 6*be3a49eeSEdward Tomasz Napierala * modification, are permitted provided that the following conditions 7*be3a49eeSEdward Tomasz Napierala * are met: 8*be3a49eeSEdward Tomasz Napierala * 1. Redistributions of source code must retain the above copyright 9*be3a49eeSEdward Tomasz Napierala * notice, this list of conditions and the following disclaimer. 10*be3a49eeSEdward Tomasz Napierala * 2. Redistributions in binary form must reproduce the above copyright 11*be3a49eeSEdward Tomasz Napierala * notice, this list of conditions and the following disclaimer in the 12*be3a49eeSEdward Tomasz Napierala * documentation and/or other materials provided with the distribution. 13*be3a49eeSEdward Tomasz Napierala * 14*be3a49eeSEdward Tomasz Napierala * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 15*be3a49eeSEdward Tomasz Napierala * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16*be3a49eeSEdward Tomasz Napierala * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*be3a49eeSEdward Tomasz Napierala * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 18*be3a49eeSEdward Tomasz Napierala * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*be3a49eeSEdward Tomasz Napierala * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*be3a49eeSEdward Tomasz Napierala * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*be3a49eeSEdward Tomasz Napierala * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*be3a49eeSEdward Tomasz Napierala * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*be3a49eeSEdward Tomasz Napierala * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*be3a49eeSEdward Tomasz Napierala * SUCH DAMAGE. 25*be3a49eeSEdward Tomasz Napierala */ 26*be3a49eeSEdward Tomasz Napierala 27*be3a49eeSEdward Tomasz Napierala #include <sys/types.h> 28*be3a49eeSEdward Tomasz Napierala 29*be3a49eeSEdward Tomasz Napierala /* 30*be3a49eeSEdward Tomasz Napierala * Conversion macros for little endian encoded unsigned integers 31*be3a49eeSEdward Tomasz Napierala * in byte streams to the local unsigned integer format. 32*be3a49eeSEdward Tomasz Napierala */ 33*be3a49eeSEdward Tomasz Napierala #define UINT16BYTES(p) ((uint32_t)((p)[0] + (256*(p)[1]))) 34*be3a49eeSEdward Tomasz Napierala #define UINT32BYTES(p) ((uint32_t)((p)[0] + (256*(p)[1]) + \ 35*be3a49eeSEdward Tomasz Napierala (65536*(p)[2]) + (16777216*(p)[3]))) 36*be3a49eeSEdward Tomasz Napierala 37*be3a49eeSEdward Tomasz Napierala /* 38*be3a49eeSEdward Tomasz Napierala * All following structures are according to: 39*be3a49eeSEdward Tomasz Napierala * 40*be3a49eeSEdward Tomasz Napierala * Microsoft Extensible Firmware Initiative FAT32 File System Specification 41*be3a49eeSEdward Tomasz Napierala * FAT: General Overview of On-Disk Format 42*be3a49eeSEdward Tomasz Napierala * Version 1.03, December 6, 2000 43*be3a49eeSEdward Tomasz Napierala * Microsoft Corporation 44*be3a49eeSEdward Tomasz Napierala */ 45*be3a49eeSEdward Tomasz Napierala 46*be3a49eeSEdward Tomasz Napierala /* 47*be3a49eeSEdward Tomasz Napierala * FAT boot sector and boot parameter block for 48*be3a49eeSEdward Tomasz Napierala * FAT12 and FAT16 volumes 49*be3a49eeSEdward Tomasz Napierala */ 50*be3a49eeSEdward Tomasz Napierala typedef struct fat_bsbpb { 51*be3a49eeSEdward Tomasz Napierala /* common fields */ 52*be3a49eeSEdward Tomasz Napierala uint8_t BS_jmpBoot[3]; 53*be3a49eeSEdward Tomasz Napierala uint8_t BS_OEMName[8]; 54*be3a49eeSEdward Tomasz Napierala uint8_t BPB_BytsPerSec[2]; 55*be3a49eeSEdward Tomasz Napierala uint8_t BPB_SecPerClus; 56*be3a49eeSEdward Tomasz Napierala uint8_t BPB_RsvdSecCnt[2]; 57*be3a49eeSEdward Tomasz Napierala uint8_t BPB_NumFATs; 58*be3a49eeSEdward Tomasz Napierala uint8_t BPB_RootEntCnt[2]; 59*be3a49eeSEdward Tomasz Napierala uint8_t BPB_TotSec16[2]; 60*be3a49eeSEdward Tomasz Napierala uint8_t BPB_Media; 61*be3a49eeSEdward Tomasz Napierala uint8_t BPB_FATSz16[2]; 62*be3a49eeSEdward Tomasz Napierala uint8_t BPB_SecPerTrack[2]; 63*be3a49eeSEdward Tomasz Napierala uint8_t BPB_NumHeads[2]; 64*be3a49eeSEdward Tomasz Napierala uint8_t BPB_HiddSec[4]; 65*be3a49eeSEdward Tomasz Napierala uint8_t BPB_TotSec32[4]; 66*be3a49eeSEdward Tomasz Napierala /* FAT12/FAT16 only fields */ 67*be3a49eeSEdward Tomasz Napierala uint8_t BS_DrvNum; 68*be3a49eeSEdward Tomasz Napierala uint8_t BS_Reserved1; 69*be3a49eeSEdward Tomasz Napierala uint8_t BS_BootSig; 70*be3a49eeSEdward Tomasz Napierala uint8_t BS_VolID[4]; 71*be3a49eeSEdward Tomasz Napierala uint8_t BS_VolLab[11]; 72*be3a49eeSEdward Tomasz Napierala uint8_t BS_FilSysType[8]; 73*be3a49eeSEdward Tomasz Napierala } FAT_BSBPB; /* 62 bytes */ 74*be3a49eeSEdward Tomasz Napierala 75*be3a49eeSEdward Tomasz Napierala /* 76*be3a49eeSEdward Tomasz Napierala * FAT boot sector and boot parameter block for 77*be3a49eeSEdward Tomasz Napierala * FAT32 volumes 78*be3a49eeSEdward Tomasz Napierala */ 79*be3a49eeSEdward Tomasz Napierala typedef struct fat32_bsbpb { 80*be3a49eeSEdward Tomasz Napierala /* common fields */ 81*be3a49eeSEdward Tomasz Napierala uint8_t BS_jmpBoot[3]; 82*be3a49eeSEdward Tomasz Napierala uint8_t BS_OEMName[8]; 83*be3a49eeSEdward Tomasz Napierala uint8_t BPB_BytsPerSec[2]; 84*be3a49eeSEdward Tomasz Napierala uint8_t BPB_SecPerClus; 85*be3a49eeSEdward Tomasz Napierala uint8_t BPB_RsvdSecCnt[2]; 86*be3a49eeSEdward Tomasz Napierala uint8_t BPB_NumFATs; 87*be3a49eeSEdward Tomasz Napierala uint8_t BPB_RootEntCnt[2]; 88*be3a49eeSEdward Tomasz Napierala uint8_t BPB_TotSec16[2]; 89*be3a49eeSEdward Tomasz Napierala uint8_t BPB_Media; 90*be3a49eeSEdward Tomasz Napierala uint8_t BPB_FATSz16[2]; 91*be3a49eeSEdward Tomasz Napierala uint8_t BPB_SecPerTrack[2]; 92*be3a49eeSEdward Tomasz Napierala uint8_t BPB_NumHeads[2]; 93*be3a49eeSEdward Tomasz Napierala uint8_t BPB_HiddSec[4]; 94*be3a49eeSEdward Tomasz Napierala uint8_t BPB_TotSec32[4]; 95*be3a49eeSEdward Tomasz Napierala /* FAT32 only fields */ 96*be3a49eeSEdward Tomasz Napierala uint8_t BPB_FATSz32[4]; 97*be3a49eeSEdward Tomasz Napierala uint8_t BPB_ExtFlags[2]; 98*be3a49eeSEdward Tomasz Napierala uint8_t BPB_FSVer[2]; 99*be3a49eeSEdward Tomasz Napierala uint8_t BPB_RootClus[4]; 100*be3a49eeSEdward Tomasz Napierala uint8_t BPB_FSInfo[2]; 101*be3a49eeSEdward Tomasz Napierala uint8_t BPB_BkBootSec[2]; 102*be3a49eeSEdward Tomasz Napierala uint8_t BPB_Reserved[12]; 103*be3a49eeSEdward Tomasz Napierala uint8_t BS_DrvNum; 104*be3a49eeSEdward Tomasz Napierala uint8_t BS_Reserved1; 105*be3a49eeSEdward Tomasz Napierala uint8_t BS_BootSig; 106*be3a49eeSEdward Tomasz Napierala uint8_t BS_VolID[4]; 107*be3a49eeSEdward Tomasz Napierala uint8_t BS_VolLab[11]; 108*be3a49eeSEdward Tomasz Napierala uint8_t BS_FilSysType[8]; 109*be3a49eeSEdward Tomasz Napierala } FAT32_BSBPB; /* 90 bytes */ 110*be3a49eeSEdward Tomasz Napierala 111*be3a49eeSEdward Tomasz Napierala /* 112*be3a49eeSEdward Tomasz Napierala * FAT directory entry structure 113*be3a49eeSEdward Tomasz Napierala */ 114*be3a49eeSEdward Tomasz Napierala #define FAT_DES_ATTR_READ_ONLY 0x01 115*be3a49eeSEdward Tomasz Napierala #define FAT_DES_ATTR_HIDDEN 0x02 116*be3a49eeSEdward Tomasz Napierala #define FAT_DES_ATTR_SYSTEM 0x04 117*be3a49eeSEdward Tomasz Napierala #define FAT_DES_ATTR_VOLUME_ID 0x08 118*be3a49eeSEdward Tomasz Napierala #define FAT_DES_ATTR_DIRECTORY 0x10 119*be3a49eeSEdward Tomasz Napierala #define FAT_DES_ATTR_ARCHIVE 0x20 120*be3a49eeSEdward Tomasz Napierala #define FAT_DES_ATTR_LONG_NAME (FAT_DES_ATTR_READ_ONLY | \ 121*be3a49eeSEdward Tomasz Napierala FAT_DES_ATTR_HIDDEN | \ 122*be3a49eeSEdward Tomasz Napierala FAT_DES_ATTR_SYSTEM | \ 123*be3a49eeSEdward Tomasz Napierala FAT_DES_ATTR_VOLUME_ID) 124*be3a49eeSEdward Tomasz Napierala 125*be3a49eeSEdward Tomasz Napierala typedef struct fat_des { 126*be3a49eeSEdward Tomasz Napierala uint8_t DIR_Name[11]; 127*be3a49eeSEdward Tomasz Napierala uint8_t DIR_Attr; 128*be3a49eeSEdward Tomasz Napierala uint8_t DIR_NTRes; 129*be3a49eeSEdward Tomasz Napierala uint8_t DIR_CrtTimeTenth; 130*be3a49eeSEdward Tomasz Napierala uint8_t DIR_CrtTime[2]; 131*be3a49eeSEdward Tomasz Napierala uint8_t DIR_CrtDate[2]; 132*be3a49eeSEdward Tomasz Napierala uint8_t DIR_LstAccDate[2]; 133*be3a49eeSEdward Tomasz Napierala uint8_t DIR_FstClusHI[2]; 134*be3a49eeSEdward Tomasz Napierala uint8_t DIR_WrtTime[2]; 135*be3a49eeSEdward Tomasz Napierala uint8_t DIR_WrtDate[2]; 136*be3a49eeSEdward Tomasz Napierala uint8_t DIR_FstClusLO[2]; 137*be3a49eeSEdward Tomasz Napierala uint8_t DIR_FileSize[4]; 138*be3a49eeSEdward Tomasz Napierala } FAT_DES; 139