*** empty log message ***
[reactos.git] / reactos / drivers / fs / vfat / vfat.h
1 #include <wchar.h>
2
3
4
5
6 struct _BootSector {
7 unsigned char magic0, res0, magic1;
8 unsigned char OEMName[8];
9 unsigned short BytesPerSector;
10 unsigned char SectorsPerCluster;
11 unsigned short ReservedSectors;
12 unsigned char FATCount;
13 unsigned short RootEntries, Sectors;
14 unsigned char Media;
15 unsigned short FATSectors, SectorsPerTrack, Heads;
16 unsigned long HiddenSectors, SectorsHuge;
17 unsigned char Drive, Res1, Sig;
18 unsigned long VolumeID;
19 unsigned char VolumeLabel[11], SysType[8];
20 unsigned char Res2[450];
21 } __attribute__((packed));
22
23 struct _BootSector32 {
24 unsigned char magic0, res0, magic1;
25 unsigned char OEMName[8];
26 unsigned short BytesPerSector;
27 unsigned char SectorsPerCluster;
28 unsigned short ReservedSectors;
29 unsigned char FATCount;
30 unsigned short RootEntries, Sectors;
31 unsigned char Media;
32 unsigned short FATSectors, SectorsPerTrack, Heads;
33 unsigned long HiddenSectors, SectorsHuge;
34 unsigned long FATSectors32;
35 unsigned char x[27];
36 unsigned long VolumeID;
37 unsigned char VolumeLabel[11], SysType[8];
38 unsigned char Res2[422];
39 } __attribute__((packed));
40
41 typedef struct _BootSector BootSector;
42
43 struct _FATDirEntry {
44 unsigned char Filename[8], Ext[3], Attrib, Res[2];
45 unsigned short CreationTime,CreationDate,AccessDate;
46 unsigned short FirstClusterHigh;// higher
47 unsigned short UpdateTime;//time create/update
48 unsigned short UpdateDate;//date create/update
49 unsigned short FirstCluster;
50 unsigned long FileSize;
51 } __attribute__((packed));
52
53 typedef struct _FATDirEntry FATDirEntry;
54
55 struct _slot
56 {
57 unsigned char id; // sequence number for slot
58 WCHAR name0_4[5]; // first 5 characters in name
59 unsigned char attr; // attribute byte
60 unsigned char reserved; // always 0
61 unsigned char alias_checksum; // checksum for 8.3 alias
62 WCHAR name5_10[6]; // 6 more characters in name
63 unsigned char start[2]; // starting cluster number
64 WCHAR name11_12[2]; // last 2 characters in name
65 } __attribute__((packed));
66
67
68 typedef struct _slot slot;
69
70 #define BLOCKSIZE 512
71
72 #define FAT16 (1)
73 #define FAT12 (2)
74 #define FAT32 (3)
75
76 typedef struct
77 {
78 ERESOURCE Resource;
79 PDEVICE_OBJECT StorageDevice;
80 BootSector *Boot;
81 int rootDirectorySectors, FATStart, rootStart, dataStart;
82 int FATEntriesPerSector, FATUnit;
83 ULONG BytesPerCluster;
84 ULONG FatType;
85 unsigned char* FAT;
86 } DEVICE_EXTENSION, *PDEVICE_EXTENSION;
87
88 typedef struct _FSRTL_COMMON_FCB_HEADER{
89 char IsFastIoPossible;//is char the realtype ?
90 ERESOURCE Resource;
91 ERESOURCE PagingIoResource;
92 ULONG Flags;// is long the real type ?
93 LARGE_INTEGER AllocationSize;
94 LARGE_INTEGER FileSize;
95 LARGE_INTEGER ValidDataLength;
96 // other fields ??
97 } FSRTL_COMMON_FCB_HEADER;
98
99 typedef struct _SFsdNTRequiredFCB {
100 FSRTL_COMMON_FCB_HEADER CommonFCBHeader;
101 SECTION_OBJECT_POINTERS SectionObject;
102 ERESOURCE MainResource;
103 ERESOURCE PagingIoResource;
104 } SFsdNTRequiredFCB, *PtrSFsdNTRequiredFCB;
105
106 struct _VfatFCB;
107 typedef struct _VfatFCB
108 {
109 SFsdNTRequiredFCB NTRequiredFCB;
110 FATDirEntry entry;
111 WCHAR *ObjectName; // point on filename (250 chars max) in PathName
112 WCHAR PathName[MAX_PATH];// path+filename 260 max
113 long RefCount;
114 PDEVICE_EXTENSION pDevExt;
115 struct _VfatFCB * nextFcb, *prevFcb;
116 struct _VfatFCB * parentFcb;
117 } VfatFCB, *PVfatFCB;
118
119 typedef struct
120 {
121 VfatFCB * pFcb;
122 LIST_ENTRY NextCCB;
123 PFILE_OBJECT PtrFileObject;
124 LARGE_INTEGER CurrentByteOffset;
125 ULONG StartSector; // for DirectoryControl
126 ULONG StartEntry; //for DirectoryControl
127 // PSTRING DirectorySearchPattern;// for DirectoryControl ?
128 } VfatCCB, *PVfatCCB;
129
130
131 #define ENTRIES_PER_SECTOR (BLOCKSIZE / sizeof(FATDirEntry))
132
133
134 typedef struct __DOSTIME
135 {
136 WORD Second:5;
137 WORD Minute:6;
138 WORD Hour:5;
139 } DOSTIME, *PDOSTIME;
140
141 typedef struct __DOSDATE
142 {
143 WORD Day:5;
144 WORD Month:4;
145 WORD Year:5;
146 } DOSDATE, *PDOSDATE;
147
148
149 extern PVfatFCB pFirstFcb;
150
151 // functions called by i/o manager :
152 NTSTATUS STDCALL DriverEntry(PDRIVER_OBJECT _DriverObject,PUNICODE_STRING RegistryPath);
153 NTSTATUS FsdDirectoryControl(PDEVICE_OBJECT DeviceObject, PIRP Irp);
154 NTSTATUS FsdRead(PDEVICE_OBJECT DeviceObject, PIRP Irp);
155 NTSTATUS FsdWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp);
156 NTSTATUS FsdCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp);
157 NTSTATUS FsdClose(PDEVICE_OBJECT DeviceObject, PIRP Irp);
158 NTSTATUS FsdFileSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp);
159 NTSTATUS FsdQueryInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
160
161
162 // internal functions in blockdev.c
163 BOOLEAN VFATReadSectors(IN PDEVICE_OBJECT pDeviceObject,
164 IN ULONG DiskSector,
165 IN ULONG SectorCount,
166 IN UCHAR* Buffer);
167
168 BOOLEAN VFATWriteSectors(IN PDEVICE_OBJECT pDeviceObject,
169 IN ULONG DiskSector,
170 IN ULONG SectorCount,
171 IN UCHAR* Buffer);
172
173 //internal functions in dir.c :
174 BOOL FsdDosDateTimeToFileTime(WORD wDosDate,WORD wDosTime, TIME *FileTime);
175
176 //internal functions in iface.c :
177 NTSTATUS FindFile(PDEVICE_EXTENSION DeviceExt, PVfatFCB Fcb,
178 PVfatFCB Parent, PWSTR FileToFind,ULONG *StartSector,ULONG *Entry);
179 NTSTATUS FsdCloseFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject);
180 NTSTATUS FsdGetStandardInformation(PVfatFCB FCB, PDEVICE_OBJECT DeviceObject,
181 PFILE_STANDARD_INFORMATION StandardInfo);
182 NTSTATUS FsdOpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
183 PWSTR FileName);
184 NTSTATUS FsdReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
185 PVOID Buffer, ULONG Length, ULONG ReadOffset,
186 PULONG LengthRead);
187 NTSTATUS FsdWriteFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
188 PVOID Buffer, ULONG Length, ULONG WriteOffset);
189 ULONG GetNextWriteCluster(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster);
190 BOOLEAN IsDeletedEntry(PVOID Block, ULONG Offset);
191 BOOLEAN IsLastEntry(PVOID Block, ULONG Offset);
192 wchar_t * vfat_wcsncpy(wchar_t * dest, const wchar_t *src,size_t wcount);
193 void VFATWriteCluster(PDEVICE_EXTENSION DeviceExt, PVOID Buffer, ULONG Cluster);
194
195 //internal functions in dirwr.c
196 NTSTATUS addEntry(PDEVICE_EXTENSION DeviceExt
197 ,PFILE_OBJECT pFileObject,ULONG RequestedOptions,UCHAR ReqAttr);
198 NTSTATUS updEntry(PDEVICE_EXTENSION DeviceExt,PFILE_OBJECT pFileObject);
199
200
201 //FIXME : following defines must be removed
202 //FIXME when this functions will work.
203 #define ExAcquireResourceExclusiveLite(x,y) {}
204 #define ExReleaseResourceForThreadLite(x,y) {}