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