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