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