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