Sync with trunk (r48545)
[reactos.git] / drivers / filesystems / fastfat_new / fatstruc.h
1 #pragma once
2
3 typedef struct _FAT_SCAN_CONTEXT *PFAT_SCAN_CONTEXT;
4 typedef struct _FAT_IO_CONTEXT *PFAT_IO_CONTEXT;
5 typedef struct _FAT_IRP_CONTEXT *PFAT_IRP_CONTEXT;
6 typedef PVOID PBCB;
7
8 typedef NTSTATUS (*PFAT_OPERATION_HANDLER) (PFAT_IRP_CONTEXT);
9
10 /* Node type stuff */
11 typedef CSHORT FAT_NODE_TYPE;
12 typedef FAT_NODE_TYPE *PFAT_NODE_TYPE;
13
14 #define FatNodeType(Ptr) (*((PFAT_NODE_TYPE)(Ptr)))
15
16 /* Node type codes */
17 #define FAT_NTC_VCB (CSHORT) '00VF'
18 #define FAT_NTC_FCB (CSHORT) 'CF'
19 #define FAT_NTC_DCB (CSHORT) 'DF'
20 #define FAT_NTC_ROOT_DCB (CSHORT) 'RFD'
21 #define FAT_NTC_CCB (CSHORT) 'BCC'
22 #define FAT_NTC_IRP_CONTEXT (CSHORT) 'PRI'
23
24 typedef struct _FAT_GLOBAL_DATA
25 {
26 ERESOURCE Resource;
27 PEPROCESS SystemProcess;
28 PDRIVER_OBJECT DriverObject;
29 PDEVICE_OBJECT DiskDeviceObject;
30 LIST_ENTRY VcbListHead;
31 NPAGED_LOOKASIDE_LIST NonPagedFcbList;
32 NPAGED_LOOKASIDE_LIST ResourceList;
33 NPAGED_LOOKASIDE_LIST IrpContextList;
34 FAST_IO_DISPATCH FastIoDispatch;
35 CACHE_MANAGER_CALLBACKS CacheMgrCallbacks;
36 CACHE_MANAGER_CALLBACKS CacheMgrNoopCallbacks;
37 BOOLEAN Win31FileSystem;
38 BOOLEAN ShutdownStarted;
39 /* Jan 1, 1980 System Time */
40 LARGE_INTEGER DefaultFileTime;
41
42 /* Queued close */
43 ULONG AsyncCloseCount;
44 ULONG DelayedCloseCount;
45 LIST_ENTRY AsyncCloseList;
46 LIST_ENTRY DelayedCloseList;
47 PIO_WORKITEM FatCloseItem;
48
49 /* Various flags */
50 BOOLEAN AsyncCloseActive;
51
52 /* FullFAT integration */
53 FF_IOMAN *Ioman;
54 FF_ERROR FF_Error;
55 } FAT_GLOBAL_DATA;
56
57 typedef struct _FAT_PAGE_CONTEXT
58 {
59 PFILE_OBJECT FileObject;
60 LARGE_INTEGER EndOfData;
61 LARGE_INTEGER Offset;
62 LARGE_INTEGER EndOfPage;
63 SIZE_T ValidLength;
64 PVOID Buffer;
65 PBCB Bcb;
66 BOOLEAN CanWait;
67 } FAT_PAGE_CONTEXT, *PFAT_PAGE_CONTEXT;
68
69 #define FatPinSetupContext(xContext, xFcb, CanWait) \
70 { \
71 (xContext)->FileObject = (xFcb)->StreamFileObject; \
72 (xContext)->EndOfData = (xFcb)->Header.FileSize; \
73 (xContext)->Offset.QuadPart = -1LL; \
74 (xContext)->Bcb = NULL; \
75 (xContext)->CanWait = CanWait; \
76 }
77
78 #define FatPinCleanupContext(xContext) \
79 if ((xContext)->Bcb != NULL) { \
80 CcUnpinData((xContext)->Bcb); \
81 (xContext)->Bcb = NULL; \
82 } \
83
84 #define FatPinEndOfPage(xContext, xType) \
85 Add2Ptr((xContext)->Buffer, (xContext)->ValidLength, xType)
86
87 #define FatPinIsLastPage(xContext) \
88 ((xContext)->ValidLength != PAGE_SIZE)
89
90 #define IRPCONTEXT_CANWAIT 0x0001
91 #define IRPCONTEXT_PENDINGRETURNED 0x0002
92 #define IRPCONTEXT_STACK_IO_CONTEXT 0x0004
93 #define IRPCONTEXT_WRITETHROUGH 0x0008
94 #define IRPCONTEXT_TOPLEVEL 0x0010
95
96 typedef struct _FAT_IRP_CONTEXT
97 {
98 /* Type and size of this record (must be FAT_NTC_IRP_CONTEXT) */
99 FAT_NODE_TYPE NodeTypeCode;
100 CSHORT NodeByteSize;
101
102 PIRP Irp;
103 PDEVICE_OBJECT DeviceObject;
104 UCHAR MajorFunction;
105 UCHAR MinorFunction;
106 PFILE_OBJECT FileObject;
107 ULONG Flags;
108 struct _VCB *Vcb;
109 ULONG PinCount;
110 FAT_PAGE_CONTEXT Page;
111 struct _FAT_IO_CONTEXT *FatIoContext;
112 WORK_QUEUE_ITEM WorkQueueItem;
113 PFAT_OPERATION_HANDLER QueuedOperationHandler;
114 PIO_STACK_LOCATION Stack;
115 KEVENT Event;
116 } FAT_IRP_CONTEXT;
117
118 typedef struct _FAT_IO_CONTEXT
119 {
120 PMDL ZeroMdl;
121 PIRP Irp;
122 LONG RunCount;
123 SIZE_T Length;
124 LONGLONG Offset;
125 PFILE_OBJECT FileObject;
126
127 union
128 {
129 struct
130 {
131 PERESOURCE Resource;
132 PERESOURCE PagingIoResource;
133 ERESOURCE_THREAD ResourceThreadId;
134 } Async;
135 KEVENT SyncEvent;
136 } Wait;
137 PIRP AssociatedIrp[0];
138 } FAT_IO_CONTEXT;
139
140 typedef ULONG (*PFAT_SCANFAT_FOR_CONTINOUS_RUN_ROUTINE) (PFAT_PAGE_CONTEXT, PULONG, BOOLEAN);
141 typedef ULONG (*PFAT_SETFAT_CONTINOUS_RUN_ROUTINE) (PFAT_PAGE_CONTEXT, ULONG, ULONG, BOOLEAN);
142 typedef ULONG (*PFAT_SCANFAT_FOR_VALUE_RUN_ROUTINE) (PFAT_PAGE_CONTEXT, PULONG, ULONG, BOOLEAN);
143 typedef ULONG (*PFAT_SETFAT_VALUE_RUN_ROUTINE) (PFAT_PAGE_CONTEXT, ULONG, ULONG, ULONG, BOOLEAN);
144
145 typedef struct _FAT_METHODS {
146 PFAT_SCANFAT_FOR_CONTINOUS_RUN_ROUTINE ScanContinousRun;
147 PFAT_SETFAT_CONTINOUS_RUN_ROUTINE SetContinousRun;
148 PFAT_SCANFAT_FOR_VALUE_RUN_ROUTINE ScanValueRun;
149 PFAT_SETFAT_VALUE_RUN_ROUTINE SetValueRun;
150 } FAT_METHODS, *PFAT_METHODS;
151
152 #define VCB_STATE_FLAG_LOCKED 0x001
153 #define VCB_STATE_FLAG_DIRTY 0x002
154 #define VCB_STATE_MOUNTED_DIRTY 0x004
155 #define VCB_STATE_CREATE_IN_PROGRESS 0x008
156 #define VCB_STATE_FLAG_CLOSE_IN_PROGRESS 0x010
157 #define VCB_STATE_FLAG_DELETED_FCB 0x020
158 #define VCB_STATE_FLAG_DISMOUNT_IN_PROGRESS 0x040
159 #define VCB_STATE_FLAG_DEFERRED_FLUSH 0x080
160 #define VCB_STATE_FLAG_WRITE_PROTECTED 0x100
161
162 typedef enum _VCB_CONDITION
163 {
164 VcbGood,
165 VcbNotMounted,
166 VcbBad
167 } VCB_CONDITION;
168
169 /* Volume Control Block */
170 typedef struct _VCB
171 {
172 FSRTL_ADVANCED_FCB_HEADER Header;
173 FAST_MUTEX HeaderMutex;
174 SECTION_OBJECT_POINTERS SectionObjectPointers;
175
176 PFILE_OBJECT StreamFileObject;
177 PDEVICE_OBJECT TargetDeviceObject;
178 LIST_ENTRY VcbLinks;
179 PVPB Vpb;
180 ULONG State;
181 VCB_CONDITION Condition;
182 ERESOURCE Resource;
183 struct _CLOSE_CONTEXT *CloseContext;
184 LIST_ENTRY AsyncCloseList;
185 LIST_ENTRY DelayedCloseList;
186
187 /* Direct volume access */
188 SHARE_ACCESS ShareAccess;
189 PFILE_OBJECT FileObjectWithVcbLocked;
190
191 /* Notifications support */
192 PNOTIFY_SYNC NotifySync;
193 LIST_ENTRY NotifyList;
194
195 /* Volume Characteristics: */
196 ULONG SerialNumber;
197 BIOS_PARAMETER_BLOCK Bpb;
198 ULONG BytesPerClusterLog;
199 ULONG BytesPerCluster;
200 ULONG SectorsPerFat;
201 ULONG DataArea;
202 ULONG Sectors;
203 ULONG Clusters;
204 ULONG IndexDepth;
205 ULONG RootDirent;
206 ULONG RootDirentSectors;
207 LONGLONG BeyondLastClusterInFat;
208 FAT_METHODS Methods;
209
210 /* Root Directory Control block */
211 struct _FCB *RootDcb;
212
213 /* Counters */
214 ULONG DirectOpenCount;
215 ULONG OpenFileCount;
216 ULONG ReadOnlyCount;
217 ULONG InternalOpenCount;
218 ULONG ResidualOpenCount;
219 ULONG DirectAccessOpenCount;
220 ULONG MediaChangeCount;
221
222 /* FullFAT integration */
223 FF_IOMAN *Ioman;
224 } VCB, *PVCB;
225
226 #define VcbToVolumeDeviceObject(xVcb) \
227 CONTAINING_RECORD((xVcb), VOLUME_DEVICE_OBJECT, Vcb))
228
229 #define VcbToDeviceObject(xVcb) \
230 &(VcbToVolumeDeviceObject(xVcb)->DeviceObject)
231
232
233 #define SectorsToBytes(xVcb, xSectrors) \
234 ((xVcb)->Bpb.BytesPerSector * (xSectrors))
235
236 #define BytesToSectors(xVcb, xBytes) \
237 ((xBytes + (xVcb)->Bpb.BytesPerSector - 1) / (xVcb)->Bpb.BytesPerSector)
238
239 #define SectorsToClusters(xVcb, xSectors) \
240 ((xSectors + (xVcb)->Bpb.SectorsPerCluster - 1) / (xVcb)->Bpb.SectorsPerCluster)
241
242 #define VCB_FAT_BITMAP_SIZE 0x10000
243 #define VcbFatBitmapIndex(xCluster) ((xCluster)/VCB_FAT_BITMAP_SIZE)
244
245 /* Volume Device Object */
246 typedef struct _VOLUME_DEVICE_OBJECT
247 {
248 DEVICE_OBJECT DeviceObject;
249 union {
250 FSRTL_COMMON_FCB_HEADER VolumeHeader;
251 VCB Vcb; /* Must be the last entry! */
252 };
253 } VOLUME_DEVICE_OBJECT, *PVOLUME_DEVICE_OBJECT;
254
255 typedef enum _TYPE_OF_OPEN
256 {
257 UnopenedFileObject,
258 UserFileOpen,
259 UserDirectoryOpen,
260 UserVolumeOpen,
261 VirtualVolumeFile,
262 DirectoryFile,
263 EaFile
264 } TYPE_OF_OPEN;
265
266 //
267 // Short name always exists in FAT
268 //
269 enum _FCB_NAME_TYPE {
270 FcbShortName = 0x0,
271 FcbLongName
272 } FCB_NAME_TYPE;
273
274 typedef struct _FCB_NAME_LINK {
275 struct _FCB *Fcb;
276 RTL_SPLAY_LINKS Links;
277 union
278 {
279 OEM_STRING Ansi;
280 UNICODE_STRING String;
281 } Name;
282 BOOLEAN IsDosName;
283 } FCB_NAME_LINK, *PFCB_NAME_LINK;
284
285 typedef enum _FCB_CONDITION
286 {
287 FcbGood,
288 FcbBad,
289 FcbNeedsToBeVerified
290 } FCB_CONDITION;
291
292 #define FCB_STATE_HAS_NAMES 0x01
293 #define FCB_STATE_HAS_UNICODE_NAME 0x02
294 #define FCB_STATE_PAGEFILE 0x04
295 #define FCB_STATE_DELAY_CLOSE 0x08
296 #define FCB_STATE_TRUNCATE_ON_CLOSE 0x10
297 #define FCB_STATE_DELETE_ON_CLOSE 0x20
298
299 typedef struct _FCB
300 {
301 FSRTL_ADVANCED_FCB_HEADER Header;
302 /*
303 * Later we might want to move the next four fields
304 * into a separate structureif we decide to split
305 * FCB into paged and non paged parts
306 * (as it is done in MS implementation
307 */
308 FAST_MUTEX HeaderMutex; // nonpaged!
309 SECTION_OBJECT_POINTERS SectionObjectPointers;
310 ERESOURCE Resource; // nonpaged!
311 ERESOURCE PagingIoResource; // nonpaged!
312
313 /* First cluster in the fat allocation chain */
314 ULONG FirstClusterOfFile;
315 /* A list of all FCBs of that DCB */
316 LIST_ENTRY ParentDcbLinks;
317 /* Reference to the Parent Dcb*/
318 struct _FCB *ParentFcb;
319 /* Pointer to a Vcb */
320 PVCB Vcb;
321 /* Fcb state */
322 ULONG State;
323 /* Fcb condition */
324 FCB_CONDITION Condition;
325 /* Share access */
326 SHARE_ACCESS ShareAccess;
327 ULONG FirstCluster;
328 /* Links into FCB Tree */
329 FCB_NAME_LINK ShortName;
330 FCB_NAME_LINK LongName;
331 /* Buffer for the short name */
332 CHAR ShortNameBuffer[0xc];
333 /* Full file name */
334 UNICODE_STRING FullFileName;
335 /* Long name with exact case */
336 UNICODE_STRING ExactCaseLongName;
337 /* Hint for the filename length */
338 ULONG FileNameLength;
339 /* A copy of fat attribute byte */
340 UCHAR DirentFatFlags;
341 /* File basic info */
342 FILE_BASIC_INFORMATION BasicInfo;
343 /* FullFAT file handle */
344 FF_FILE *FatHandle;
345 /* The file has outstanding async writes */
346 ULONG OutstandingAsyncWrites;
347 /* The outstanding async writes sync event */
348 PKEVENT OutstandingAsyncEvent;
349 /* Counters */
350 ULONG OpenCount;
351 ULONG UncleanCount;
352 ULONG NonCachedUncleanCount;
353 union
354 {
355 struct
356 {
357 /* File and Op locks */
358 FILE_LOCK Lock;
359 OPLOCK Oplock;
360 } Fcb;
361
362 struct
363 {
364 LIST_ENTRY ParentDcbList; /* A list of all FCBs/DCBs opened under this DCB */
365 ULONG DirectoryFileOpenCount; /* Sector-based access to the dir */
366 PFILE_OBJECT DirectoryFile;
367 /* Directory data stream (just handy to have it). */
368 //PFILE_OBJECT StreamFileObject;
369 /* Names */
370 PRTL_SPLAY_LINKS SplayLinksAnsi;
371 PRTL_SPLAY_LINKS SplayLinksUnicode;
372 } Dcb;
373 };
374 } FCB, *PFCB;
375
376 typedef struct _FAT_ENUM_DIRENT_CONTEXT *PFAT_ENUM_DIRENT_CONTEXT;
377 typedef struct _FAT_ENUM_DIR_CONTEXT *PFAT_ENUM_DIR_CONTEXT;
378
379 typedef ULONG (*PFAT_COPY_DIRENT_ROUTINE) (PFAT_ENUM_DIR_CONTEXT, PDIR_ENTRY, PVOID);
380
381 typedef struct _FAT_ENUM_DIRENT_CONTEXT
382 {
383 FAT_PAGE_CONTEXT Page;
384
385 /* Copy dirent to dirinfo */
386 PFAT_COPY_DIRENT_ROUTINE CopyDirent;
387 LONGLONG BytesPerClusterMask;
388
389 /* Info buffer characteristics */
390 PVOID Buffer;
391 SIZE_T Offset;
392 SIZE_T Length;
393
394 /* Criteria */
395 PUNICODE_STRING FileName;
396 UCHAR CcbFlags;
397
398 /* Lfn buffer/length offsets */
399 ULONG LengthOffset;
400 ULONG NameOffset;
401 } FAT_ENUM_DIRENT_CONTEXT;
402
403 typedef struct _FAT_FIND_DIRENT_CONTEXT
404 {
405 FAT_PAGE_CONTEXT Page;
406 UNICODE_STRING ShortName;
407 WCHAR ShortNameBuffer[0x18];
408 /* Criteria */
409 PUNICODE_STRING FileName;
410 BOOLEAN Valid8dot3Name;
411 } FAT_FIND_DIRENT_CONTEXT, *PFAT_FIND_DIRENT_CONTEXT;
412
413 typedef struct _CLOSE_CONTEXT
414 {
415 LIST_ENTRY GlobalLinks;
416 LIST_ENTRY VcbLinks;
417
418 PVCB Vcb;
419 PFCB Fcb;
420 TYPE_OF_OPEN TypeOfOpen;
421 BOOLEAN Free;
422 } CLOSE_CONTEXT, *PCLOSE_CONTEXT;
423
424 typedef struct _CCB
425 {
426 CSHORT NodeTypeCode;
427 CSHORT NodeByteSize;
428
429 LARGE_INTEGER CurrentByteOffset;
430 ULONG Entry;
431 UNICODE_STRING SearchPattern;
432 UCHAR Flags;
433 CLOSE_CONTEXT CloseContext;
434 } CCB, *PCCB;
435
436 typedef enum _FILE_TIME_INDEX
437 {
438 FileCreationTime = 0,
439 FileLastAccessTime,
440 FileLastWriteTime,
441 FileChangeTime
442 } FILE_TIME_INDEX;
443
444 #define CCB_SEARCH_RETURN_SINGLE_ENTRY 0x01
445 #define CCB_SEARCH_PATTERN_LEGAL_8DOT3 0x02
446 #define CCB_SEARCH_PATTERN_HAS_WILD_CARD 0x04
447 #define CCB_DASD_IO 0x08
448 #define CCB_READ_ONLY 0x10
449 #define CCB_DELETE_ON_CLOSE 0x20
450 #define CCB_COMPLETE_DISMOUNT 0x40
451 #define CCB_CLOSE_CONTEXT 0x80
452
453 extern FAT_GLOBAL_DATA FatGlobalData;