89951cf29b83c18592a30106fac17712dbc86b17
[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 PVOID PBCB;
7
8 typedef struct _FAT_GLOBAL_DATA
9 {
10 ERESOURCE Resource;
11 PDRIVER_OBJECT DriverObject;
12 PDEVICE_OBJECT DiskDeviceObject;
13 LIST_ENTRY VcbListHead;
14 NPAGED_LOOKASIDE_LIST NonPagedFcbList;
15 NPAGED_LOOKASIDE_LIST ResourceList;
16 NPAGED_LOOKASIDE_LIST IrpContextList;
17 FAST_IO_DISPATCH FastIoDispatch;
18 CACHE_MANAGER_CALLBACKS CacheMgrCallbacks;
19 CACHE_MANAGER_CALLBACKS CacheMgrNoopCallbacks;
20 BOOLEAN Win31FileSystem;
21 /* Jan 1, 1980 System Time */
22 LARGE_INTEGER DefaultFileTime;
23 } FAT_GLOBAL_DATA;
24
25 #define IRPCONTEXT_CANWAIT 0x0001
26 #define IRPCONTEXT_PENDINGRETURNED 0x0002
27 #define IRPCONTEXT_STACK_IO_CONTEXT 0x0004
28 #define IRPCONTEXT_WRITETHROUGH 0x0008
29 #define IRPCONTEXT_TOPLEVEL 0x0010
30
31 typedef struct _FAT_IRP_CONTEXT
32 {
33 PIRP Irp;
34 PDEVICE_OBJECT DeviceObject;
35 UCHAR MajorFunction;
36 UCHAR MinorFunction;
37 PFILE_OBJECT FileObject;
38 ULONG Flags;
39 struct _VCB *Vcb;
40 ULONG PinCount;
41 struct _FAT_IO_CONTEXT *FatIoContext;
42
43 WORK_QUEUE_ITEM WorkQueueItem;
44 PIO_STACK_LOCATION Stack;
45 KEVENT Event;
46 } FAT_IRP_CONTEXT, *PFAT_IRP_CONTEXT;
47
48 typedef struct _FAT_IO_CONTEXT
49 {
50 PMDL ZeroMdl;
51 PIRP MasterIrp;
52 LONG IrpCount;
53 union
54 {
55 struct
56 {
57 PERESOURCE Resource;
58 PERESOURCE PagingIoResource;
59 ERESOURCE_THREAD ResourceThreadId;
60 ULONG RequestedByteCount;
61 PFILE_OBJECT FileObject;
62 BOOLEAN ReadOperation;
63 } Async;
64 KEVENT SyncEvent;
65 } Wait;
66 PIRP Irp[0];
67 } FAT_IO_CONTEXT;
68
69 typedef ULONG (*PFAT_SCANFAT_FOR_CONTINOUS_RUN_ROUTINE) (struct _FAT_SCAN_CONTEXT*, PULONG, BOOLEAN);
70 typedef ULONG (*PFAT_SETFAT_CONTINOUS_RUN_ROUTINE) (PFAT_SCAN_CONTEXT, ULONG, ULONG, BOOLEAN);
71 typedef ULONG (*PFAT_SCANFAT_FOR_VALUE_RUN_ROUTINE) (PFAT_SCAN_CONTEXT, PULONG, ULONG, BOOLEAN);
72 typedef ULONG (*PFAT_SETFAT_VALUE_RUN_ROUTINE) (PFAT_SCAN_CONTEXT, ULONG, ULONG, ULONG, BOOLEAN);
73
74 typedef struct _FAT_METHODS {
75 PFAT_SCANFAT_FOR_CONTINOUS_RUN_ROUTINE ScanContinousRun;
76 PFAT_SETFAT_CONTINOUS_RUN_ROUTINE SetContinousRun;
77 PFAT_SCANFAT_FOR_VALUE_RUN_ROUTINE ScanValueRun;
78 PFAT_SETFAT_VALUE_RUN_ROUTINE SetValueRun;
79 } FAT_METHODS, *PFAT_METHODS;
80
81 #define FAT_NTC_VCB (USHORT)TAG('F', 'V', 0, 0);
82
83 /* Volume Control Block */
84 typedef struct _VCB
85 {
86 FSRTL_ADVANCED_FCB_HEADER Header;
87 FAST_MUTEX HeaderMutex;
88 SECTION_OBJECT_POINTERS SectionObjectPointers;
89
90 PFILE_OBJECT VolumeFileObject;
91 PDEVICE_OBJECT TargetDeviceObject;
92 LIST_ENTRY VcbLinks;
93
94 /* Notifications support */
95 PNOTIFY_SYNC NotifySync;
96 LIST_ENTRY NotifyList;
97
98 /* Volume Characteristics: */
99 ULONG SerialNumber;
100 BIOS_PARAMETER_BLOCK Bpb;
101 ULONG BytesPerClusterLog;
102 ULONG BytesPerCluster;
103 ULONG SectorsPerFat;
104 ULONG DataArea;
105 ULONG Sectors;
106 ULONG Clusters;
107 ULONG IndexDepth;
108 ULONG RootDirent;
109 ULONG RootDirentSectors;
110 LONGLONG BeyoundLastClusterInFat;
111 FAT_METHODS Methods;
112 /* Root Directory Fcb: */
113 struct _FCB *RootFcb;
114 } VCB, *PVCB;
115
116 #define VcbToVolumeDeviceObject(xVcb) \
117 CONTAINING_RECORD((xVcb), VOLUME_DEVICE_OBJECT, Vcb))
118
119 #define VcbToDeviceObject(xVcb) \
120 &(VcbToVolumeDeviceObject(xVcb)->DeviceObject)
121
122
123 #define SectorsToBytes(xVcb, xSectrors) \
124 ((xVcb)->Bpb.BytesPerSector * (xSectrors))
125
126 #define BytesToSectors(xVcb, xBytes) \
127 ((xBytes + (xVcb)->Bpb.BytesPerSector - 1) / (xVcb)->Bpb.BytesPerSector)
128
129 #define SectorsToClusters(xVcb, xSectors) \
130 ((xSectors + (xVcb)->Bpb.SectorsPerCluster - 1) / (xVcb)->Bpb.SectorsPerCluster)
131
132 #define VCB_FAT_BITMAP_SIZE 0x10000
133 #define VcbFatBitmapIndex(xCluster) ((xCluster)/VCB_FAT_BITMAP_SIZE)
134
135 /* Volume Device Object */
136 typedef struct _VOLUME_DEVICE_OBJECT
137 {
138 DEVICE_OBJECT DeviceObject;
139 union {
140 FSRTL_COMMON_FCB_HEADER VolumeHeader;
141 VCB Vcb; /* Must be the last entry! */
142 };
143 } VOLUME_DEVICE_OBJECT, *PVOLUME_DEVICE_OBJECT;
144 //
145 // Short name always exists in FAT
146 //
147 enum _FCB_NAME_TYPE {
148 FcbShortName = 0x0,
149 FcbLongName
150 } FCB_NAME_TYPE;
151
152 typedef struct _FCB_NAME_LINK {
153 RTL_SPLAY_LINKS Links;
154 UNICODE_STRING String;
155 UCHAR Type;
156 } FCB_NAME_LINK, *PFCB_NAME_LINK;
157
158 #define FAT_NTC_FCB (USHORT) 'CF'
159 #define FAT_NTC_DCB (USHORT) 'DF'
160
161 typedef struct _FCB
162 {
163 FSRTL_ADVANCED_FCB_HEADER Header;
164 /*
165 * Later we might want to move the next four fields
166 * into a separate structureif we decide to split
167 * FCB into paged and non paged parts
168 * (as it is done in MS implementation
169 */
170 FAST_MUTEX HeaderMutex;
171 SECTION_OBJECT_POINTERS SectionObjectPointers;
172 ERESOURCE Resource;
173 ERESOURCE PagingIoResource;
174
175 FILE_LOCK Lock;
176 /* Reference to the Parent Dcb*/
177 struct _FCB *ParentFcb;
178 /* Pointer to a Vcb */
179 PVCB Vcb;
180 /* Mcb mapping Vbo->Lbo */
181 LARGE_MCB Mcb;
182 ULONG FirstCluster;
183 /* Links into FCB Trie */
184 FCB_NAME_LINK FileName[0x2];
185 /* Buffer for the short name */
186 WCHAR ShortNameBuffer[0xc];
187 union
188 {
189 struct
190 {
191 /* Bitmap to search for free dirents. */
192 /* RTL_BITMAP Bitmap; */
193 PRTL_SPLAY_LINKS SplayLinks;
194 } Dcb;
195 };
196 } FCB, *PFCB;
197
198 typedef struct _CCB
199 {
200 LARGE_INTEGER CurrentByteOffset;
201 ULONG Entry;
202 UNICODE_STRING SearchPattern;
203 } CCB, *PCCB;
204
205 extern FAT_GLOBAL_DATA FatGlobalData;
206
207 #endif//__STRUCT_H__