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