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