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