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