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