aba8b291969378d88b58f552c16a095c30bffc5d
[reactos.git] / drivers / filesystems / ntfs / ntfs.h
1 #ifndef NTFS_H
2 #define NTFS_H
3
4 #include <ntifs.h>
5 #include <pseh/pseh2.h>
6
7 #ifdef __GNUC__
8 #define INIT_SECTION __attribute__((section ("INIT")))
9 #else
10 #define INIT_SECTION /* Done via alloc_text for MSC */
11 #endif
12
13 #define CACHEPAGESIZE(pDeviceExt) \
14 ((pDeviceExt)->NtfsInfo.UCHARsPerCluster > PAGE_SIZE ? \
15 (pDeviceExt)->NtfsInfo.UCHARsPerCluster : PAGE_SIZE)
16
17 #define TAG_NTFS 'SFTN'
18
19 #define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
20 #define ROUND_DOWN(N, S) ((N) - ((N) % (S)))
21
22 #define DEVICE_NAME L"\\Ntfs"
23
24 #include <pshpack1.h>
25 typedef struct _BIOS_PARAMETERS_BLOCK
26 {
27 USHORT BytesPerSector; // 0x0B
28 UCHAR SectorsPerCluster; // 0x0D
29 UCHAR Unused0[7]; // 0x0E, checked when volume is mounted
30 UCHAR MediaId; // 0x15
31 UCHAR Unused1[2]; // 0x16
32 USHORT SectorsPerTrack; // 0x18
33 USHORT Heads; // 0x1A
34 UCHAR Unused2[4]; // 0x1C
35 UCHAR Unused3[4]; // 0x20, checked when volume is mounted
36 } BIOS_PARAMETERS_BLOCK, *PBIOS_PARAMETERS_BLOCK;
37
38 typedef struct _EXTENDED_BIOS_PARAMETERS_BLOCK
39 {
40 USHORT Unknown[2]; // 0x24, always 80 00 80 00
41 ULONGLONG SectorCount; // 0x28
42 ULONGLONG MftLocation; // 0x30
43 ULONGLONG MftMirrLocation; // 0x38
44 CHAR ClustersPerMftRecord; // 0x40
45 UCHAR Unused4[3]; // 0x41
46 CHAR ClustersPerIndexRecord; // 0x44
47 UCHAR Unused5[3]; // 0x45
48 ULONGLONG SerialNumber; // 0x48
49 UCHAR Checksum[4]; // 0x50
50 } EXTENDED_BIOS_PARAMETERS_BLOCK, *PEXTENDED_BIOS_PARAMETERS_BLOCK;
51
52 typedef struct _BOOT_SECTOR
53 {
54 UCHAR Jump[3]; // 0x00
55 UCHAR OEMID[8]; // 0x03
56 BIOS_PARAMETERS_BLOCK BPB;
57 EXTENDED_BIOS_PARAMETERS_BLOCK EBPB;
58 UCHAR BootStrap[426]; // 0x54
59 USHORT EndSector; // 0x1FE
60 } BOOT_SECTOR, *PBOOT_SECTOR;
61 #include <poppack.h>
62
63 //typedef struct _BootSector BootSector;
64
65 typedef struct _NTFS_INFO
66 {
67 ULONG BytesPerSector;
68 ULONG SectorsPerCluster;
69 ULONG BytesPerCluster;
70 ULONGLONG SectorCount;
71 ULONGLONG ClusterCount;
72 ULARGE_INTEGER MftStart;
73 ULARGE_INTEGER MftMirrStart;
74 ULONG BytesPerFileRecord;
75 ULONG BytesPerIndexRecord;
76
77 ULONGLONG SerialNumber;
78 USHORT VolumeLabelLength;
79 WCHAR VolumeLabel[MAXIMUM_VOLUME_LABEL_LENGTH];
80 UCHAR MajorVersion;
81 UCHAR MinorVersion;
82 USHORT Flags;
83
84 ULONG MftZoneReservation;
85 } NTFS_INFO, *PNTFS_INFO;
86
87 #define NTFS_TYPE_CCB '20SF'
88 #define NTFS_TYPE_FCB '30SF'
89 #define NTFS_TYPE_VCB '50SF'
90 #define NTFS_TYPE_IRP_CONTEXT '60SF'
91 #define NTFS_TYPE_GLOBAL_DATA '70SF'
92
93 typedef struct
94 {
95 ULONG Type;
96 ULONG Size;
97 } NTFSIDENTIFIER, *PNTFSIDENTIFIER;
98
99 typedef struct
100 {
101 NTFSIDENTIFIER Identifier;
102
103 ERESOURCE DirResource;
104 // ERESOURCE FatResource;
105
106 KSPIN_LOCK FcbListLock;
107 LIST_ENTRY FcbListHead;
108
109 PVPB Vpb;
110 PDEVICE_OBJECT StorageDevice;
111 PFILE_OBJECT StreamFileObject;
112
113 struct _NTFS_ATTR_CONTEXT* MFTContext;
114 struct _FILE_RECORD_HEADER* MasterFileTable;
115 struct _FCB *VolumeFcb;
116
117 NTFS_INFO NtfsInfo;
118
119 ULONG MftDataOffset;
120 ULONG Flags;
121 ULONG OpenHandleCount;
122
123 } DEVICE_EXTENSION, *PDEVICE_EXTENSION, NTFS_VCB, *PNTFS_VCB;
124
125 #define VCB_VOLUME_LOCKED 0x0001
126
127 typedef struct
128 {
129 NTFSIDENTIFIER Identifier;
130 LIST_ENTRY NextCCB;
131 PFILE_OBJECT PtrFileObject;
132 LARGE_INTEGER CurrentByteOffset;
133 /* for DirectoryControl */
134 ULONG Entry;
135 /* for DirectoryControl */
136 PWCHAR DirectorySearchPattern;
137 ULONG LastCluster;
138 ULONG LastOffset;
139 } NTFS_CCB, *PNTFS_CCB;
140
141 #define TAG_CCB 'BCCI'
142 #define TAG_FCB 'BCFI'
143
144 typedef struct
145 {
146 NTFSIDENTIFIER Identifier;
147 ERESOURCE Resource;
148 PDRIVER_OBJECT DriverObject;
149 PDEVICE_OBJECT DeviceObject;
150 CACHE_MANAGER_CALLBACKS CacheMgrCallbacks;
151 ULONG Flags;
152 FAST_IO_DISPATCH FastIoDispatch;
153 NPAGED_LOOKASIDE_LIST IrpContextLookasideList;
154 NPAGED_LOOKASIDE_LIST FcbLookasideList;
155 BOOLEAN EnableWriteSupport;
156 } NTFS_GLOBAL_DATA, *PNTFS_GLOBAL_DATA;
157
158
159 typedef enum
160 {
161 AttributeStandardInformation = 0x10,
162 AttributeAttributeList = 0x20,
163 AttributeFileName = 0x30,
164 AttributeObjectId = 0x40,
165 AttributeSecurityDescriptor = 0x50,
166 AttributeVolumeName = 0x60,
167 AttributeVolumeInformation = 0x70,
168 AttributeData = 0x80,
169 AttributeIndexRoot = 0x90,
170 AttributeIndexAllocation = 0xA0,
171 AttributeBitmap = 0xB0,
172 AttributeReparsePoint = 0xC0,
173 AttributeEAInformation = 0xD0,
174 AttributeEA = 0xE0,
175 AttributePropertySet = 0xF0,
176 AttributeLoggedUtilityStream = 0x100,
177 AttributeEnd = 0xFFFFFFFF
178 } ATTRIBUTE_TYPE, *PATTRIBUTE_TYPE;
179
180 // FILE_RECORD_END seems to follow AttributeEnd in every file record starting with $Quota.
181 // No clue what data is being represented here.
182 #define FILE_RECORD_END 0x11477982
183
184 #define NTFS_FILE_MFT 0
185 #define NTFS_FILE_MFTMIRR 1
186 #define NTFS_FILE_LOGFILE 2
187 #define NTFS_FILE_VOLUME 3
188 #define NTFS_FILE_ATTRDEF 4
189 #define NTFS_FILE_ROOT 5
190 #define NTFS_FILE_BITMAP 6
191 #define NTFS_FILE_BOOT 7
192 #define NTFS_FILE_BADCLUS 8
193 #define NTFS_FILE_QUOTA 9
194 #define NTFS_FILE_UPCASE 10
195 #define NTFS_FILE_EXTEND 11
196 #define NTFS_FILE_FIRST_USER_FILE 16
197
198 #define NTFS_MFT_MASK 0x0000FFFFFFFFFFFFULL
199
200 #define COLLATION_BINARY 0x00
201 #define COLLATION_FILE_NAME 0x01
202 #define COLLATION_UNICODE_STRING 0x02
203 #define COLLATION_NTOFS_ULONG 0x10
204 #define COLLATION_NTOFS_SID 0x11
205 #define COLLATION_NTOFS_SECURITY_HASH 0x12
206 #define COLLATION_NTOFS_ULONGS 0x13
207
208 #define INDEX_ROOT_SMALL 0x0
209 #define INDEX_ROOT_LARGE 0x1
210
211 #define INDEX_NODE_SMALL 0x0
212 #define INDEX_NODE_LARGE 0x1
213
214 #define NTFS_INDEX_ENTRY_NODE 1
215 #define NTFS_INDEX_ENTRY_END 2
216
217 #define NTFS_FILE_NAME_POSIX 0
218 #define NTFS_FILE_NAME_WIN32 1
219 #define NTFS_FILE_NAME_DOS 2
220 #define NTFS_FILE_NAME_WIN32_AND_DOS 3
221
222 #define NTFS_FILE_TYPE_READ_ONLY 0x1
223 #define NTFS_FILE_TYPE_HIDDEN 0x2
224 #define NTFS_FILE_TYPE_SYSTEM 0x4
225 #define NTFS_FILE_TYPE_ARCHIVE 0x20
226 #define NTFS_FILE_TYPE_REPARSE 0x400
227 #define NTFS_FILE_TYPE_COMPRESSED 0x800
228 #define NTFS_FILE_TYPE_DIRECTORY 0x10000000
229
230 /* Indexed Flag in Resident attributes - still somewhat speculative */
231 #define RA_INDEXED 0x01
232
233 typedef struct
234 {
235 ULONG Type; /* Magic number 'FILE' */
236 USHORT UsaOffset; /* Offset to the update sequence */
237 USHORT UsaCount; /* Size in words of Update Sequence Number & Array (S) */
238 ULONGLONG Lsn; /* $LogFile Sequence Number (LSN) */
239 } NTFS_RECORD_HEADER, *PNTFS_RECORD_HEADER;
240
241 /* NTFS_RECORD_HEADER.Type */
242 #define NRH_FILE_TYPE 0x454C4946 /* 'FILE' */
243 #define NRH_INDX_TYPE 0x58444E49 /* 'INDX' */
244
245
246 typedef struct _FILE_RECORD_HEADER
247 {
248 NTFS_RECORD_HEADER Ntfs;
249 USHORT SequenceNumber; /* Sequence number */
250 USHORT LinkCount; /* Hard link count */
251 USHORT AttributeOffset; /* Offset to the first Attribute */
252 USHORT Flags; /* Flags */
253 ULONG BytesInUse; /* Real size of the FILE record */
254 ULONG BytesAllocated; /* Allocated size of the FILE record */
255 ULONGLONG BaseFileRecord; /* File reference to the base FILE record */
256 USHORT NextAttributeNumber; /* Next Attribute Id */
257 USHORT Padding; /* Align to 4 UCHAR boundary (XP) */
258 ULONG MFTRecordNumber; /* Number of this MFT Record (XP) */
259 } FILE_RECORD_HEADER, *PFILE_RECORD_HEADER;
260
261 /* Flags in FILE_RECORD_HEADER */
262
263 #define FRH_IN_USE 0x0001 /* Record is in use */
264 #define FRH_DIRECTORY 0x0002 /* Record is a directory */
265 #define FRH_UNKNOWN1 0x0004 /* Don't know */
266 #define FRH_UNKNOWN2 0x0008 /* Don't know */
267
268 typedef struct
269 {
270 ULONG Type;
271 ULONG Length;
272 UCHAR IsNonResident;
273 UCHAR NameLength;
274 USHORT NameOffset;
275 USHORT Flags;
276 USHORT Instance;
277 union
278 {
279 // Resident attributes
280 struct
281 {
282 ULONG ValueLength;
283 USHORT ValueOffset;
284 UCHAR Flags;
285 UCHAR Reserved;
286 } Resident;
287 // Non-resident attributes
288 struct
289 {
290 ULONGLONG LowestVCN;
291 ULONGLONG HighestVCN;
292 USHORT MappingPairsOffset;
293 USHORT CompressionUnit;
294 UCHAR Reserved[4];
295 LONGLONG AllocatedSize;
296 LONGLONG DataSize;
297 LONGLONG InitializedSize;
298 LONGLONG CompressedSize;
299 } NonResident;
300 };
301 } NTFS_ATTR_RECORD, *PNTFS_ATTR_RECORD;
302
303 // The beginning and length of an attribute record are always aligned to an 8-byte boundary,
304 // relative to the beginning of the file record.
305 #define ATTR_RECORD_ALIGNMENT 8
306
307 // Data runs are aligned to a 4-byte boundary, relative to the start of the attribute record
308 #define DATA_RUN_ALIGNMENT 4
309
310 // Value offset is aligned to a 4-byte boundary, relative to the start of the attribute record
311 #define VALUE_OFFSET_ALIGNMENT 4
312
313 typedef struct
314 {
315 ULONGLONG CreationTime;
316 ULONGLONG ChangeTime;
317 ULONGLONG LastWriteTime;
318 ULONGLONG LastAccessTime;
319 ULONG FileAttribute;
320 ULONG AlignmentOrReserved[3];
321 #if 0
322 ULONG QuotaId;
323 ULONG SecurityId;
324 ULONGLONG QuotaCharge;
325 USN Usn;
326 #endif
327 } STANDARD_INFORMATION, *PSTANDARD_INFORMATION;
328
329
330 typedef struct
331 {
332 ATTRIBUTE_TYPE AttributeType;
333 USHORT Length;
334 UCHAR NameLength;
335 UCHAR NameOffset;
336 ULONGLONG StartVcn; // LowVcn
337 ULONGLONG FileReferenceNumber;
338 USHORT AttributeNumber;
339 USHORT AlignmentOrReserved[3];
340 } ATTRIBUTE_LIST, *PATTRIBUTE_LIST;
341
342
343 typedef struct
344 {
345 ULONGLONG DirectoryFileReferenceNumber;
346 ULONGLONG CreationTime;
347 ULONGLONG ChangeTime;
348 ULONGLONG LastWriteTime;
349 ULONGLONG LastAccessTime;
350 ULONGLONG AllocatedSize;
351 ULONGLONG DataSize;
352 ULONG FileAttributes;
353 union
354 {
355 struct
356 {
357 USHORT PackedEaSize;
358 USHORT AlignmentOrReserved;
359 } EaInfo;
360 ULONG ReparseTag;
361 } Extended;
362 UCHAR NameLength;
363 UCHAR NameType;
364 WCHAR Name[1];
365 } FILENAME_ATTRIBUTE, *PFILENAME_ATTRIBUTE;
366
367 typedef struct
368 {
369 ULONG FirstEntryOffset;
370 ULONG TotalSizeOfEntries;
371 ULONG AllocatedSize;
372 UCHAR Flags;
373 UCHAR Padding[3];
374 } INDEX_HEADER_ATTRIBUTE, *PINDEX_HEADER_ATTRIBUTE;
375
376 typedef struct
377 {
378 ULONG AttributeType;
379 ULONG CollationRule;
380 ULONG SizeOfEntry;
381 UCHAR ClustersPerIndexRecord;
382 UCHAR Padding[3];
383 INDEX_HEADER_ATTRIBUTE Header;
384 } INDEX_ROOT_ATTRIBUTE, *PINDEX_ROOT_ATTRIBUTE;
385
386 typedef struct
387 {
388 NTFS_RECORD_HEADER Ntfs;
389 ULONGLONG VCN;
390 INDEX_HEADER_ATTRIBUTE Header;
391 } INDEX_BUFFER, *PINDEX_BUFFER;
392
393 typedef struct
394 {
395 union
396 {
397 struct
398 {
399 ULONGLONG IndexedFile;
400 } Directory;
401 struct
402 {
403 USHORT DataOffset;
404 USHORT DataLength;
405 ULONG Reserved;
406 } ViewIndex;
407 } Data;
408 USHORT Length;
409 USHORT KeyLength;
410 USHORT Flags;
411 USHORT Reserved;
412 FILENAME_ATTRIBUTE FileName;
413 } INDEX_ENTRY_ATTRIBUTE, *PINDEX_ENTRY_ATTRIBUTE;
414
415 struct _B_TREE_FILENAME_NODE;
416 typedef struct _B_TREE_FILENAME_NODE B_TREE_FILENAME_NODE;
417
418 // Keys are arranged in nodes as an ordered, linked list
419 typedef struct _B_TREE_KEY
420 {
421 struct _B_TREE_KEY *NextKey;
422 B_TREE_FILENAME_NODE *LesserChild; // Child-Node. All the keys in this node will be sorted before IndexEntry
423 PINDEX_ENTRY_ATTRIBUTE IndexEntry; // must be last member for FIELD_OFFSET
424 }B_TREE_KEY, *PB_TREE_KEY;
425
426 // Every Node is just an ordered list of keys.
427 // Sub-nodes can be found attached to a key (if they exist).
428 // A key's sub-node precedes that key in the ordered list.
429 typedef struct _B_TREE_FILENAME_NODE
430 {
431 ULONG KeyCount;
432 BOOLEAN HasValidVCN;
433 BOOLEAN DiskNeedsUpdating;
434 ULONGLONG VCN;
435 PB_TREE_KEY FirstKey;
436 } B_TREE_FILENAME_NODE, *PB_TREE_FILENAME_NODE;
437
438 typedef struct
439 {
440 PB_TREE_FILENAME_NODE RootNode;
441 } B_TREE, *PB_TREE;
442
443 typedef struct
444 {
445 ULONGLONG Unknown1;
446 UCHAR MajorVersion;
447 UCHAR MinorVersion;
448 USHORT Flags;
449 ULONG Unknown2;
450 } VOLINFO_ATTRIBUTE, *PVOLINFO_ATTRIBUTE;
451
452 typedef struct {
453 ULONG ReparseTag;
454 USHORT DataLength;
455 USHORT Reserved;
456 UCHAR Data[1];
457 } REPARSE_POINT_ATTRIBUTE, *PREPARSE_POINT_ATTRIBUTE;
458
459 #define IRPCONTEXT_CANWAIT 0x1
460 #define IRPCONTEXT_COMPLETE 0x2
461 #define IRPCONTEXT_QUEUE 0x4
462
463 typedef struct
464 {
465 NTFSIDENTIFIER Identifier;
466 ULONG Flags;
467 PIO_STACK_LOCATION Stack;
468 UCHAR MajorFunction;
469 UCHAR MinorFunction;
470 WORK_QUEUE_ITEM WorkQueueItem;
471 PIRP Irp;
472 BOOLEAN IsTopLevel;
473 PDEVICE_OBJECT DeviceObject;
474 PFILE_OBJECT FileObject;
475 NTSTATUS SavedExceptionCode;
476 CCHAR PriorityBoost;
477 } NTFS_IRP_CONTEXT, *PNTFS_IRP_CONTEXT;
478
479 typedef struct _NTFS_ATTR_CONTEXT
480 {
481 PUCHAR CacheRun;
482 ULONGLONG CacheRunOffset;
483 LONGLONG CacheRunStartLCN;
484 ULONGLONG CacheRunLength;
485 LONGLONG CacheRunLastLCN;
486 ULONGLONG CacheRunCurrentOffset;
487 LARGE_MCB DataRunsMCB;
488 ULONGLONG FileMFTIndex;
489 PNTFS_ATTR_RECORD pRecord;
490 } NTFS_ATTR_CONTEXT, *PNTFS_ATTR_CONTEXT;
491
492 #define FCB_CACHE_INITIALIZED 0x0001
493 #define FCB_IS_VOLUME_STREAM 0x0002
494 #define FCB_IS_VOLUME 0x0004
495 #define MAX_PATH 260
496
497 typedef struct _FCB
498 {
499 NTFSIDENTIFIER Identifier;
500
501 FSRTL_COMMON_FCB_HEADER RFCB;
502 SECTION_OBJECT_POINTERS SectionObjectPointers;
503
504 PFILE_OBJECT FileObject;
505 PNTFS_VCB Vcb;
506
507 WCHAR Stream[MAX_PATH];
508 WCHAR *ObjectName; /* point on filename (250 chars max) in PathName */
509 WCHAR PathName[MAX_PATH]; /* path+filename 260 max */
510
511 ERESOURCE PagingIoResource;
512 ERESOURCE MainResource;
513
514 LIST_ENTRY FcbListEntry;
515 struct _FCB* ParentFcb;
516
517 ULONG DirIndex;
518
519 LONG RefCount;
520 ULONG Flags;
521 ULONG OpenHandleCount;
522
523 ULONGLONG MFTIndex;
524 USHORT LinkCount;
525
526 FILENAME_ATTRIBUTE Entry;
527
528 } NTFS_FCB, *PNTFS_FCB;
529
530 typedef struct _FIND_ATTR_CONTXT
531 {
532 PDEVICE_EXTENSION Vcb;
533 BOOLEAN OnlyResident;
534 PNTFS_ATTR_RECORD FirstAttr;
535 PNTFS_ATTR_RECORD CurrAttr;
536 PNTFS_ATTR_RECORD LastAttr;
537 PNTFS_ATTR_RECORD NonResidentStart;
538 PNTFS_ATTR_RECORD NonResidentEnd;
539 ULONG Offset;
540 } FIND_ATTR_CONTXT, *PFIND_ATTR_CONTXT;
541
542 typedef struct
543 {
544 USHORT USN;
545 USHORT Array[];
546 } FIXUP_ARRAY, *PFIXUP_ARRAY;
547
548 extern PNTFS_GLOBAL_DATA NtfsGlobalData;
549
550 FORCEINLINE
551 NTSTATUS
552 NtfsMarkIrpContextForQueue(PNTFS_IRP_CONTEXT IrpContext)
553 {
554 PULONG Flags = &IrpContext->Flags;
555
556 *Flags &= ~IRPCONTEXT_COMPLETE;
557 *Flags |= IRPCONTEXT_QUEUE;
558
559 return STATUS_PENDING;
560 }
561
562 /* attrib.c */
563
564 //VOID
565 //NtfsDumpAttribute(PATTRIBUTE Attribute);
566
567 NTSTATUS
568 AddData(PFILE_RECORD_HEADER FileRecord,
569 PNTFS_ATTR_RECORD AttributeAddress);
570
571 NTSTATUS
572 AddRun(PNTFS_VCB Vcb,
573 PNTFS_ATTR_CONTEXT AttrContext,
574 ULONG AttrOffset,
575 PFILE_RECORD_HEADER FileRecord,
576 ULONGLONG NextAssignedCluster,
577 ULONG RunLength);
578
579 NTSTATUS
580 AddIndexRoot(PNTFS_VCB Vcb,
581 PFILE_RECORD_HEADER FileRecord,
582 PNTFS_ATTR_RECORD AttributeAddress,
583 PINDEX_ROOT_ATTRIBUTE NewIndexRoot,
584 ULONG RootLength,
585 PCWSTR Name,
586 USHORT NameLength);
587
588 NTSTATUS
589 AddFileName(PFILE_RECORD_HEADER FileRecord,
590 PNTFS_ATTR_RECORD AttributeAddress,
591 PDEVICE_EXTENSION DeviceExt,
592 PFILE_OBJECT FileObject,
593 BOOLEAN CaseSensitive,
594 PULONGLONG ParentMftIndex);
595
596 NTSTATUS
597 AddStandardInformation(PFILE_RECORD_HEADER FileRecord,
598 PNTFS_ATTR_RECORD AttributeAddress);
599
600 NTSTATUS
601 ConvertDataRunsToLargeMCB(PUCHAR DataRun,
602 PLARGE_MCB DataRunsMCB,
603 PULONGLONG pNextVBN);
604
605 NTSTATUS
606 ConvertLargeMCBToDataRuns(PLARGE_MCB DataRunsMCB,
607 PUCHAR RunBuffer,
608 ULONG MaxBufferSize,
609 PULONG UsedBufferSize);
610
611 PUCHAR
612 DecodeRun(PUCHAR DataRun,
613 LONGLONG *DataRunOffset,
614 ULONGLONG *DataRunLength);
615
616 ULONG GetFileNameAttributeLength(PFILENAME_ATTRIBUTE FileNameAttribute);
617
618 VOID
619 NtfsDumpDataRuns(PVOID StartOfRun,
620 ULONGLONG CurrentLCN);
621
622 VOID
623 NtfsDumpFileAttributes(PDEVICE_EXTENSION Vcb,
624 PFILE_RECORD_HEADER FileRecord);
625
626 PSTANDARD_INFORMATION
627 GetStandardInformationFromRecord(PDEVICE_EXTENSION Vcb,
628 PFILE_RECORD_HEADER FileRecord);
629
630 PFILENAME_ATTRIBUTE
631 GetFileNameFromRecord(PDEVICE_EXTENSION Vcb,
632 PFILE_RECORD_HEADER FileRecord,
633 UCHAR NameType);
634
635 UCHAR
636 GetPackedByteCount(LONGLONG NumberToPack,
637 BOOLEAN IsSigned);
638
639 NTSTATUS
640 GetLastClusterInDataRun(PDEVICE_EXTENSION Vcb,
641 PNTFS_ATTR_RECORD Attribute,
642 PULONGLONG LastCluster);
643
644 PFILENAME_ATTRIBUTE
645 GetBestFileNameFromRecord(PDEVICE_EXTENSION Vcb,
646 PFILE_RECORD_HEADER FileRecord);
647
648 NTSTATUS
649 FindFirstAttribute(PFIND_ATTR_CONTXT Context,
650 PDEVICE_EXTENSION Vcb,
651 PFILE_RECORD_HEADER FileRecord,
652 BOOLEAN OnlyResident,
653 PNTFS_ATTR_RECORD * Attribute);
654
655 NTSTATUS
656 FindNextAttribute(PFIND_ATTR_CONTXT Context,
657 PNTFS_ATTR_RECORD * Attribute);
658
659 VOID
660 FindCloseAttribute(PFIND_ATTR_CONTXT Context);
661
662 NTSTATUS
663 FreeClusters(PNTFS_VCB Vcb,
664 PNTFS_ATTR_CONTEXT AttrContext,
665 ULONG AttrOffset,
666 PFILE_RECORD_HEADER FileRecord,
667 ULONG ClustersToFree);
668
669 /* blockdev.c */
670
671 NTSTATUS
672 NtfsReadDisk(IN PDEVICE_OBJECT DeviceObject,
673 IN LONGLONG StartingOffset,
674 IN ULONG Length,
675 IN ULONG SectorSize,
676 IN OUT PUCHAR Buffer,
677 IN BOOLEAN Override);
678
679 NTSTATUS
680 NtfsWriteDisk(IN PDEVICE_OBJECT DeviceObject,
681 IN LONGLONG StartingOffset,
682 IN ULONG Length,
683 IN ULONG SectorSize,
684 IN const PUCHAR Buffer);
685
686 NTSTATUS
687 NtfsReadSectors(IN PDEVICE_OBJECT DeviceObject,
688 IN ULONG DiskSector,
689 IN ULONG SectorCount,
690 IN ULONG SectorSize,
691 IN OUT PUCHAR Buffer,
692 IN BOOLEAN Override);
693
694 NTSTATUS
695 NtfsDeviceIoControl(IN PDEVICE_OBJECT DeviceObject,
696 IN ULONG ControlCode,
697 IN PVOID InputBuffer,
698 IN ULONG InputBufferSize,
699 IN OUT PVOID OutputBuffer,
700 IN OUT PULONG OutputBufferSize,
701 IN BOOLEAN Override);
702
703
704 /* btree.c */
705
706 LONG
707 CompareTreeKeys(PB_TREE_KEY Key1,
708 PB_TREE_KEY Key2,
709 BOOLEAN CaseSensitive);
710
711 NTSTATUS
712 CreateBTreeFromIndex(PDEVICE_EXTENSION Vcb,
713 PFILE_RECORD_HEADER FileRecordWithIndex,
714 /*PCWSTR IndexName,*/
715 PNTFS_ATTR_CONTEXT IndexRootContext,
716 PINDEX_ROOT_ATTRIBUTE IndexRoot,
717 PB_TREE *NewTree);
718
719 NTSTATUS
720 CreateIndexRootFromBTree(PDEVICE_EXTENSION DeviceExt,
721 PB_TREE Tree,
722 ULONG MaxIndexSize,
723 PINDEX_ROOT_ATTRIBUTE *IndexRoot,
724 ULONG *Length);
725
726 VOID
727 DestroyBTree(PB_TREE Tree);
728
729 VOID
730 DestroyBTreeNode(PB_TREE_FILENAME_NODE Node);
731
732 VOID
733 DumpBTree(PB_TREE Tree);
734
735 VOID
736 DumpBTreeKey(PB_TREE Tree,
737 PB_TREE_KEY Key,
738 ULONG Number,
739 ULONG Depth);
740
741 VOID
742 DumpBTreeNode(PB_TREE Tree,
743 PB_TREE_FILENAME_NODE Node,
744 ULONG Number,
745 ULONG Depth);
746
747 NTSTATUS
748 CreateEmptyBTree(PB_TREE *NewTree);
749
750 ULONGLONG
751 GetAllocationOffsetFromVCN(PDEVICE_EXTENSION DeviceExt,
752 ULONG IndexBufferSize,
753 ULONGLONG Vcn);
754
755 NTSTATUS
756 NtfsInsertKey(PB_TREE Tree,
757 ULONGLONG FileReference,
758 PFILENAME_ATTRIBUTE FileNameAttribute,
759 PB_TREE_FILENAME_NODE Node,
760 BOOLEAN CaseSensitive,
761 ULONG MaxIndexRootSize);
762
763 NTSTATUS
764 UpdateIndexAllocation(PDEVICE_EXTENSION DeviceExt,
765 PB_TREE Tree,
766 ULONG IndexBufferSize,
767 PFILE_RECORD_HEADER FileRecord);
768
769 NTSTATUS
770 UpdateIndexNode(PDEVICE_EXTENSION DeviceExt,
771 PFILE_RECORD_HEADER FileRecord,
772 PB_TREE_FILENAME_NODE Node,
773 ULONG IndexBufferSize,
774 PNTFS_ATTR_CONTEXT IndexAllocationContext,
775 ULONG IndexAllocationOffset,
776 PNTFS_ATTR_CONTEXT BitmapContext);
777
778 /* close.c */
779
780 NTSTATUS
781 NtfsCleanup(PNTFS_IRP_CONTEXT IrpContext);
782
783
784 /* close.c */
785
786 NTSTATUS
787 NtfsCloseFile(PDEVICE_EXTENSION DeviceExt,
788 PFILE_OBJECT FileObject);
789
790 NTSTATUS
791 NtfsClose(PNTFS_IRP_CONTEXT IrpContext);
792
793
794 /* create.c */
795
796 NTSTATUS
797 NtfsCreate(PNTFS_IRP_CONTEXT IrpContext);
798
799 NTSTATUS
800 NtfsCreateDirectory(PDEVICE_EXTENSION DeviceExt,
801 PFILE_OBJECT FileObject,
802 BOOLEAN CaseSensitive,
803 BOOLEAN CanWait);
804
805 PFILE_RECORD_HEADER
806 NtfsCreateEmptyFileRecord(PDEVICE_EXTENSION DeviceExt);
807
808 NTSTATUS
809 NtfsCreateFileRecord(PDEVICE_EXTENSION DeviceExt,
810 PFILE_OBJECT FileObject,
811 BOOLEAN CaseSensitive,
812 BOOLEAN CanWait);
813
814 /* devctl.c */
815
816 NTSTATUS
817 NtfsDeviceControl(PNTFS_IRP_CONTEXT IrpContext);
818
819
820 /* dirctl.c */
821
822 ULONGLONG
823 NtfsGetFileSize(PDEVICE_EXTENSION DeviceExt,
824 PFILE_RECORD_HEADER FileRecord,
825 PCWSTR Stream,
826 ULONG StreamLength,
827 PULONGLONG AllocatedSize);
828
829 NTSTATUS
830 NtfsDirectoryControl(PNTFS_IRP_CONTEXT IrpContext);
831
832
833 /* dispatch.c */
834
835 DRIVER_DISPATCH NtfsFsdDispatch;
836 NTSTATUS NTAPI
837 NtfsFsdDispatch(PDEVICE_OBJECT DeviceObject,
838 PIRP Irp);
839
840
841 /* fastio.c */
842
843 BOOLEAN NTAPI
844 NtfsAcqLazyWrite(PVOID Context,
845 BOOLEAN Wait);
846
847 VOID NTAPI
848 NtfsRelLazyWrite(PVOID Context);
849
850 BOOLEAN NTAPI
851 NtfsAcqReadAhead(PVOID Context,
852 BOOLEAN Wait);
853
854 VOID NTAPI
855 NtfsRelReadAhead(PVOID Context);
856
857 FAST_IO_CHECK_IF_POSSIBLE NtfsFastIoCheckIfPossible;
858 FAST_IO_READ NtfsFastIoRead;
859 FAST_IO_WRITE NtfsFastIoWrite;
860
861
862 /* fcb.c */
863
864 PNTFS_FCB
865 NtfsCreateFCB(PCWSTR FileName,
866 PCWSTR Stream,
867 PNTFS_VCB Vcb);
868
869 VOID
870 NtfsDestroyFCB(PNTFS_FCB Fcb);
871
872 BOOLEAN
873 NtfsFCBIsDirectory(PNTFS_FCB Fcb);
874
875 BOOLEAN
876 NtfsFCBIsReparsePoint(PNTFS_FCB Fcb);
877
878 BOOLEAN
879 NtfsFCBIsCompressed(PNTFS_FCB Fcb);
880
881 BOOLEAN
882 NtfsFCBIsRoot(PNTFS_FCB Fcb);
883
884 VOID
885 NtfsGrabFCB(PNTFS_VCB Vcb,
886 PNTFS_FCB Fcb);
887
888 VOID
889 NtfsReleaseFCB(PNTFS_VCB Vcb,
890 PNTFS_FCB Fcb);
891
892 VOID
893 NtfsAddFCBToTable(PNTFS_VCB Vcb,
894 PNTFS_FCB Fcb);
895
896 PNTFS_FCB
897 NtfsGrabFCBFromTable(PNTFS_VCB Vcb,
898 PCWSTR FileName);
899
900 NTSTATUS
901 NtfsFCBInitializeCache(PNTFS_VCB Vcb,
902 PNTFS_FCB Fcb);
903
904 PNTFS_FCB
905 NtfsMakeRootFCB(PNTFS_VCB Vcb);
906
907 PNTFS_FCB
908 NtfsOpenRootFCB(PNTFS_VCB Vcb);
909
910 NTSTATUS
911 NtfsAttachFCBToFileObject(PNTFS_VCB Vcb,
912 PNTFS_FCB Fcb,
913 PFILE_OBJECT FileObject);
914
915 NTSTATUS
916 NtfsGetFCBForFile(PNTFS_VCB Vcb,
917 PNTFS_FCB *pParentFCB,
918 PNTFS_FCB *pFCB,
919 PCWSTR pFileName,
920 BOOLEAN CaseSensitive);
921
922 NTSTATUS
923 NtfsReadFCBAttribute(PNTFS_VCB Vcb,
924 PNTFS_FCB pFCB,
925 ULONG Type,
926 PCWSTR Name,
927 ULONG NameLength,
928 PVOID * Data);
929
930 NTSTATUS
931 NtfsMakeFCBFromDirEntry(PNTFS_VCB Vcb,
932 PNTFS_FCB DirectoryFCB,
933 PUNICODE_STRING Name,
934 PCWSTR Stream,
935 PFILE_RECORD_HEADER Record,
936 ULONGLONG MFTIndex,
937 PNTFS_FCB * fileFCB);
938
939
940 /* finfo.c */
941
942 NTSTATUS
943 NtfsQueryInformation(PNTFS_IRP_CONTEXT IrpContext);
944
945 NTSTATUS
946 NtfsSetEndOfFile(PNTFS_FCB Fcb,
947 PFILE_OBJECT FileObject,
948 PDEVICE_EXTENSION DeviceExt,
949 ULONG IrpFlags,
950 BOOLEAN CaseSensitive,
951 PLARGE_INTEGER NewFileSize);
952
953 NTSTATUS
954 NtfsSetInformation(PNTFS_IRP_CONTEXT IrpContext);
955
956 /* fsctl.c */
957
958 NTSTATUS
959 NtfsFileSystemControl(PNTFS_IRP_CONTEXT IrpContext);
960
961
962 /* mft.c */
963 NTSTATUS
964 NtfsAddFilenameToDirectory(PDEVICE_EXTENSION DeviceExt,
965 ULONGLONG DirectoryMftIndex,
966 ULONGLONG FileReferenceNumber,
967 PFILENAME_ATTRIBUTE FilenameAttribute,
968 BOOLEAN CaseSensitive);
969
970 NTSTATUS
971 AddNewMftEntry(PFILE_RECORD_HEADER FileRecord,
972 PDEVICE_EXTENSION DeviceExt,
973 PULONGLONG DestinationIndex,
974 BOOLEAN CanWait);
975
976 PNTFS_ATTR_CONTEXT
977 PrepareAttributeContext(PNTFS_ATTR_RECORD AttrRecord);
978
979 VOID
980 ReleaseAttributeContext(PNTFS_ATTR_CONTEXT Context);
981
982 ULONG
983 ReadAttribute(PDEVICE_EXTENSION Vcb,
984 PNTFS_ATTR_CONTEXT Context,
985 ULONGLONG Offset,
986 PCHAR Buffer,
987 ULONG Length);
988
989 NTSTATUS
990 WriteAttribute(PDEVICE_EXTENSION Vcb,
991 PNTFS_ATTR_CONTEXT Context,
992 ULONGLONG Offset,
993 const PUCHAR Buffer,
994 ULONG Length,
995 PULONG LengthWritten,
996 PFILE_RECORD_HEADER FileRecord);
997
998 ULONGLONG
999 AttributeDataLength(PNTFS_ATTR_RECORD AttrRecord);
1000
1001 NTSTATUS
1002 InternalSetResidentAttributeLength(PDEVICE_EXTENSION DeviceExt,
1003 PNTFS_ATTR_CONTEXT AttrContext,
1004 PFILE_RECORD_HEADER FileRecord,
1005 ULONG AttrOffset,
1006 ULONG DataSize);
1007
1008 PNTFS_ATTR_RECORD
1009 MoveAttributes(PDEVICE_EXTENSION DeviceExt,
1010 PNTFS_ATTR_RECORD FirstAttributeToMove,
1011 ULONG FirstAttributeOffset,
1012 ULONG_PTR MoveTo);
1013
1014 NTSTATUS
1015 SetAttributeDataLength(PFILE_OBJECT FileObject,
1016 PNTFS_FCB Fcb,
1017 PNTFS_ATTR_CONTEXT AttrContext,
1018 ULONG AttrOffset,
1019 PFILE_RECORD_HEADER FileRecord,
1020 PLARGE_INTEGER DataSize);
1021
1022 VOID
1023 SetFileRecordEnd(PFILE_RECORD_HEADER FileRecord,
1024 PNTFS_ATTR_RECORD AttrEnd,
1025 ULONG EndMarker);
1026
1027 NTSTATUS
1028 SetNonResidentAttributeDataLength(PDEVICE_EXTENSION Vcb,
1029 PNTFS_ATTR_CONTEXT AttrContext,
1030 ULONG AttrOffset,
1031 PFILE_RECORD_HEADER FileRecord,
1032 PLARGE_INTEGER DataSize);
1033
1034 NTSTATUS
1035 SetResidentAttributeDataLength(PDEVICE_EXTENSION Vcb,
1036 PNTFS_ATTR_CONTEXT AttrContext,
1037 ULONG AttrOffset,
1038 PFILE_RECORD_HEADER FileRecord,
1039 PLARGE_INTEGER DataSize);
1040
1041 ULONGLONG
1042 AttributeAllocatedLength(PNTFS_ATTR_RECORD AttrRecord);
1043
1044 BOOLEAN
1045 CompareFileName(PUNICODE_STRING FileName,
1046 PINDEX_ENTRY_ATTRIBUTE IndexEntry,
1047 BOOLEAN DirSearch,
1048 BOOLEAN CaseSensitive);
1049
1050 NTSTATUS
1051 UpdateMftMirror(PNTFS_VCB Vcb);
1052
1053 NTSTATUS
1054 ReadFileRecord(PDEVICE_EXTENSION Vcb,
1055 ULONGLONG index,
1056 PFILE_RECORD_HEADER file);
1057
1058 NTSTATUS
1059 UpdateIndexEntryFileNameSize(PDEVICE_EXTENSION Vcb,
1060 PFILE_RECORD_HEADER MftRecord,
1061 PCHAR IndexRecord,
1062 ULONG IndexBlockSize,
1063 PINDEX_ENTRY_ATTRIBUTE FirstEntry,
1064 PINDEX_ENTRY_ATTRIBUTE LastEntry,
1065 PUNICODE_STRING FileName,
1066 PULONG StartEntry,
1067 PULONG CurrentEntry,
1068 BOOLEAN DirSearch,
1069 ULONGLONG NewDataSize,
1070 ULONGLONG NewAllocatedSize,
1071 BOOLEAN CaseSensitive);
1072
1073 NTSTATUS
1074 UpdateFileNameRecord(PDEVICE_EXTENSION Vcb,
1075 ULONGLONG ParentMFTIndex,
1076 PUNICODE_STRING FileName,
1077 BOOLEAN DirSearch,
1078 ULONGLONG NewDataSize,
1079 ULONGLONG NewAllocationSize,
1080 BOOLEAN CaseSensitive);
1081
1082 NTSTATUS
1083 UpdateFileRecord(PDEVICE_EXTENSION Vcb,
1084 ULONGLONG MftIndex,
1085 PFILE_RECORD_HEADER FileRecord);
1086
1087 NTSTATUS
1088 FindAttribute(PDEVICE_EXTENSION Vcb,
1089 PFILE_RECORD_HEADER MftRecord,
1090 ULONG Type,
1091 PCWSTR Name,
1092 ULONG NameLength,
1093 PNTFS_ATTR_CONTEXT * AttrCtx,
1094 PULONG Offset);
1095
1096 VOID
1097 ReadVCN(PDEVICE_EXTENSION Vcb,
1098 PFILE_RECORD_HEADER file,
1099 ATTRIBUTE_TYPE type,
1100 ULONGLONG vcn,
1101 ULONG count,
1102 PVOID buffer);
1103
1104 NTSTATUS
1105 FixupUpdateSequenceArray(PDEVICE_EXTENSION Vcb,
1106 PNTFS_RECORD_HEADER Record);
1107
1108 NTSTATUS
1109 AddFixupArray(PDEVICE_EXTENSION Vcb,
1110 PNTFS_RECORD_HEADER Record);
1111
1112 NTSTATUS
1113 ReadLCN(PDEVICE_EXTENSION Vcb,
1114 ULONGLONG lcn,
1115 ULONG count,
1116 PVOID buffer);
1117
1118 VOID
1119 EnumerAttribute(PFILE_RECORD_HEADER file,
1120 PDEVICE_EXTENSION Vcb,
1121 PDEVICE_OBJECT DeviceObject);
1122
1123 NTSTATUS
1124 NtfsLookupFile(PDEVICE_EXTENSION Vcb,
1125 PUNICODE_STRING PathName,
1126 BOOLEAN CaseSensitive,
1127 PFILE_RECORD_HEADER *FileRecord,
1128 PULONGLONG MFTIndex);
1129
1130 NTSTATUS
1131 NtfsLookupFileAt(PDEVICE_EXTENSION Vcb,
1132 PUNICODE_STRING PathName,
1133 BOOLEAN CaseSensitive,
1134 PFILE_RECORD_HEADER *FileRecord,
1135 PULONGLONG MFTIndex,
1136 ULONGLONG CurrentMFTIndex);
1137
1138 VOID
1139 NtfsDumpFileRecord(PDEVICE_EXTENSION Vcb,
1140 PFILE_RECORD_HEADER FileRecord);
1141
1142 NTSTATUS
1143 NtfsFindFileAt(PDEVICE_EXTENSION Vcb,
1144 PUNICODE_STRING SearchPattern,
1145 PULONG FirstEntry,
1146 PFILE_RECORD_HEADER *FileRecord,
1147 PULONGLONG MFTIndex,
1148 ULONGLONG CurrentMFTIndex,
1149 BOOLEAN CaseSensitive);
1150
1151 NTSTATUS
1152 NtfsFindMftRecord(PDEVICE_EXTENSION Vcb,
1153 ULONGLONG MFTIndex,
1154 PUNICODE_STRING FileName,
1155 PULONG FirstEntry,
1156 BOOLEAN DirSearch,
1157 BOOLEAN CaseSensitive,
1158 ULONGLONG *OutMFTIndex);
1159
1160 /* misc.c */
1161
1162 BOOLEAN
1163 NtfsIsIrpTopLevel(PIRP Irp);
1164
1165 PNTFS_IRP_CONTEXT
1166 NtfsAllocateIrpContext(PDEVICE_OBJECT DeviceObject,
1167 PIRP Irp);
1168
1169 PVOID
1170 NtfsGetUserBuffer(PIRP Irp,
1171 BOOLEAN Paging);
1172
1173 NTSTATUS
1174 NtfsLockUserBuffer(IN PIRP Irp,
1175 IN ULONG Length,
1176 IN LOCK_OPERATION Operation);
1177
1178 #if 0
1179 BOOLEAN
1180 wstrcmpjoki(PWSTR s1, PWSTR s2);
1181
1182 VOID
1183 CdfsSwapString(PWCHAR Out,
1184 PUCHAR In,
1185 ULONG Count);
1186 #endif
1187
1188 VOID
1189 NtfsFileFlagsToAttributes(ULONG NtfsAttributes,
1190 PULONG FileAttributes);
1191
1192
1193 /* rw.c */
1194
1195 NTSTATUS
1196 NtfsRead(PNTFS_IRP_CONTEXT IrpContext);
1197
1198 NTSTATUS
1199 NtfsWrite(PNTFS_IRP_CONTEXT IrpContext);
1200
1201
1202 /* volinfo.c */
1203
1204 NTSTATUS
1205 NtfsAllocateClusters(PDEVICE_EXTENSION DeviceExt,
1206 ULONG FirstDesiredCluster,
1207 ULONG DesiredClusters,
1208 PULONG FirstAssignedCluster,
1209 PULONG AssignedClusters);
1210
1211 ULONGLONG
1212 NtfsGetFreeClusters(PDEVICE_EXTENSION DeviceExt);
1213
1214 NTSTATUS
1215 NtfsQueryVolumeInformation(PNTFS_IRP_CONTEXT IrpContext);
1216
1217 NTSTATUS
1218 NtfsSetVolumeInformation(PNTFS_IRP_CONTEXT IrpContext);
1219
1220
1221 /* ntfs.c */
1222
1223 DRIVER_INITIALIZE DriverEntry;
1224
1225 VOID
1226 NTAPI
1227 NtfsInitializeFunctionPointers(PDRIVER_OBJECT DriverObject);
1228
1229 #endif /* NTFS_H */