Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenfat.h
Go to the documentation of this file.
00001 #pragma once 00002 00003 // 00004 // Might be a good idea to have this as a shared 00005 // header with FS Recognizer. 00006 // 00007 // 00008 // Conversion types and macros taken from internal ntifs headers 00009 // 00010 typedef union _UCHAR1 00011 { 00012 UCHAR Uchar[1]; 00013 UCHAR ForceAlignment; 00014 } UCHAR1, *PUCHAR1; 00015 00016 typedef union _UCHAR2 00017 { 00018 UCHAR Uchar[2]; 00019 USHORT ForceAlignment; 00020 } UCHAR2, *PUCHAR2; 00021 00022 typedef union _UCHAR4 00023 { 00024 UCHAR Uchar[4]; 00025 ULONG ForceAlignment; 00026 } UCHAR4, *PUCHAR4; 00027 00028 #define CopyUchar1(Dst,Src) { \ 00029 *((UCHAR1 *)(Dst)) = *((UNALIGNED UCHAR1 *)(Src)); \ 00030 } 00031 00032 #define CopyUchar2(Dst,Src) { \ 00033 *((UCHAR2 *)(Dst)) = *((UNALIGNED UCHAR2 *)(Src)); \ 00034 } 00035 00036 #define CopyUchar4(Dst,Src) { \ 00037 *((UCHAR4 *)(Dst)) = *((UNALIGNED UCHAR4 *)(Src)); \ 00038 } 00039 00040 #define FatUnpackBios(Bios,Pbios) { \ 00041 CopyUchar2(&(Bios)->BytesPerSector, &(Pbios)->BytesPerSector[0] ); \ 00042 CopyUchar1(&(Bios)->SectorsPerCluster, &(Pbios)->SectorsPerCluster[0]); \ 00043 CopyUchar2(&(Bios)->ReservedSectors, &(Pbios)->ReservedSectors[0] ); \ 00044 CopyUchar1(&(Bios)->Fats, &(Pbios)->Fats[0] ); \ 00045 CopyUchar2(&(Bios)->RootEntries, &(Pbios)->RootEntries[0] ); \ 00046 CopyUchar2(&(Bios)->Sectors, &(Pbios)->Sectors[0] ); \ 00047 CopyUchar1(&(Bios)->Media, &(Pbios)->Media[0] ); \ 00048 CopyUchar2(&(Bios)->SectorsPerFat, &(Pbios)->SectorsPerFat[0] ); \ 00049 CopyUchar2(&(Bios)->SectorsPerTrack, &(Pbios)->SectorsPerTrack[0] ); \ 00050 CopyUchar2(&(Bios)->Heads, &(Pbios)->Heads[0] ); \ 00051 CopyUchar4(&(Bios)->HiddenSectors, &(Pbios)->HiddenSectors[0] ); \ 00052 CopyUchar4(&(Bios)->LargeSectors, &(Pbios)->LargeSectors[0] ); \ 00053 CopyUchar4(&(Bios)->LargeSectors, &(Pbios)->LargeSectors[0] ); \ 00054 CopyUchar4(&(Bios)->LargeSectorsPerFat,&((PPACKED_BIOS_PARAMETER_BLOCK_EX)Pbios)->LargeSectorsPerFat[0] ); \ 00055 CopyUchar2(&(Bios)->ExtendedFlags, &((PPACKED_BIOS_PARAMETER_BLOCK_EX)Pbios)->ExtendedFlags[0] ); \ 00056 CopyUchar2(&(Bios)->FsVersion, &((PPACKED_BIOS_PARAMETER_BLOCK_EX)Pbios)->FsVersion[0] ); \ 00057 CopyUchar4(&(Bios)->RootDirFirstCluster, \ 00058 &((PPACKED_BIOS_PARAMETER_BLOCK_EX)Pbios)->RootDirFirstCluster[0] ); \ 00059 CopyUchar2(&(Bios)->FsInfoSector, &((PPACKED_BIOS_PARAMETER_BLOCK_EX)Pbios)->FsInfoSector[0] ); \ 00060 CopyUchar2(&(Bios)->BackupBootSector, &((PPACKED_BIOS_PARAMETER_BLOCK_EX)Pbios)->BackupBootSector[0] ); \ 00061 } 00062 // 00063 // Packed versions of the BPB and Boot Sector 00064 // 00065 typedef struct _PACKED_BIOS_PARAMETER_BLOCK 00066 { 00067 UCHAR BytesPerSector[2]; 00068 UCHAR SectorsPerCluster[1]; 00069 UCHAR ReservedSectors[2]; 00070 UCHAR Fats[1]; 00071 UCHAR RootEntries[2]; 00072 UCHAR Sectors[2]; 00073 UCHAR Media[1]; 00074 UCHAR SectorsPerFat[2]; 00075 UCHAR SectorsPerTrack[2]; 00076 UCHAR Heads[2]; 00077 UCHAR HiddenSectors[4]; 00078 UCHAR LargeSectors[4]; 00079 } PACKED_BIOS_PARAMETER_BLOCK, *PPACKED_BIOS_PARAMETER_BLOCK; 00080 // sizeof = 0x019 00081 00082 typedef struct _PACKED_BIOS_PARAMETER_BLOCK_EX 00083 { 00084 PACKED_BIOS_PARAMETER_BLOCK Block; 00085 UCHAR LargeSectorsPerFat[4]; 00086 UCHAR ExtendedFlags[2]; 00087 UCHAR FsVersion[2]; 00088 UCHAR RootDirFirstCluster[4]; 00089 UCHAR FsInfoSector[2]; 00090 UCHAR BackupBootSector[2]; 00091 UCHAR Reserved[12]; 00092 } PACKED_BIOS_PARAMETER_BLOCK_EX, *PPACKED_BIOS_PARAMETER_BLOCK_EX; 00093 // sizeof = 0x035 53 00094 00095 // 00096 // Unpacked version of the BPB 00097 // 00098 typedef struct BIOS_PARAMETER_BLOCK 00099 { 00100 USHORT BytesPerSector; 00101 UCHAR SectorsPerCluster; 00102 USHORT ReservedSectors; 00103 UCHAR Fats; 00104 USHORT RootEntries; 00105 USHORT Sectors; 00106 UCHAR Media; 00107 USHORT SectorsPerFat; 00108 USHORT SectorsPerTrack; 00109 USHORT Heads; 00110 ULONG HiddenSectors; 00111 ULONG LargeSectors; 00112 ULONG LargeSectorsPerFat; 00113 union 00114 { 00115 USHORT ExtendedFlags; 00116 struct 00117 { 00118 ULONG ActiveFat:4; 00119 ULONG Reserved0:3; 00120 ULONG MirrorDisabled:1; 00121 ULONG Reserved1:8; 00122 }; 00123 }; 00124 USHORT FsVersion; 00125 ULONG RootDirFirstCluster; 00126 USHORT FsInfoSector; 00127 USHORT BackupBootSector; 00128 } BIOS_PARAMETER_BLOCK, *PBIOS_PARAMETER_BLOCK; 00129 00130 #define FatValidBytesPerSector(xBytes) \ 00131 (!((xBytes) & ((xBytes)-1)) && (xBytes)>=0x80 && (xBytes)<=0x1000) 00132 00133 #define FatValidSectorsPerCluster(xSectors) \ 00134 (!((xSectors) & ((xSectors)-1)) && (xSectors)>0 && (xSectors)<=0x80) 00135 00136 typedef struct _PACKED_BOOT_SECTOR 00137 { 00138 UCHAR Jump[3]; 00139 UCHAR Oem[8]; 00140 PACKED_BIOS_PARAMETER_BLOCK PackedBpb; 00141 UCHAR PhysicalDriveNumber; 00142 UCHAR CurrentHead; 00143 UCHAR Signature; 00144 UCHAR Id[4]; 00145 UCHAR VolumeLabel[11]; 00146 UCHAR SystemId[8]; 00147 } PACKED_BOOT_SECTOR, *PPACKED_BOOT_SECTOR; 00148 // sizeof = 0x03E 00149 00150 typedef struct _PACKED_BOOT_SECTOR_EX 00151 { 00152 UCHAR Jump[3]; 00153 UCHAR Oem[8]; 00154 PACKED_BIOS_PARAMETER_BLOCK_EX PackedBpb; 00155 UCHAR PhysicalDriveNumber; 00156 UCHAR CurrentHead; 00157 UCHAR Signature; 00158 UCHAR Id[4]; 00159 UCHAR VolumeLabel[11]; 00160 UCHAR SystemId[8]; 00161 } PACKED_BOOT_SECTOR_EX, *PPACKED_BOOT_SECTOR_EX; 00162 // sizeof = 0x060 00163 00164 #define FatBootSectorJumpValid(xMagic) \ 00165 ((xMagic)[0] == 0xe9 || (xMagic)[0] == 0xeb || (xMagic)[0] == 0x49) 00166 00167 typedef struct _FSINFO_SECTOR 00168 { 00169 ULONG SectorBeginSignature; 00170 UCHAR Reserved[480]; 00171 ULONG FsInfoSignature; 00172 ULONG FreeClusterCount; 00173 ULONG NextFreeCluster; 00174 UCHAR Reserved0[12]; 00175 ULONG SectorEndSignature; 00176 } FSINFO_SECTOR, *PFSINFO_SECTOR; 00177 // sizeof = 0x200 00178 #define FSINFO_SECTOR_BEGIN_SIGNATURE 0x41615252 00179 #define FSINFO_SECTOR_END_SIGNATURE 0xaa550000 00180 #define FSINFO_SIGNATURE 0x61417272 00181 // 00182 // Cluster Markers: 00183 // 00184 #define FAT_CLUSTER_AVAILABLE 0x00000000 00185 #define FAT_CLUSTER_RESERVED 0x0ffffff0 00186 #define FAT_CLUSTER_BAD 0x0ffffff7 00187 #define FAT_CLUSTER_LAST 0x0fffffff 00188 // 00189 // Directory Structure: 00190 // 00191 typedef struct _FAT_TIME 00192 { 00193 union { 00194 struct { 00195 USHORT DoubleSeconds : 5; 00196 USHORT Minute : 6; 00197 USHORT Hour : 5; 00198 }; 00199 USHORT Value; 00200 }; 00201 } FAT_TIME, *PFAT_TIME; 00202 // 00203 // 00204 // 00205 typedef struct _FAT_DATE { 00206 union { 00207 struct { 00208 USHORT Day : 5; 00209 USHORT Month : 4; 00210 /* Relative to 1980 */ 00211 USHORT Year : 7; 00212 }; 00213 USHORT Value; 00214 }; 00215 } FAT_DATE, *PFAT_DATE; 00216 // 00217 // 00218 // 00219 typedef struct _FAT_DATETIME { 00220 union { 00221 struct { 00222 FAT_TIME Time; 00223 FAT_DATE Date; 00224 }; 00225 ULONG Value; 00226 }; 00227 } FAT_DATETIME, *PFAT_DATETIME; 00228 // 00229 // 00230 // 00231 typedef struct _DIR_ENTRY 00232 { 00233 UCHAR FileName[11]; 00234 UCHAR Attributes; 00235 UCHAR Case; 00236 UCHAR CreationTimeTenMs; 00237 FAT_DATETIME CreationDateTime; 00238 FAT_DATE LastAccessDate; 00239 union { 00240 USHORT ExtendedAttributes; 00241 USHORT FirstClusterOfFileHi; 00242 }; 00243 FAT_DATETIME LastWriteDateTime; 00244 USHORT FirstCluster; 00245 ULONG FileSize; 00246 } DIR_ENTRY, *PDIR_ENTRY; 00247 // sizeof = 0x020 00248 00249 typedef struct _LONG_FILE_NAME_ENTRY { 00250 UCHAR SeqNum; 00251 UCHAR NameA[10]; 00252 UCHAR Attributes; 00253 UCHAR Type; 00254 UCHAR Checksum; 00255 USHORT NameB[6]; 00256 USHORT Reserved; 00257 USHORT NameC[2]; 00258 } LONG_FILE_NAME_ENTRY, *PLONG_FILE_NAME_ENTRY; 00259 // sizeof = 0x020 00260 00261 #define FAT_LFN_NAME_LENGTH \ 00262 (RTL_FIELD_SIZE(LONG_FILE_NAME_ENTRY, NameA) \ 00263 + RTL_FIELD_SIZE(LONG_FILE_NAME_ENTRY, NameB) \ 00264 + RTL_FIELD_SIZE(LONG_FILE_NAME_ENTRY, NameC)) 00265 00266 #define FAT_FN_DIR_ENTRY_LAST 0x40 00267 #define FAT_FN_MAX_DIR_ENTIES 0x14 00268 00269 #define FAT_BYTES_PER_DIRENT 0x20 00270 #define FAT_BYTES_PER_DIRENT_LOG 0x05 00271 #define FAT_DIRENT_NEVER_USED 0x00 00272 #define FAT_DIRENT_REALLY_0E5 0x05 00273 #define FAT_DIRENT_DIRECTORY_ALIAS 0x2e 00274 #define FAT_DIRENT_DELETED 0xe5 00275 00276 #define FAT_CASE_LOWER_BASE 0x08 00277 #define FAT_CASE_LOWER_EXT 0x10 00278 00279 #define FAT_DIRENT_ATTR_READ_ONLY 0x01 00280 #define FAT_DIRENT_ATTR_HIDDEN 0x02 00281 #define FAT_DIRENT_ATTR_SYSTEM 0x04 00282 #define FAT_DIRENT_ATTR_VOLUME_ID 0x08 00283 #define FAT_DIRENT_ATTR_DIRECTORY 0x10 00284 #define FAT_DIRENT_ATTR_ARCHIVE 0x20 00285 #define FAT_DIRENT_ATTR_DEVICE 0x40 00286 #define FAT_DIRENT_ATTR_LFN (FAT_DIRENT_ATTR_READ_ONLY | \ 00287 FAT_DIRENT_ATTR_HIDDEN | \ 00288 FAT_DIRENT_ATTR_SYSTEM | \ 00289 FAT_DIRENT_ATTR_VOLUME_ID) Generated on Sun May 27 2012 04:19:06 for ReactOS by
1.7.6.1
|