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