fixed some more warnings when compiled with -Wwrite-strings
[reactos.git] / reactos / drivers / fs / ntfs / ntfs.h
1 #ifndef NTFS_H
2 #define NTFS_H
3
4 #include <ddk/ntddk.h>
5 #include <ddk/ntifs.h>
6 #include <ddk/ntdddisk.h>
7 #include <ccros.h>
8
9 #define USE_ROS_CC_AND_FS
10
11
12 #define CACHEPAGESIZE(pDeviceExt) \
13 ((pDeviceExt)->NtfsInfo.BytesPerCluster > PAGE_SIZE ? \
14 (pDeviceExt)->NtfsInfo.BytesPerCluster : PAGE_SIZE)
15
16 #ifndef TAG
17 #define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
18 #endif
19
20 #define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
21
22
23 typedef struct _BOOT_SECTOR
24 {
25 UCHAR Magic[3]; // 0x00
26 UCHAR OemName[8]; // 0x03
27 USHORT BytesPerSector; // 0x0B
28 UCHAR SectorsPerCluster; // 0x0D
29 UCHAR Unused0[7]; // 0x0E
30 UCHAR MediaId; // 0x15
31 UCHAR Unused1[2]; // 0x16
32 USHORT SectorsPerTrack;
33 USHORT Heads;
34 UCHAR Unused2[8];
35 UCHAR Unknown0[4]; /* always 80 00 80 00 */
36 ULONGLONG SectorCount;
37 ULONGLONG MftLocation;
38 ULONGLONG MftMirrLocation;
39 CHAR ClustersPerMftRecord;
40 BYTE Unused3[3];
41 CHAR ClustersPerIndexRecord;
42 BYTE Unused4[3];
43 ULONGLONG SerialNumber; // 0x48
44 UCHAR BootCode[432]; // 0x50
45 } __attribute__((packed)) BOOT_SECTOR, *PBOOT_SECTOR;
46
47 //typedef struct _BootSector BootSector;
48
49
50
51
52
53 typedef struct _NTFS_INFO
54 {
55 ULONG BytesPerSector;
56 ULONG SectorsPerCluster;
57 ULONG BytesPerCluster;
58 ULONGLONG SectorCount;
59 ULARGE_INTEGER MftStart;
60 ULARGE_INTEGER MftMirrStart;
61 ULONG BytesPerFileRecord;
62
63 ULONGLONG SerialNumber;
64 USHORT VolumeLabelLength;
65 WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH];
66 UCHAR MajorVersion;
67 UCHAR MinorVersion;
68 USHORT Flags;
69
70 } NTFS_INFO, *PNTFS_INFO;
71
72
73 typedef struct
74 {
75 ERESOURCE DirResource;
76 // ERESOURCE FatResource;
77
78 KSPIN_LOCK FcbListLock;
79 LIST_ENTRY FcbListHead;
80
81 PVPB Vpb;
82 PDEVICE_OBJECT StorageDevice;
83 PFILE_OBJECT StreamFileObject;
84
85 NTFS_INFO NtfsInfo;
86
87
88 } DEVICE_EXTENSION, *PDEVICE_EXTENSION, VCB, *PVCB;
89
90
91 #define FCB_CACHE_INITIALIZED 0x0001
92 #define FCB_IS_VOLUME_STREAM 0x0002
93 #define FCB_IS_VOLUME 0x0004
94
95 typedef struct _FCB
96 {
97 FSRTL_COMMON_FCB_HEADER RFCB;
98 SECTION_OBJECT_POINTERS SectionObjectPointers;
99
100 PFILE_OBJECT FileObject;
101 PDEVICE_EXTENSION DevExt;
102
103 WCHAR *ObjectName; /* point on filename (250 chars max) in PathName */
104 WCHAR PathName[MAX_PATH]; /* path+filename 260 max */
105
106 ERESOURCE PagingIoResource;
107 ERESOURCE MainResource;
108
109 LIST_ENTRY FcbListEntry;
110 struct _FCB* ParentFcb;
111
112 ULONG DirIndex;
113
114 LONG RefCount;
115 ULONG Flags;
116
117 // DIR_RECORD Entry;
118
119
120 } FCB, *PFCB;
121
122
123 typedef struct _CCB
124 {
125 LIST_ENTRY NextCCB;
126 PFILE_OBJECT PtrFileObject;
127 LARGE_INTEGER CurrentByteOffset;
128 /* for DirectoryControl */
129 ULONG Entry;
130 /* for DirectoryControl */
131 PWCHAR DirectorySearchPattern;
132 ULONG LastCluster;
133 ULONG LastOffset;
134 } CCB, *PCCB;
135
136 #define TAG_CCB TAG('I', 'C', 'C', 'B')
137
138 typedef struct
139 {
140 PDRIVER_OBJECT DriverObject;
141 PDEVICE_OBJECT DeviceObject;
142 ULONG Flags;
143 } NTFS_GLOBAL_DATA, *PNTFS_GLOBAL_DATA;
144
145
146 typedef enum
147 {
148 AttributeStandardInformation = 0x10,
149 AttributeAttributeList = 0x20,
150 AttributeFileName = 0x30,
151 AttributeObjectId = 0x40,
152 AttributeSecurityDescriptor = 0x50,
153 AttributeVolumeName = 0x60,
154 AttributeVolumeInformation = 0x70,
155 AttributeData = 0x80,
156 AttributeIndexRoot = 0x90,
157 AttributeIndexAllocation = 0xA0,
158 AttributeBitmap = 0xB0,
159 AttributeReparsePoint = 0xC0,
160 AttributeEAInformation = 0xD0,
161 AttributeEA = 0xE0,
162 AttributePropertySet = 0xF0,
163 AttributeLoggedUtilityStream = 0x100
164 } ATTRIBUTE_TYPE, *PATTRIBUTE_TYPE;
165
166
167 typedef struct
168 {
169 ULONG Type; /* Magic number 'FILE' */
170 USHORT UsaOffset; /* Offset to the update sequence */
171 USHORT UsaCount; /* Size in words of Update Sequence Number & Array (S) */
172 ULONGLONG Lsn; /* $LogFile Sequence Number (LSN) */
173 } NTFS_RECORD_HEADER, *PNTFS_RECORD_HEADER;
174
175 /* NTFS_RECORD_HEADER.Type */
176 #define NRH_FILE_TYPE 0x454C4946 /* 'FILE' */
177
178
179 typedef struct
180 {
181 NTFS_RECORD_HEADER Ntfs;
182 USHORT SequenceNumber; /* Sequence number */
183 USHORT LinkCount; /* Hard link count */
184 USHORT AttributeOffset; /* Offset to the first Attribute */
185 USHORT Flags; /* Flags */
186 ULONG BytesInUse; /* Real size of the FILE record */
187 ULONG BytesAllocated; /* Allocated size of the FILE record */
188 ULONGLONG BaseFileRecord; /* File reference to the base FILE record */
189 USHORT NextAttributeNumber; /* Next Attribute Id */
190 USHORT Pading; /* Align to 4 byte boundary (XP) */
191 ULONG MFTRecordNumber; /* Number of this MFT Record (XP) */
192 } FILE_RECORD_HEADER, *PFILE_RECORD_HEADER;
193
194 /* Flags in FILE_RECORD_HEADER */
195
196 #define FRH_IN_USE 0x0001 /* Record is in use */
197 #define FRH_DIRECTORY 0x0002 /* Record is a directory */
198 #define FRH_UNKNOWN1 0x0004 /* Don't know */
199 #define FRH_UNKNOWN2 0x0008 /* Don't know */
200
201 typedef struct
202 {
203 ATTRIBUTE_TYPE AttributeType;
204 ULONG Length;
205 BOOLEAN Nonresident;
206 UCHAR NameLength;
207 USHORT NameOffset;
208 USHORT Flags;
209 USHORT AttributeNumber;
210 } ATTRIBUTE, *PATTRIBUTE;
211
212 typedef struct
213 {
214 ATTRIBUTE Attribute;
215 ULONG ValueLength;
216 USHORT ValueOffset;
217 UCHAR Flags;
218 // UCHAR Padding0;
219 } RESIDENT_ATTRIBUTE, *PRESIDENT_ATTRIBUTE;
220
221 typedef struct
222 {
223 ATTRIBUTE Attribute;
224 ULONGLONG StartVcn; // LowVcn
225 ULONGLONG LastVcn; // HighVcn
226 USHORT RunArrayOffset;
227 USHORT CompressionUnit;
228 ULONG Padding0;
229 UCHAR IndexedFlag;
230 ULONGLONG AllocatedSize;
231 ULONGLONG DataSize;
232 ULONGLONG InitializedSize;
233 ULONGLONG CompressedSize;
234 } NONRESIDENT_ATTRIBUTE, *PNONRESIDENT_ATTRIBUTE;
235
236
237 typedef struct
238 {
239 ULONGLONG CreationTime;
240 ULONGLONG ChangeTime;
241 ULONGLONG LastWriteTime;
242 ULONGLONG LastAccessTime;
243 ULONG FileAttribute;
244 ULONG AlignmentOrReserved[3];
245 #if 0
246 ULONG QuotaId;
247 ULONG SecurityId;
248 ULONGLONG QuotaCharge;
249 USN Usn;
250 #endif
251 } STANDARD_INFORMATION, *PSTANDARD_INFORMATION;
252
253
254 typedef struct
255 {
256 ATTRIBUTE_TYPE AttributeType;
257 USHORT Length;
258 UCHAR NameLength;
259 UCHAR NameOffset;
260 ULONGLONG StartVcn; // LowVcn
261 ULONGLONG FileReferenceNumber;
262 USHORT AttributeNumber;
263 USHORT AlignmentOrReserved[3];
264 } ATTRIBUTE_LIST, *PATTRIBUTE_LIST;
265
266
267 typedef struct
268 {
269 ULONGLONG DirectoryFileReferenceNumber;
270 ULONGLONG CreationTime;
271 ULONGLONG ChangeTime;
272 ULONGLONG LastWriteTime;
273 ULONGLONG LastAccessTime;
274 ULONGLONG AllocatedSize;
275 ULONGLONG DataSize;
276 ULONG FileAttributes;
277 ULONG AlignmentOrReserved;
278 UCHAR NameLength;
279 UCHAR NameType;
280 WCHAR Name[1];
281 } FILENAME_ATTRIBUTE, *PFILENAME_ATTRIBUTE;
282
283 typedef struct
284 {
285 ULONGLONG Unknown1;
286 UCHAR MajorVersion;
287 UCHAR MinorVersion;
288 USHORT Flags;
289 ULONG Unknown2;
290 } VOLINFO_ATTRIBUTE, *PVOLINFO_ATTRIBUTE;
291
292
293 extern PNTFS_GLOBAL_DATA NtfsGlobalData;
294
295 //int CdfsStrcmpi( wchar_t *str1, wchar_t *str2 );
296 //void CdfsWstrcpy( wchar_t *str1, wchar_t *str2, int max );
297
298
299 /* attrib.c */
300
301 //VOID
302 //NtfsDumpAttribute(PATTRIBUTE Attribute);
303
304 //LONGLONG RunLCN(PUCHAR run);
305
306 //ULONG RunLength(PUCHAR run);
307
308 BOOLEAN
309 FindRun (PNONRESIDENT_ATTRIBUTE NresAttr,
310 ULONGLONG vcn,
311 PULONGLONG lcn,
312 PULONGLONG count);
313
314 VOID
315 NtfsDumpFileAttributes (PFILE_RECORD_HEADER FileRecord);
316
317 /* blockdev.c */
318
319 NTSTATUS
320 NtfsReadSectors(IN PDEVICE_OBJECT DeviceObject,
321 IN ULONG DiskSector,
322 IN ULONG SectorCount,
323 IN ULONG SectorSize,
324 IN OUT PUCHAR Buffer,
325 IN BOOLEAN Override);
326
327 NTSTATUS
328 NtfsDeviceIoControl(IN PDEVICE_OBJECT DeviceObject,
329 IN ULONG ControlCode,
330 IN PVOID InputBuffer,
331 IN ULONG InputBufferSize,
332 IN OUT PVOID OutputBuffer,
333 IN OUT PULONG OutputBufferSize,
334 IN BOOLEAN Override);
335
336 /* close.c */
337
338 NTSTATUS STDCALL
339 NtfsClose(PDEVICE_OBJECT DeviceObject,
340 PIRP Irp);
341
342 /* create.c */
343
344 NTSTATUS STDCALL
345 NtfsCreate(PDEVICE_OBJECT DeviceObject,
346 PIRP Irp);
347
348
349 /* dirctl.c */
350
351 NTSTATUS STDCALL
352 NtfsDirectoryControl(PDEVICE_OBJECT DeviceObject,
353 PIRP Irp);
354
355 /* fcb.c */
356
357 PFCB
358 NtfsCreateFCB(PCWSTR FileName);
359
360 VOID
361 NtfsDestroyFCB(PFCB Fcb);
362
363 BOOLEAN
364 NtfsFCBIsDirectory(PFCB Fcb);
365
366 BOOLEAN
367 NtfsFCBIsRoot(PFCB Fcb);
368
369 VOID
370 NtfsGrabFCB(PDEVICE_EXTENSION Vcb,
371 PFCB Fcb);
372
373 VOID
374 NtfsReleaseFCB(PDEVICE_EXTENSION Vcb,
375 PFCB Fcb);
376
377 VOID
378 NtfsAddFCBToTable(PDEVICE_EXTENSION Vcb,
379 PFCB Fcb);
380
381 PFCB
382 NtfsGrabFCBFromTable(PDEVICE_EXTENSION Vcb,
383 PCWSTR FileName);
384
385 NTSTATUS
386 NtfsFCBInitializeCache(PVCB Vcb,
387 PFCB Fcb);
388
389 PFCB
390 NtfsMakeRootFCB(PDEVICE_EXTENSION Vcb);
391
392 PFCB
393 NtfsOpenRootFCB(PDEVICE_EXTENSION Vcb);
394
395 NTSTATUS
396 NtfsAttachFCBToFileObject(PDEVICE_EXTENSION Vcb,
397 PFCB Fcb,
398 PFILE_OBJECT FileObject);
399
400 NTSTATUS
401 NtfsGetFCBForFile(PDEVICE_EXTENSION Vcb,
402 PFCB *pParentFCB,
403 PFCB *pFCB,
404 const PWSTR pFileName);
405
406
407 /* finfo.c */
408
409 NTSTATUS STDCALL
410 NtfsQueryInformation(PDEVICE_OBJECT DeviceObject,
411 PIRP Irp);
412
413
414 /* fsctl.c */
415
416 NTSTATUS STDCALL
417 NtfsFileSystemControl(PDEVICE_OBJECT DeviceObject,
418 PIRP Irp);
419
420
421 /* mft.c */
422 NTSTATUS
423 NtfsOpenMft (PDEVICE_EXTENSION Vcb);
424
425
426 VOID
427 ReadAttribute(PATTRIBUTE attr, PVOID buffer, PDEVICE_EXTENSION Vcb,
428 PDEVICE_OBJECT DeviceObject);
429
430 ULONG
431 AttributeDataLength(PATTRIBUTE attr);
432
433 ULONG
434 AttributeAllocatedLength (PATTRIBUTE Attribute);
435
436 NTSTATUS
437 ReadFileRecord (PDEVICE_EXTENSION Vcb,
438 ULONG index,
439 PFILE_RECORD_HEADER file,
440 PFILE_RECORD_HEADER Mft);
441
442 PATTRIBUTE
443 FindAttribute(PFILE_RECORD_HEADER file,
444 ATTRIBUTE_TYPE type,
445 PWSTR name);
446
447 ULONG
448 AttributeLengthAllocated(PATTRIBUTE attr);
449
450 VOID
451 ReadVCN (PDEVICE_EXTENSION Vcb,
452 PFILE_RECORD_HEADER file,
453 ATTRIBUTE_TYPE type,
454 ULONGLONG vcn,
455 ULONG count,
456 PVOID buffer);
457
458
459 VOID FixupUpdateSequenceArray(PFILE_RECORD_HEADER file);
460
461 VOID
462 ReadExternalAttribute (PDEVICE_EXTENSION Vcb,
463 PNONRESIDENT_ATTRIBUTE NresAttr,
464 ULONGLONG vcn,
465 ULONG count,
466 PVOID buffer);
467
468 NTSTATUS
469 ReadLCN (PDEVICE_EXTENSION Vcb,
470 ULONGLONG lcn,
471 ULONG count,
472 PVOID buffer);
473
474
475 VOID
476 EnumerAttribute(PFILE_RECORD_HEADER file,
477 PDEVICE_EXTENSION Vcb,
478 PDEVICE_OBJECT DeviceObject);
479
480 #if 0
481 /* misc.c */
482
483 BOOLEAN
484 wstrcmpjoki(PWSTR s1, PWSTR s2);
485
486 VOID
487 CdfsSwapString(PWCHAR Out,
488 PUCHAR In,
489 ULONG Count);
490
491 VOID
492 CdfsDateTimeToFileTime(PFCB Fcb,
493 TIME *FileTime);
494
495 VOID
496 CdfsFileFlagsToAttributes(PFCB Fcb,
497 PULONG FileAttributes);
498 #endif
499
500 /* rw.c */
501
502 NTSTATUS STDCALL
503 NtfsRead(PDEVICE_OBJECT DeviceObject,
504 PIRP Irp);
505
506 NTSTATUS STDCALL
507 NtfsWrite(PDEVICE_OBJECT DeviceObject,
508 PIRP Irp);
509
510
511 /* volinfo.c */
512
513 NTSTATUS STDCALL
514 NtfsQueryVolumeInformation(PDEVICE_OBJECT DeviceObject,
515 PIRP Irp);
516
517 NTSTATUS STDCALL
518 NtfsSetVolumeInformation(PDEVICE_OBJECT DeviceObject,
519 PIRP Irp);
520
521 /* ntfs.c */
522
523 NTSTATUS STDCALL
524 DriverEntry(PDRIVER_OBJECT DriverObject,
525 PUNICODE_STRING RegistryPath);
526
527 #endif /* NTFS_H */