[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 _CDFS_GLOBAL_DATA
242 {
243 PDRIVER_OBJECT DriverObject;
244 PDEVICE_OBJECT DeviceObject;
245 ULONG Flags;
246 CACHE_MANAGER_CALLBACKS CacheMgrCallbacks;
247 FAST_IO_DISPATCH FastIoDispatch;
248 NPAGED_LOOKASIDE_LIST IrpContextLookasideList;
249 } CDFS_GLOBAL_DATA, *PCDFS_GLOBAL_DATA;
250
251 #define IRPCONTEXT_CANWAIT 0x1
252 #define IRPCONTEXT_COMPLETE 0x2
253 #define IRPCONTEXT_QUEUE 0x4
254
255 typedef struct _CDFS_IRP_CONTEXT
256 {
257 // NTFSIDENTIFIER Identifier;
258 ULONG Flags;
259 PIO_STACK_LOCATION Stack;
260 UCHAR MajorFunction;
261 UCHAR MinorFunction;
262 WORK_QUEUE_ITEM WorkQueueItem;
263 PIRP Irp;
264 BOOLEAN IsTopLevel;
265 PDEVICE_OBJECT DeviceObject;
266 PFILE_OBJECT FileObject;
267 NTSTATUS SavedExceptionCode;
268 CCHAR PriorityBoost;
269 } CDFS_IRP_CONTEXT, *PCDFS_IRP_CONTEXT;
270
271
272 extern PCDFS_GLOBAL_DATA CdfsGlobalData;
273
274 /* cdfs.c */
275
276 NTSTATUS
277 NTAPI
278 DriverEntry(
279 PDRIVER_OBJECT DriverObject,
280 PUNICODE_STRING RegistryPath);
281
282 /* cleanup.c */
283
284 NTSTATUS
285 NTAPI
286 CdfsCleanup(
287 PCDFS_IRP_CONTEXT IrpContext);
288
289
290 /* close.c */
291
292 NTSTATUS
293 NTAPI
294 CdfsClose(
295 PCDFS_IRP_CONTEXT IrpContext);
296
297 NTSTATUS
298 CdfsCloseFile(PDEVICE_EXTENSION DeviceExt,
299 PFILE_OBJECT FileObject);
300
301
302 /* common.c */
303
304 NTSTATUS
305 CdfsReadSectors(IN PDEVICE_OBJECT DeviceObject,
306 IN ULONG DiskSector,
307 IN ULONG SectorCount,
308 IN OUT PUCHAR Buffer,
309 IN BOOLEAN Override);
310
311 NTSTATUS
312 CdfsDeviceIoControl (IN PDEVICE_OBJECT DeviceObject,
313 IN ULONG CtlCode,
314 IN PVOID InputBuffer,
315 IN ULONG InputBufferSize,
316 IN OUT PVOID OutputBuffer,
317 IN OUT PULONG pOutputBufferSize,
318 IN BOOLEAN Override);
319
320 /* create.c */
321
322 DRIVER_DISPATCH CdfsCreate;
323
324 NTSTATUS
325 NTAPI
326 CdfsCreate(PDEVICE_OBJECT DeviceObject,
327 PIRP Irp);
328
329 /* devctrl.c */
330
331 NTSTATUS NTAPI
332 CdfsDeviceControl(
333 PCDFS_IRP_CONTEXT IrpContext);
334
335 /* dirctl.c */
336
337 NTSTATUS
338 NTAPI
339 CdfsDirectoryControl(
340 PCDFS_IRP_CONTEXT IrpContext);
341
342 /* dispatch.c */
343
344 DRIVER_DISPATCH CdfsFsdDispatch;
345 NTSTATUS
346 NTAPI
347 CdfsFsdDispatch(
348 PDEVICE_OBJECT DeviceObject,
349 PIRP Irp);
350
351 /* fastio.c */
352
353 BOOLEAN
354 NTAPI
355 CdfsAcquireForLazyWrite(IN PVOID Context,
356 IN BOOLEAN Wait);
357
358 VOID
359 NTAPI
360 CdfsReleaseFromLazyWrite(IN PVOID Context);
361
362 FAST_IO_CHECK_IF_POSSIBLE CdfsFastIoCheckIfPossible;
363 FAST_IO_READ CdfsFastIoRead;
364 FAST_IO_WRITE CdfsFastIoWrite;
365
366 /* fcb.c */
367
368 PFCB
369 CdfsCreateFCB(PCWSTR FileName);
370
371 VOID
372 CdfsDestroyFCB(PFCB Fcb);
373
374 BOOLEAN
375 CdfsFCBIsDirectory(PFCB Fcb);
376
377 BOOLEAN
378 CdfsFCBIsRoot(PFCB Fcb);
379
380 VOID
381 CdfsGrabFCB(PDEVICE_EXTENSION Vcb,
382 PFCB Fcb);
383
384 VOID
385 CdfsReleaseFCB(PDEVICE_EXTENSION Vcb,
386 PFCB Fcb);
387
388 VOID
389 CdfsAddFCBToTable(PDEVICE_EXTENSION Vcb,
390 PFCB Fcb);
391
392 PFCB
393 CdfsGrabFCBFromTable(PDEVICE_EXTENSION Vcb,
394 PUNICODE_STRING FileName);
395
396 NTSTATUS
397 CdfsFCBInitializeCache(PVCB Vcb,
398 PFCB Fcb);
399
400 PFCB
401 CdfsMakeRootFCB(PDEVICE_EXTENSION Vcb);
402
403 PFCB
404 CdfsOpenRootFCB(PDEVICE_EXTENSION Vcb);
405
406 NTSTATUS
407 CdfsMakeFCBFromDirEntry(PVCB Vcb,
408 PFCB DirectoryFCB,
409 PWSTR LongName,
410 PWSTR ShortName,
411 PDIR_RECORD Record,
412 ULONG DirectorySector,
413 ULONG DirectoryOffset,
414 PFCB * fileFCB);
415
416 NTSTATUS
417 CdfsAttachFCBToFileObject(PDEVICE_EXTENSION Vcb,
418 PFCB Fcb,
419 PFILE_OBJECT FileObject);
420
421 NTSTATUS
422 CdfsDirFindFile(PDEVICE_EXTENSION DeviceExt,
423 PFCB DirectoryFcb,
424 PUNICODE_STRING FileToFind,
425 PFCB *FoundFCB);
426
427 NTSTATUS
428 CdfsGetFCBForFile(PDEVICE_EXTENSION Vcb,
429 PFCB *pParentFCB,
430 PFCB *pFCB,
431 PUNICODE_STRING FileName);
432
433
434 /* finfo.c */
435
436 NTSTATUS
437 NTAPI
438 CdfsQueryInformation(
439 PCDFS_IRP_CONTEXT IrpContext);
440
441 NTSTATUS
442 NTAPI
443 CdfsSetInformation(
444 PCDFS_IRP_CONTEXT IrpContext);
445
446
447 /* fsctl.c */
448
449 NTSTATUS NTAPI
450 CdfsFileSystemControl(
451 PCDFS_IRP_CONTEXT IrpContext);
452
453
454 /* misc.c */
455
456 BOOLEAN
457 CdfsIsIrpTopLevel(
458 PIRP Irp);
459
460 PCDFS_IRP_CONTEXT
461 CdfsAllocateIrpContext(
462 PDEVICE_OBJECT DeviceObject,
463 PIRP Irp);
464
465 VOID
466 CdfsSwapString(PWCHAR Out,
467 PUCHAR In,
468 ULONG Count);
469
470 VOID
471 CdfsDateTimeToSystemTime(PFCB Fcb,
472 PLARGE_INTEGER SystemTime);
473
474 VOID
475 CdfsFileFlagsToAttributes(PFCB Fcb,
476 PULONG FileAttributes);
477
478 VOID
479 CdfsShortNameCacheGet
480 (PFCB DirectoryFcb,
481 PLARGE_INTEGER StreamOffset,
482 PUNICODE_STRING LongName,
483 PUNICODE_STRING ShortName);
484
485 /* rw.c */
486
487 NTSTATUS
488 NTAPI
489 CdfsRead(
490 PCDFS_IRP_CONTEXT IrpContext);
491
492 NTSTATUS
493 NTAPI
494 CdfsWrite(
495 PCDFS_IRP_CONTEXT IrpContext);
496
497
498 /* volinfo.c */
499
500 NTSTATUS
501 NTAPI
502 CdfsQueryVolumeInformation(
503 PCDFS_IRP_CONTEXT IrpContext);
504
505 NTSTATUS
506 NTAPI
507 CdfsSetVolumeInformation(
508 PCDFS_IRP_CONTEXT IrpContext);
509
510 #endif /* CDFS_H */