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