[BLUE][CDFS]
[reactos.git] / reactos / drivers / filesystems / cdfs / cdfs.h
1 #ifndef CDFS_H
2 #define CDFS_H
3
4 #include <ntifs.h>
5 #include <ntddcdrm.h>
6 #include <pseh/pseh2.h>
7
8 #define CDFS_BASIC_SECTOR 2048
9 #define CDFS_PRIMARY_DESCRIPTOR_LOCATION 16
10 #define BLOCKSIZE CDFS_BASIC_SECTOR
11 #define CDFS_MAX_NAME_LEN 256
12
13 /* Volume descriptor types (VdType) */
14 #define BOOT_VOLUME_DESCRIPTOR_TYPE 0
15 #define PRIMARY_VOLUME_DESCRIPTOR_TYPE 1
16 #define SUPPLEMENTARY_VOLUME_DESCRIPTOR_TYPE 2
17 #define VOLUME_PARTITION_DESCRIPTOR_TYPE 3
18 #define VOLUME_DESCRIPTOR_SET_TERMINATOR 255
19
20 #include <pshpack1.h>
21 struct _DIR_RECORD
22 {
23 UCHAR RecordLength; // 1
24 UCHAR ExtAttrRecordLength; // 2
25 ULONG ExtentLocationL; // 3-6
26 ULONG ExtentLocationM; // 7-10
27 ULONG DataLengthL; // 11-14
28 ULONG DataLengthM; // 15-18
29 UCHAR Year; // 19
30 UCHAR Month; // 20
31 UCHAR Day; // 21
32 UCHAR Hour; // 22
33 UCHAR Minute; // 23
34 UCHAR Second; // 24
35 UCHAR TimeZone; // 25
36 UCHAR FileFlags; // 26
37 UCHAR FileUnitSize; // 27
38 UCHAR InterleaveGapSize; // 28
39 ULONG VolumeSequenceNumber; // 29-32
40 UCHAR FileIdLength; // 33
41 UCHAR FileId[1]; // 34
42 };
43 #include <poppack.h>
44
45 typedef struct _DIR_RECORD DIR_RECORD, *PDIR_RECORD;
46
47 /* DIR_RECORD.FileFlags */
48 #define FILE_FLAG_HIDDEN 0x01
49 #define FILE_FLAG_DIRECTORY 0x02
50 #define FILE_FLAG_SYSTEM 0x04
51 #define FILE_FLAG_READONLY 0x10
52
53
54 /* Volume Descriptor header*/
55 #include <pshpack1.h>
56 struct _VD_HEADER
57 {
58 UCHAR VdType; // 1
59 UCHAR StandardId[5]; // 2-6
60 UCHAR VdVersion; // 7
61 };
62
63 typedef struct _VD_HEADER VD_HEADER, *PVD_HEADER;
64
65
66
67 /* Primary Volume Descriptor */
68 struct _PVD
69 {
70 UCHAR VdType; // 1
71 UCHAR StandardId[5]; // 2-6
72 UCHAR VdVersion; // 7
73 UCHAR unused0; // 8
74 UCHAR SystemId[32]; // 9-40
75 UCHAR VolumeId[32]; // 41-72
76 UCHAR unused1[8]; // 73-80
77 ULONG VolumeSpaceSizeL; // 81-84
78 ULONG VolumeSpaceSizeM; // 85-88
79 UCHAR unused2[32]; // 89-120
80 ULONG VolumeSetSize; // 121-124
81 ULONG VolumeSequenceNumber; // 125-128
82 ULONG LogicalBlockSize; // 129-132
83 ULONG PathTableSizeL; // 133-136
84 ULONG PathTableSizeM; // 137-140
85 ULONG LPathTablePos; // 141-144
86 ULONG LOptPathTablePos; // 145-148
87 ULONG MPathTablePos; // 149-152
88 ULONG MOptPathTablePos; // 153-156
89 DIR_RECORD RootDirRecord; // 157-190
90 UCHAR VolumeSetIdentifier[128]; // 191-318
91 UCHAR PublisherIdentifier[128]; // 319-446
92
93 /* more data ... */
94
95 };
96 typedef struct _PVD PVD, *PPVD;
97
98
99 /* Supplementary Volume Descriptor */
100 struct _SVD
101 {
102 UCHAR VdType; // 1
103 UCHAR StandardId[5]; // 2-6
104 UCHAR VdVersion; // 7
105 UCHAR VolumeFlags; // 8
106 UCHAR SystemId[32]; // 9-40
107 UCHAR VolumeId[32]; // 41-72
108 UCHAR unused1[8]; // 73-80
109 ULONG VolumeSpaceSizeL; // 81-84
110 ULONG VolumeSpaceSizeM; // 85-88
111 UCHAR EscapeSequences[32]; // 89-120
112 ULONG VolumeSetSize; // 121-124
113 ULONG VolumeSequenceNumber; // 125-128
114 ULONG LogicalBlockSize; // 129-132
115 ULONG PathTableSizeL; // 133-136
116 ULONG PathTableSizeM; // 137-140
117 ULONG LPathTablePos; // 141-144
118 ULONG LOptPathTablePos; // 145-148
119 ULONG MPathTablePos; // 149-152
120 ULONG MOptPathTablePos; // 153-156
121 DIR_RECORD RootDirRecord; // 157-190
122 UCHAR VolumeSetIdentifier[128]; // 191-318
123 UCHAR PublisherIdentifier[128]; // 319-446
124
125 // more data ...
126 };
127 #include <poppack.h>
128
129 typedef struct _SVD SVD, *PSVD;
130
131
132
133
134
135
136
137 typedef struct _CDINFO
138 {
139 ULONG VolumeOffset;
140 ULONG VolumeSpaceSize;
141 ULONG JolietLevel;
142 ULONG RootStart;
143 ULONG RootSize;
144 WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH / sizeof(WCHAR)];
145 USHORT VolumeLabelLength;
146 ULONG SerialNumber;
147 } CDINFO, *PCDINFO;
148
149
150 typedef struct
151 {
152 ERESOURCE VcbResource;
153 ERESOURCE DirResource;
154
155 KSPIN_LOCK FcbListLock;
156 LIST_ENTRY FcbListHead;
157
158 PVPB Vpb;
159 PDEVICE_OBJECT VolumeDevice;
160 PDEVICE_OBJECT StorageDevice;
161 PFILE_OBJECT StreamFileObject;
162
163 CDINFO CdInfo;
164
165 /* Notifications */
166 LIST_ENTRY NotifyList;
167 PNOTIFY_SYNC NotifySync;
168 } DEVICE_EXTENSION, *PDEVICE_EXTENSION, VCB, *PVCB;
169
170
171 #define FCB_CACHE_INITIALIZED 0x0001
172 #define FCB_IS_VOLUME_STREAM 0x0002
173 #define FCB_IS_VOLUME 0x0004
174
175 #define MAX_PATH 260
176
177 typedef struct _CDFS_SHORT_NAME
178 {
179 LIST_ENTRY Entry;
180 LARGE_INTEGER StreamOffset;
181 UNICODE_STRING Name;
182 WCHAR NameBuffer[13];
183 } CDFS_SHORT_NAME, *PCDFS_SHORT_NAME;
184
185 typedef struct _FCB
186 {
187 FSRTL_COMMON_FCB_HEADER RFCB;
188 SECTION_OBJECT_POINTERS SectionObjectPointers;
189 ERESOURCE MainResource;
190 ERESOURCE PagingIoResource;
191
192 PFILE_OBJECT FileObject;
193 PDEVICE_EXTENSION DevExt;
194
195 UNICODE_STRING ShortNameU;
196
197 WCHAR *ObjectName; /* point on filename (250 chars max) in PathName */
198 UNICODE_STRING PathName; /* path+filename 260 max */
199 WCHAR PathNameBuffer[MAX_PATH]; /* Buffer for PathName */
200 WCHAR ShortNameBuffer[13];
201
202 LIST_ENTRY FcbListEntry;
203 struct _FCB* ParentFcb;
204
205 ULONG DirIndex;
206
207 LARGE_INTEGER IndexNumber; /* HighPart: Parent directory start sector */
208 /* LowPart: Directory record offset in the parent directory file */
209
210 LONG RefCount;
211 ULONG Flags;
212
213 DIR_RECORD Entry;
214
215 ERESOURCE NameListResource;
216 LIST_ENTRY ShortNameList;
217 } FCB, *PFCB;
218
219
220 typedef struct _CCB
221 {
222 LIST_ENTRY NextCCB;
223 PFILE_OBJECT PtrFileObject;
224 LARGE_INTEGER CurrentByteOffset;
225 /* for DirectoryControl */
226 ULONG Entry;
227 ULONG Offset;
228 /* for DirectoryControl */
229 UNICODE_STRING DirectorySearchPattern;
230 ULONG LastCluster;
231 ULONG LastOffset;
232 } CCB, *PCCB;
233
234 #define CDFS_TAG 'sfdC'
235 #define CDFS_CCB_TAG 'ccdC'
236 #define CDFS_NONPAGED_FCB_TAG 'nfdC'
237 #define CDFS_SHORT_NAME_TAG 'sgdC'
238 #define CDFS_SEARCH_PATTERN_TAG 'eedC'
239 #define CDFS_FILENAME_TAG 'nFdC'
240
241 typedef struct
242 {
243 PDRIVER_OBJECT DriverObject;
244 PDEVICE_OBJECT DeviceObject;
245 ULONG Flags;
246 CACHE_MANAGER_CALLBACKS CacheMgrCallbacks;
247 FAST_IO_DISPATCH FastIoDispatch;
248 } CDFS_GLOBAL_DATA, *PCDFS_GLOBAL_DATA;
249
250 extern PCDFS_GLOBAL_DATA CdfsGlobalData;
251
252
253 /* cleanup.c */
254
255 DRIVER_DISPATCH CdfsCleanup;
256
257 NTSTATUS
258 NTAPI
259 CdfsCleanup(PDEVICE_OBJECT DeviceObject,
260 PIRP Irp);
261
262
263 /* close.c */
264
265 DRIVER_DISPATCH CdfsClose;
266
267 NTSTATUS
268 NTAPI
269 CdfsClose(PDEVICE_OBJECT DeviceObject,
270 PIRP Irp);
271
272 NTSTATUS
273 CdfsCloseFile(PDEVICE_EXTENSION DeviceExt,
274 PFILE_OBJECT FileObject);
275
276
277 /* common.c */
278
279 NTSTATUS
280 CdfsReadSectors(IN PDEVICE_OBJECT DeviceObject,
281 IN ULONG DiskSector,
282 IN ULONG SectorCount,
283 IN OUT PUCHAR Buffer,
284 IN BOOLEAN Override);
285
286 NTSTATUS
287 CdfsDeviceIoControl (IN PDEVICE_OBJECT DeviceObject,
288 IN ULONG CtlCode,
289 IN PVOID InputBuffer,
290 IN ULONG InputBufferSize,
291 IN OUT PVOID OutputBuffer,
292 IN OUT PULONG pOutputBufferSize,
293 IN BOOLEAN Override);
294
295 /* create.c */
296
297 DRIVER_DISPATCH CdfsCreate;
298
299 NTSTATUS
300 NTAPI
301 CdfsCreate(PDEVICE_OBJECT DeviceObject,
302 PIRP Irp);
303
304 /* devctrl.c */
305
306 DRIVER_DISPATCH CdfsDeviceControl;
307
308 NTSTATUS NTAPI
309 CdfsDeviceControl(PDEVICE_OBJECT DeviceObject,
310 PIRP Irp);
311
312 /* dirctl.c */
313
314 DRIVER_DISPATCH CdfsDirectoryControl;
315
316 NTSTATUS
317 NTAPI
318 CdfsDirectoryControl(PDEVICE_OBJECT DeviceObject,
319 PIRP Irp);
320
321
322 /* fcb.c */
323
324 PFCB
325 CdfsCreateFCB(PCWSTR FileName);
326
327 VOID
328 CdfsDestroyFCB(PFCB Fcb);
329
330 BOOLEAN
331 CdfsFCBIsDirectory(PFCB Fcb);
332
333 BOOLEAN
334 CdfsFCBIsRoot(PFCB Fcb);
335
336 VOID
337 CdfsGrabFCB(PDEVICE_EXTENSION Vcb,
338 PFCB Fcb);
339
340 VOID
341 CdfsReleaseFCB(PDEVICE_EXTENSION Vcb,
342 PFCB Fcb);
343
344 VOID
345 CdfsAddFCBToTable(PDEVICE_EXTENSION Vcb,
346 PFCB Fcb);
347
348 PFCB
349 CdfsGrabFCBFromTable(PDEVICE_EXTENSION Vcb,
350 PUNICODE_STRING FileName);
351
352 NTSTATUS
353 CdfsFCBInitializeCache(PVCB Vcb,
354 PFCB Fcb);
355
356 PFCB
357 CdfsMakeRootFCB(PDEVICE_EXTENSION Vcb);
358
359 PFCB
360 CdfsOpenRootFCB(PDEVICE_EXTENSION Vcb);
361
362 NTSTATUS
363 CdfsMakeFCBFromDirEntry(PVCB Vcb,
364 PFCB DirectoryFCB,
365 PWSTR LongName,
366 PWSTR ShortName,
367 PDIR_RECORD Record,
368 ULONG DirectorySector,
369 ULONG DirectoryOffset,
370 PFCB * fileFCB);
371
372 NTSTATUS
373 CdfsAttachFCBToFileObject(PDEVICE_EXTENSION Vcb,
374 PFCB Fcb,
375 PFILE_OBJECT FileObject);
376
377 NTSTATUS
378 CdfsDirFindFile(PDEVICE_EXTENSION DeviceExt,
379 PFCB DirectoryFcb,
380 PUNICODE_STRING FileToFind,
381 PFCB *FoundFCB);
382
383 NTSTATUS
384 CdfsGetFCBForFile(PDEVICE_EXTENSION Vcb,
385 PFCB *pParentFCB,
386 PFCB *pFCB,
387 PUNICODE_STRING FileName);
388
389
390 /* finfo.c */
391
392 DRIVER_DISPATCH CdfsQueryInformation;
393
394 NTSTATUS
395 NTAPI
396 CdfsQueryInformation(PDEVICE_OBJECT DeviceObject,
397 PIRP Irp);
398
399 DRIVER_DISPATCH CdfsSetInformation;
400
401 NTSTATUS
402 NTAPI
403 CdfsSetInformation(PDEVICE_OBJECT DeviceObject,
404 PIRP Irp);
405
406
407 /* fsctl.c */
408
409 DRIVER_DISPATCH CdfsFileSystemControl;
410
411 NTSTATUS NTAPI
412 CdfsFileSystemControl(PDEVICE_OBJECT DeviceObject,
413 PIRP Irp);
414
415
416 /* misc.c */
417
418 VOID
419 CdfsSwapString(PWCHAR Out,
420 PUCHAR In,
421 ULONG Count);
422
423 VOID
424 CdfsDateTimeToSystemTime(PFCB Fcb,
425 PLARGE_INTEGER SystemTime);
426
427 VOID
428 CdfsFileFlagsToAttributes(PFCB Fcb,
429 PULONG FileAttributes);
430
431 VOID
432 CdfsShortNameCacheGet
433 (PFCB DirectoryFcb,
434 PLARGE_INTEGER StreamOffset,
435 PUNICODE_STRING LongName,
436 PUNICODE_STRING ShortName);
437
438 /* rw.c */
439
440 DRIVER_DISPATCH CdfsRead;
441
442 NTSTATUS
443 NTAPI
444 CdfsRead(PDEVICE_OBJECT DeviceObject,
445 PIRP Irp);
446
447 DRIVER_DISPATCH CdfsWrite;
448
449 NTSTATUS
450 NTAPI
451 CdfsWrite(PDEVICE_OBJECT DeviceObject,
452 PIRP Irp);
453
454
455 /* volinfo.c */
456
457 DRIVER_DISPATCH CdfsQueryVolumeInformation;
458
459 NTSTATUS
460 NTAPI
461 CdfsQueryVolumeInformation(PDEVICE_OBJECT DeviceObject,
462 PIRP Irp);
463
464 DRIVER_DISPATCH CdfsSetVolumeInformation;
465
466 NTSTATUS
467 NTAPI
468 CdfsSetVolumeInformation(PDEVICE_OBJECT DeviceObject,
469 PIRP Irp);
470
471 /* cdfs.c */
472
473 NTSTATUS NTAPI
474 DriverEntry(PDRIVER_OBJECT DriverObject,
475 PUNICODE_STRING RegistryPath);
476
477 BOOLEAN NTAPI
478 CdfsAcquireForLazyWrite(IN PVOID Context,
479 IN BOOLEAN Wait);
480
481 VOID NTAPI
482 CdfsReleaseFromLazyWrite(IN PVOID Context);
483
484 FAST_IO_READ CdfsFastIoRead;
485 FAST_IO_WRITE CdfsFastIoWrite;
486
487 #endif /* CDFS_H */