3b846c8e58d11468333465140307d2e83351aa59
[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
140 typedef enum _VCB_CONDITION
141 {
142 VcbGood,
143 VcbNotMounted,
144 VcbBad
145 } VCB_CONDITION;
146
147 /* Volume Control Block */
148 typedef struct _VCB
149 {
150 FSRTL_ADVANCED_FCB_HEADER Header;
151 FAST_MUTEX HeaderMutex;
152 SECTION_OBJECT_POINTERS SectionObjectPointers;
153
154 PFILE_OBJECT StreamFileObject;
155 PDEVICE_OBJECT TargetDeviceObject;
156 LIST_ENTRY VcbLinks;
157 PVPB Vpb;
158 ULONG State;
159 VCB_CONDITION Condition;
160 ERESOURCE Resource;
161
162 /* Direct volume access */
163 ULONG DirectOpenCount;
164 SHARE_ACCESS ShareAccess;
165
166 /* Notifications support */
167 PNOTIFY_SYNC NotifySync;
168 LIST_ENTRY NotifyList;
169
170 /* Volume Characteristics: */
171 ULONG SerialNumber;
172 BIOS_PARAMETER_BLOCK Bpb;
173 ULONG BytesPerClusterLog;
174 ULONG BytesPerCluster;
175 ULONG SectorsPerFat;
176 ULONG DataArea;
177 ULONG Sectors;
178 ULONG Clusters;
179 ULONG IndexDepth;
180 ULONG RootDirent;
181 ULONG RootDirentSectors;
182 LONGLONG BeyondLastClusterInFat;
183 FAT_METHODS Methods;
184
185 /* Root Directory Control block */
186 struct _FCB *RootDcb;
187
188 /* Counters */
189 ULONG MediaChangeCount;
190 ULONG OpenFileCount;
191
192 /* FullFAT integration */
193 FF_IOMAN *Ioman;
194 } VCB, *PVCB;
195
196 #define VcbToVolumeDeviceObject(xVcb) \
197 CONTAINING_RECORD((xVcb), VOLUME_DEVICE_OBJECT, Vcb))
198
199 #define VcbToDeviceObject(xVcb) \
200 &(VcbToVolumeDeviceObject(xVcb)->DeviceObject)
201
202
203 #define SectorsToBytes(xVcb, xSectrors) \
204 ((xVcb)->Bpb.BytesPerSector * (xSectrors))
205
206 #define BytesToSectors(xVcb, xBytes) \
207 ((xBytes + (xVcb)->Bpb.BytesPerSector - 1) / (xVcb)->Bpb.BytesPerSector)
208
209 #define SectorsToClusters(xVcb, xSectors) \
210 ((xSectors + (xVcb)->Bpb.SectorsPerCluster - 1) / (xVcb)->Bpb.SectorsPerCluster)
211
212 #define VCB_FAT_BITMAP_SIZE 0x10000
213 #define VcbFatBitmapIndex(xCluster) ((xCluster)/VCB_FAT_BITMAP_SIZE)
214
215 /* Volume Device Object */
216 typedef struct _VOLUME_DEVICE_OBJECT
217 {
218 DEVICE_OBJECT DeviceObject;
219 union {
220 FSRTL_COMMON_FCB_HEADER VolumeHeader;
221 VCB Vcb; /* Must be the last entry! */
222 };
223 } VOLUME_DEVICE_OBJECT, *PVOLUME_DEVICE_OBJECT;
224 //
225 // Short name always exists in FAT
226 //
227 enum _FCB_NAME_TYPE {
228 FcbShortName = 0x0,
229 FcbLongName
230 } FCB_NAME_TYPE;
231
232 typedef struct _FCB_NAME_LINK {
233 struct _FCB *Fcb;
234 RTL_SPLAY_LINKS Links;
235 union
236 {
237 OEM_STRING Ansi;
238 UNICODE_STRING String;
239 } Name;
240 BOOLEAN IsDosName;
241 } FCB_NAME_LINK, *PFCB_NAME_LINK;
242
243 typedef enum _FCB_CONDITION
244 {
245 FcbGood,
246 FcbBad,
247 FcbNeedsToBeVerified
248 } FCB_CONDITION;
249
250 #define FCB_STATE_HAS_NAMES 0x01
251 #define FCB_STATE_HAS_UNICODE_NAME 0x02
252
253 typedef struct _FCB
254 {
255 FSRTL_ADVANCED_FCB_HEADER Header;
256 /*
257 * Later we might want to move the next four fields
258 * into a separate structureif we decide to split
259 * FCB into paged and non paged parts
260 * (as it is done in MS implementation
261 */
262 FAST_MUTEX HeaderMutex; // nonpaged!
263 SECTION_OBJECT_POINTERS SectionObjectPointers;
264 ERESOURCE Resource; // nonpaged!
265 ERESOURCE PagingIoResource; // nonpaged!
266
267 FILE_LOCK Lock;
268 /* First cluster in the fat allocation chain */
269 ULONG FirstClusterOfFile;
270 /* A list of all FCBs of that DCB */
271 LIST_ENTRY ParentDcbLinks;
272 /* Reference to the Parent Dcb*/
273 struct _FCB *ParentFcb;
274 /* Pointer to a Vcb */
275 PVCB Vcb;
276 /* Fcb state */
277 ULONG State;
278 /* Fcb condition */
279 FCB_CONDITION Condition;
280 /* Share access */
281 SHARE_ACCESS ShareAccess;
282 /* Mcb mapping Vbo->Lbo */
283 LARGE_MCB Mcb;
284 ULONG FirstCluster;
285 /* Links into FCB Tree */
286 FCB_NAME_LINK ShortName;
287 FCB_NAME_LINK LongName;
288 /* Buffer for the short name */
289 CHAR ShortNameBuffer[0xc];
290 /* Full file name */
291 UNICODE_STRING FullFileName;
292 /* Long name with exact case */
293 UNICODE_STRING ExactCaseLongName;
294 /* Hint for the filename length */
295 ULONG FileNameLength;
296 /* A copy of fat attribute byte */
297 UCHAR DirentFatFlags;
298 /* File basic info */
299 FILE_BASIC_INFORMATION BasicInfo;
300 /* FullFAT file handle */
301 FF_FILE *FatHandle;
302 /* The file has outstanding async writes */
303 ULONG OutstandingAsyncWrites;
304 /* The outstanding async writes sync event */
305 PKEVENT OutstandingAsyncEvent;
306 union
307 {
308 struct
309 {
310 /* A list of all FCBs/DCBs opened under this DCB */
311 LIST_ENTRY ParentDcbList;
312 /* Directory data stream (just handy to have it). */
313 PFILE_OBJECT StreamFileObject;
314 /* Bitmap to search for free dirents. */
315 RTL_BITMAP FreeBitmap;
316 /* Names */
317 PRTL_SPLAY_LINKS SplayLinksAnsi;
318 PRTL_SPLAY_LINKS SplayLinksUnicode;
319 } Dcb;
320 };
321 } FCB, *PFCB;
322
323 typedef struct _FAT_ENUM_DIRENT_CONTEXT *PFAT_ENUM_DIRENT_CONTEXT;
324 typedef struct _FAT_ENUM_DIR_CONTEXT *PFAT_ENUM_DIR_CONTEXT;
325
326 typedef ULONG (*PFAT_COPY_DIRENT_ROUTINE) (PFAT_ENUM_DIR_CONTEXT, PDIR_ENTRY, PVOID);
327
328 typedef struct _FAT_ENUM_DIRENT_CONTEXT
329 {
330 FAT_PAGE_CONTEXT Page;
331
332 /* Copy dirent to dirinfo */
333 PFAT_COPY_DIRENT_ROUTINE CopyDirent;
334 LONGLONG BytesPerClusterMask;
335
336 /* Info buffer characteristics */
337 PVOID Buffer;
338 SIZE_T Offset;
339 SIZE_T Length;
340
341 /* Criteria */
342 PUNICODE_STRING FileName;
343 UCHAR CcbFlags;
344
345 /* Lfn buffer/length offsets */
346 ULONG LengthOffset;
347 ULONG NameOffset;
348 } FAT_ENUM_DIRENT_CONTEXT;
349
350 typedef struct _FAT_FIND_DIRENT_CONTEXT
351 {
352 FAT_PAGE_CONTEXT Page;
353 UNICODE_STRING ShortName;
354 WCHAR ShortNameBuffer[0x18];
355 /* Criteria */
356 PUNICODE_STRING FileName;
357 BOOLEAN Valid8dot3Name;
358 } FAT_FIND_DIRENT_CONTEXT, *PFAT_FIND_DIRENT_CONTEXT;
359
360 typedef struct _CCB
361 {
362 CSHORT NodeTypeCode;
363 CSHORT NodeByteSize;
364
365 LARGE_INTEGER CurrentByteOffset;
366 ULONG Entry;
367 UNICODE_STRING SearchPattern;
368 UCHAR Flags;
369 } CCB, *PCCB;
370
371 typedef enum _TYPE_OF_OPEN
372 {
373 UnopenedFileObject,
374 UserFileOpen,
375 UserDirectoryOpen,
376 UserVolumeOpen,
377 VirtualVolumeFile,
378 DirectoryFile,
379 EaFile
380 } TYPE_OF_OPEN;
381
382 #define CCB_SEARCH_RETURN_SINGLE_ENTRY 0x01
383 #define CCB_SEARCH_PATTERN_LEGAL_8DOT3 0x02
384 #define CCB_SEARCH_PATTERN_HAS_WILD_CARD 0x04
385 #define CCB_DASD_IO 0x10
386 extern FAT_GLOBAL_DATA FatGlobalData;
387
388 #endif//__STRUCT_H__