1 /* 2 * COPYRIGHT: See COPYING in the top level directory 3 * PROJECT: ReactOS VFAT filesystem library 4 * FILE: vfatlib.h 5 */ 6 7 #ifndef _VFATLIB_H_ 8 #define _VFATLIB_H_ 9 10 #include <stdio.h> 11 #include <stdlib.h> 12 13 #define WIN32_NO_STATUS 14 #define _INC_WINDOWS 15 #define COM_NO_WINDOWS_H 16 #include <windef.h> 17 #include <winbase.h> 18 #define NTOS_MODE_USER 19 #include <ndk/iofuncs.h> 20 #include <ndk/kefuncs.h> 21 #include <ndk/obfuncs.h> 22 #include <ndk/rtlfuncs.h> 23 #include <fmifs/fmifs.h> 24 25 #include "check/dosfsck.h" 26 27 #include <pshpack1.h> 28 typedef struct _FAT16_BOOT_SECTOR 29 { 30 unsigned char magic0; // 0 31 unsigned char res0; // 1 32 unsigned char magic1; // 2 33 unsigned char OEMName[8]; // 3 34 unsigned short BytesPerSector; // 11 35 unsigned char SectorsPerCluster; // 13 36 unsigned short ReservedSectors; // 14 37 unsigned char FATCount; // 16 38 unsigned short RootEntries; // 17 39 unsigned short Sectors; // 19 40 unsigned char Media; // 21 41 unsigned short FATSectors; // 22 42 unsigned short SectorsPerTrack; // 24 43 unsigned short Heads; // 26 44 unsigned long HiddenSectors; // 28 45 unsigned long SectorsHuge; // 32 46 unsigned char Drive; // 36 47 unsigned char Res1; // 37 48 unsigned char ExtBootSignature; // 38 49 unsigned long VolumeID; // 39 50 unsigned char VolumeLabel[11]; // 43 51 unsigned char SysType[8]; // 54 52 unsigned char Res2[446]; // 62 53 unsigned long Signature1; // 508 54 } FAT16_BOOT_SECTOR, *PFAT16_BOOT_SECTOR; 55 56 typedef struct _FAT32_BOOT_SECTOR 57 { 58 unsigned char magic0; // 0 59 unsigned char res0; // 1 60 unsigned char magic1; // 2 61 unsigned char OEMName[8]; // 3 62 unsigned short BytesPerSector; // 11 63 unsigned char SectorsPerCluster; // 13 64 unsigned short ReservedSectors; // 14 65 unsigned char FATCount; // 16 66 unsigned short RootEntries; // 17 67 unsigned short Sectors; // 19 68 unsigned char Media; // 21 69 unsigned short FATSectors; // 22 70 unsigned short SectorsPerTrack; // 24 71 unsigned short Heads; // 26 72 unsigned long HiddenSectors; // 28 73 unsigned long SectorsHuge; // 32 74 unsigned long FATSectors32; // 36 75 unsigned short ExtFlag; // 40 76 unsigned short FSVersion; // 42 77 unsigned long RootCluster; // 44 78 unsigned short FSInfoSector; // 48 79 unsigned short BootBackup; // 50 80 unsigned char Res3[12]; // 52 81 unsigned char Drive; // 64 82 unsigned char Res4; // 65 83 unsigned char ExtBootSignature; // 66 84 unsigned long VolumeID; // 67 85 unsigned char VolumeLabel[11]; // 71 86 unsigned char SysType[8]; // 82 87 unsigned char Res2[418]; // 90 88 unsigned long Signature1; // 508 89 } FAT32_BOOT_SECTOR, *PFAT32_BOOT_SECTOR; 90 91 typedef struct _FAT32_FSINFO 92 { 93 unsigned long LeadSig; // 0 94 unsigned char Res1[480]; // 4 95 unsigned long StrucSig; // 484 96 unsigned long FreeCount; // 488 97 unsigned long NextFree; // 492 98 unsigned long Res2[3]; // 496 99 unsigned long TrailSig; // 508 100 } FAT32_FSINFO, *PFAT32_FSINFO; 101 #include <poppack.h> 102 103 #define FSINFO_SECTOR_BEGIN_SIGNATURE 0x41615252 // 'RRaA' 104 #define FSINFO_SECTOR_END_SIGNATURE 0xAA550000 105 #define FSINFO_SIGNATURE 0x61417272 // 'rrAa' 106 107 typedef struct _FORMAT_CONTEXT 108 { 109 PFMIFSCALLBACK Callback; 110 ULONG TotalSectorCount; 111 ULONG CurrentSectorCount; 112 BOOLEAN Success; 113 ULONG Percent; 114 } FORMAT_CONTEXT, *PFORMAT_CONTEXT; 115 116 #include "common.h" 117 118 119 NTSTATUS 120 Fat12Format(HANDLE FileHandle, 121 PPARTITION_INFORMATION PartitionInfo, 122 PDISK_GEOMETRY DiskGeometry, 123 PUNICODE_STRING Label, 124 BOOLEAN QuickFormat, 125 ULONG ClusterSize, 126 PFORMAT_CONTEXT Context); 127 128 NTSTATUS 129 Fat16Format(HANDLE FileHandle, 130 PPARTITION_INFORMATION PartitionInfo, 131 PDISK_GEOMETRY DiskGeometry, 132 PUNICODE_STRING Label, 133 BOOLEAN QuickFormat, 134 ULONG ClusterSize, 135 PFORMAT_CONTEXT Context); 136 137 NTSTATUS 138 Fat32Format(HANDLE FileHandle, 139 PPARTITION_INFORMATION PartitionInfo, 140 PDISK_GEOMETRY DiskGeometry, 141 PUNICODE_STRING Label, 142 BOOLEAN QuickFormat, 143 ULONG ClusterSize, 144 PFORMAT_CONTEXT Context); 145 146 VOID 147 UpdateProgress(PFORMAT_CONTEXT Context, 148 ULONG Increment); 149 150 VOID 151 VfatPrintV(PCHAR Format, va_list args); 152 153 VOID 154 VfatPrint(PCHAR Format, ...); 155 156 #endif /* _VFATLIB_H_ */ 157 158 /* EOF */ 159