39c33210fcff6e0f1c47558d19f5a54ec9d28c29
[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 typedef struct
308 {
309 ULONGLONG CreationTime;
310 ULONGLONG ChangeTime;
311 ULONGLONG LastWriteTime;
312 ULONGLONG LastAccessTime;
313 ULONG FileAttribute;
314 ULONG AlignmentOrReserved[3];
315 #if 0
316 ULONG QuotaId;
317 ULONG SecurityId;
318 ULONGLONG QuotaCharge;
319 USN Usn;
320 #endif
321 } STANDARD_INFORMATION, *PSTANDARD_INFORMATION;
322
323
324 typedef struct
325 {
326 ATTRIBUTE_TYPE AttributeType;
327 USHORT Length;
328 UCHAR NameLength;
329 UCHAR NameOffset;
330 ULONGLONG StartVcn; // LowVcn
331 ULONGLONG FileReferenceNumber;
332 USHORT AttributeNumber;
333 USHORT AlignmentOrReserved[3];
334 } ATTRIBUTE_LIST, *PATTRIBUTE_LIST;
335
336
337 typedef struct
338 {
339 ULONGLONG DirectoryFileReferenceNumber;
340 ULONGLONG CreationTime;
341 ULONGLONG ChangeTime;
342 ULONGLONG LastWriteTime;
343 ULONGLONG LastAccessTime;
344 ULONGLONG AllocatedSize;
345 ULONGLONG DataSize;
346 ULONG FileAttributes;
347 union
348 {
349 struct
350 {
351 USHORT PackedEaSize;
352 USHORT AlignmentOrReserved;
353 } EaInfo;
354 ULONG ReparseTag;
355 } Extended;
356 UCHAR NameLength;
357 UCHAR NameType;
358 WCHAR Name[1];
359 } FILENAME_ATTRIBUTE, *PFILENAME_ATTRIBUTE;
360
361 typedef struct
362 {
363 ULONG FirstEntryOffset;
364 ULONG TotalSizeOfEntries;
365 ULONG AllocatedSize;
366 UCHAR Flags;
367 UCHAR Padding[3];
368 } INDEX_HEADER_ATTRIBUTE, *PINDEX_HEADER_ATTRIBUTE;
369
370 typedef struct
371 {
372 ULONG AttributeType;
373 ULONG CollationRule;
374 ULONG SizeOfEntry;
375 UCHAR ClustersPerIndexRecord;
376 UCHAR Padding[3];
377 INDEX_HEADER_ATTRIBUTE Header;
378 } INDEX_ROOT_ATTRIBUTE, *PINDEX_ROOT_ATTRIBUTE;
379
380 typedef struct
381 {
382 NTFS_RECORD_HEADER Ntfs;
383 ULONGLONG VCN;
384 INDEX_HEADER_ATTRIBUTE Header;
385 } INDEX_BUFFER, *PINDEX_BUFFER;
386
387 typedef struct
388 {
389 union
390 {
391 struct
392 {
393 ULONGLONG IndexedFile;
394 } Directory;
395 struct
396 {
397 USHORT DataOffset;
398 USHORT DataLength;
399 ULONG Reserved;
400 } ViewIndex;
401 } Data;
402 USHORT Length;
403 USHORT KeyLength;
404 USHORT Flags;
405 USHORT Reserved;
406 FILENAME_ATTRIBUTE FileName;
407 } INDEX_ENTRY_ATTRIBUTE, *PINDEX_ENTRY_ATTRIBUTE;
408
409 // Keys are arranged in nodes as an ordered, linked list
410 typedef struct _B_TREE_KEY
411 {
412 struct _B_TREE_KEY *NextKey;
413 // PB_TREE_FILENAME_NODE LesserChild; // we aren't worried about multi-level trees yet
414 PINDEX_ENTRY_ATTRIBUTE IndexEntry; // must be last member for FIELD_OFFSET
415 }B_TREE_KEY, *PB_TREE_KEY;
416
417 // Every Node is just an ordered list of keys.
418 // Sub-nodes can be found attached to a key (if they exist).
419 // A key's sub-node precedes that key in the ordered list.
420 typedef struct
421 {
422 ULONG KeyCount;
423 PB_TREE_KEY FirstKey;
424 } B_TREE_FILENAME_NODE, *PB_TREE_FILENAME_NODE;
425
426 typedef struct
427 {
428 PB_TREE_FILENAME_NODE RootNode;
429 } B_TREE, *PB_TREE;
430
431 typedef struct
432 {
433 ULONGLONG Unknown1;
434 UCHAR MajorVersion;
435 UCHAR MinorVersion;
436 USHORT Flags;
437 ULONG Unknown2;
438 } VOLINFO_ATTRIBUTE, *PVOLINFO_ATTRIBUTE;
439
440 typedef struct {
441 ULONG ReparseTag;
442 USHORT DataLength;
443 USHORT Reserved;
444 UCHAR Data[1];
445 } REPARSE_POINT_ATTRIBUTE, *PREPARSE_POINT_ATTRIBUTE;
446
447 #define IRPCONTEXT_CANWAIT 0x1
448 #define IRPCONTEXT_COMPLETE 0x2
449 #define IRPCONTEXT_QUEUE 0x4
450
451 typedef struct
452 {
453 NTFSIDENTIFIER Identifier;
454 ULONG Flags;
455 PIO_STACK_LOCATION Stack;
456 UCHAR MajorFunction;
457 UCHAR MinorFunction;
458 WORK_QUEUE_ITEM WorkQueueItem;
459 PIRP Irp;
460 BOOLEAN IsTopLevel;
461 PDEVICE_OBJECT DeviceObject;
462 PFILE_OBJECT FileObject;
463 NTSTATUS SavedExceptionCode;
464 CCHAR PriorityBoost;
465 } NTFS_IRP_CONTEXT, *PNTFS_IRP_CONTEXT;
466
467 typedef struct _NTFS_ATTR_CONTEXT
468 {
469 PUCHAR CacheRun;
470 ULONGLONG CacheRunOffset;
471 LONGLONG CacheRunStartLCN;
472 ULONGLONG CacheRunLength;
473 LONGLONG CacheRunLastLCN;
474 ULONGLONG CacheRunCurrentOffset;
475 LARGE_MCB DataRunsMCB;
476 ULONGLONG FileMFTIndex;
477 NTFS_ATTR_RECORD Record;
478 } NTFS_ATTR_CONTEXT, *PNTFS_ATTR_CONTEXT;
479
480 #define FCB_CACHE_INITIALIZED 0x0001
481 #define FCB_IS_VOLUME_STREAM 0x0002
482 #define FCB_IS_VOLUME 0x0004
483 #define MAX_PATH 260
484
485 typedef struct _FCB
486 {
487 NTFSIDENTIFIER Identifier;
488
489 FSRTL_COMMON_FCB_HEADER RFCB;
490 SECTION_OBJECT_POINTERS SectionObjectPointers;
491
492 PFILE_OBJECT FileObject;
493 PNTFS_VCB Vcb;
494
495 WCHAR Stream[MAX_PATH];
496 WCHAR *ObjectName; /* point on filename (250 chars max) in PathName */
497 WCHAR PathName[MAX_PATH]; /* path+filename 260 max */
498
499 ERESOURCE PagingIoResource;
500 ERESOURCE MainResource;
501
502 LIST_ENTRY FcbListEntry;
503 struct _FCB* ParentFcb;
504
505 ULONG DirIndex;
506
507 LONG RefCount;
508 ULONG Flags;
509 ULONG OpenHandleCount;
510
511 ULONGLONG MFTIndex;
512 USHORT LinkCount;
513
514 FILENAME_ATTRIBUTE Entry;
515
516 } NTFS_FCB, *PNTFS_FCB;
517
518 typedef struct _FIND_ATTR_CONTXT
519 {
520 PDEVICE_EXTENSION Vcb;
521 BOOLEAN OnlyResident;
522 PNTFS_ATTR_RECORD FirstAttr;
523 PNTFS_ATTR_RECORD CurrAttr;
524 PNTFS_ATTR_RECORD LastAttr;
525 PNTFS_ATTR_RECORD NonResidentStart;
526 PNTFS_ATTR_RECORD NonResidentEnd;
527 ULONG Offset;
528 } FIND_ATTR_CONTXT, *PFIND_ATTR_CONTXT;
529
530 typedef struct
531 {
532 USHORT USN;
533 USHORT Array[];
534 } FIXUP_ARRAY, *PFIXUP_ARRAY;
535
536 extern PNTFS_GLOBAL_DATA NtfsGlobalData;
537
538 FORCEINLINE
539 NTSTATUS
540 NtfsMarkIrpContextForQueue(PNTFS_IRP_CONTEXT IrpContext)
541 {
542 PULONG Flags = &IrpContext->Flags;
543
544 *Flags &= ~IRPCONTEXT_COMPLETE;
545 *Flags |= IRPCONTEXT_QUEUE;
546
547 return STATUS_PENDING;
548 }
549
550 /* attrib.c */
551
552 //VOID
553 //NtfsDumpAttribute(PATTRIBUTE Attribute);
554
555 NTSTATUS
556 AddData(PFILE_RECORD_HEADER FileRecord,
557 PNTFS_ATTR_RECORD AttributeAddress);
558
559 NTSTATUS
560 AddRun(PNTFS_VCB Vcb,
561 PNTFS_ATTR_CONTEXT AttrContext,
562 ULONG AttrOffset,
563 PFILE_RECORD_HEADER FileRecord,
564 ULONGLONG NextAssignedCluster,
565 ULONG RunLength);
566
567 NTSTATUS
568 AddFileName(PFILE_RECORD_HEADER FileRecord,
569 PNTFS_ATTR_RECORD AttributeAddress,
570 PDEVICE_EXTENSION DeviceExt,
571 PFILE_OBJECT FileObject,
572 BOOLEAN CaseSensitive,
573 PULONGLONG ParentMftIndex);
574
575 NTSTATUS
576 AddStandardInformation(PFILE_RECORD_HEADER FileRecord,
577 PNTFS_ATTR_RECORD AttributeAddress);
578
579 NTSTATUS
580 ConvertDataRunsToLargeMCB(PUCHAR DataRun,
581 PLARGE_MCB DataRunsMCB,
582 PULONGLONG pNextVBN);
583
584 NTSTATUS
585 ConvertLargeMCBToDataRuns(PLARGE_MCB DataRunsMCB,
586 PUCHAR RunBuffer,
587 ULONG MaxBufferSize,
588 PULONG UsedBufferSize);
589
590 PUCHAR
591 DecodeRun(PUCHAR DataRun,
592 LONGLONG *DataRunOffset,
593 ULONGLONG *DataRunLength);
594
595 ULONG GetFileNameAttributeLength(PFILENAME_ATTRIBUTE FileNameAttribute);
596
597 VOID
598 NtfsDumpDataRuns(PVOID StartOfRun,
599 ULONGLONG CurrentLCN);
600
601 VOID
602 NtfsDumpFileAttributes(PDEVICE_EXTENSION Vcb,
603 PFILE_RECORD_HEADER FileRecord);
604
605 PSTANDARD_INFORMATION
606 GetStandardInformationFromRecord(PDEVICE_EXTENSION Vcb,
607 PFILE_RECORD_HEADER FileRecord);
608
609 PFILENAME_ATTRIBUTE
610 GetFileNameFromRecord(PDEVICE_EXTENSION Vcb,
611 PFILE_RECORD_HEADER FileRecord,
612 UCHAR NameType);
613
614 UCHAR
615 GetPackedByteCount(LONGLONG NumberToPack,
616 BOOLEAN IsSigned);
617
618 NTSTATUS
619 GetLastClusterInDataRun(PDEVICE_EXTENSION Vcb,
620 PNTFS_ATTR_RECORD Attribute,
621 PULONGLONG LastCluster);
622
623 PFILENAME_ATTRIBUTE
624 GetBestFileNameFromRecord(PDEVICE_EXTENSION Vcb,
625 PFILE_RECORD_HEADER FileRecord);
626
627 NTSTATUS
628 FindFirstAttribute(PFIND_ATTR_CONTXT Context,
629 PDEVICE_EXTENSION Vcb,
630 PFILE_RECORD_HEADER FileRecord,
631 BOOLEAN OnlyResident,
632 PNTFS_ATTR_RECORD * Attribute);
633
634 NTSTATUS
635 FindNextAttribute(PFIND_ATTR_CONTXT Context,
636 PNTFS_ATTR_RECORD * Attribute);
637
638 VOID
639 FindCloseAttribute(PFIND_ATTR_CONTXT Context);
640
641 NTSTATUS
642 FreeClusters(PNTFS_VCB Vcb,
643 PNTFS_ATTR_CONTEXT AttrContext,
644 ULONG AttrOffset,
645 PFILE_RECORD_HEADER FileRecord,
646 ULONG ClustersToFree);
647
648 /* blockdev.c */
649
650 NTSTATUS
651 NtfsReadDisk(IN PDEVICE_OBJECT DeviceObject,
652 IN LONGLONG StartingOffset,
653 IN ULONG Length,
654 IN ULONG SectorSize,
655 IN OUT PUCHAR Buffer,
656 IN BOOLEAN Override);
657
658 NTSTATUS
659 NtfsWriteDisk(IN PDEVICE_OBJECT DeviceObject,
660 IN LONGLONG StartingOffset,
661 IN ULONG Length,
662 IN ULONG SectorSize,
663 IN const PUCHAR Buffer);
664
665 NTSTATUS
666 NtfsReadSectors(IN PDEVICE_OBJECT DeviceObject,
667 IN ULONG DiskSector,
668 IN ULONG SectorCount,
669 IN ULONG SectorSize,
670 IN OUT PUCHAR Buffer,
671 IN BOOLEAN Override);
672
673 NTSTATUS
674 NtfsDeviceIoControl(IN PDEVICE_OBJECT DeviceObject,
675 IN ULONG ControlCode,
676 IN PVOID InputBuffer,
677 IN ULONG InputBufferSize,
678 IN OUT PVOID OutputBuffer,
679 IN OUT PULONG OutputBufferSize,
680 IN BOOLEAN Override);
681
682
683 /* btree.c */
684
685 LONG
686 CompareTreeKeys(PB_TREE_KEY Key1,
687 PB_TREE_KEY Key2,
688 BOOLEAN CaseSensitive);
689
690 NTSTATUS
691 CreateBTreeFromIndex(/*PDEVICE_EXTENSION Vcb,*/
692 PNTFS_ATTR_CONTEXT IndexRootContext,
693 PINDEX_ROOT_ATTRIBUTE IndexRoot,
694 PB_TREE *NewTree);
695
696 NTSTATUS
697 CreateIndexRootFromBTree(PDEVICE_EXTENSION DeviceExt,
698 PB_TREE Tree,
699 ULONG MaxIndexSize,
700 PINDEX_ROOT_ATTRIBUTE *IndexRoot,
701 ULONG *Length);
702
703 VOID
704 DestroyBTree(PB_TREE Tree);
705
706 VOID
707 DestroyBTreeNode(PB_TREE_FILENAME_NODE Node);
708
709 VOID
710 DumpBTree(PB_TREE Tree);
711
712 VOID
713 DumpBTreeNode(PB_TREE_FILENAME_NODE Node,
714 ULONG Number,
715 ULONG Depth);
716
717 ULONGLONG
718 GetAllocationOffsetFromVCN(PDEVICE_EXTENSION DeviceExt,
719 ULONG IndexBufferSize,
720 ULONGLONG Vcn);
721
722 NTSTATUS
723 NtfsInsertKey(ULONGLONG FileReference,
724 PFILENAME_ATTRIBUTE FileNameAttribute,
725 PB_TREE_FILENAME_NODE Node,
726 BOOLEAN CaseSensitive);
727
728 /* close.c */
729
730 NTSTATUS
731 NtfsCleanup(PNTFS_IRP_CONTEXT IrpContext);
732
733
734 /* close.c */
735
736 NTSTATUS
737 NtfsCloseFile(PDEVICE_EXTENSION DeviceExt,
738 PFILE_OBJECT FileObject);
739
740 NTSTATUS
741 NtfsClose(PNTFS_IRP_CONTEXT IrpContext);
742
743
744 /* create.c */
745
746 NTSTATUS
747 NtfsCreate(PNTFS_IRP_CONTEXT IrpContext);
748
749 NTSTATUS
750 NtfsCreateFileRecord(PDEVICE_EXTENSION DeviceExt,
751 PFILE_OBJECT FileObject,
752 BOOLEAN CaseSensitive,
753 BOOLEAN CanWait);
754
755 /* devctl.c */
756
757 NTSTATUS
758 NtfsDeviceControl(PNTFS_IRP_CONTEXT IrpContext);
759
760
761 /* dirctl.c */
762
763 ULONGLONG
764 NtfsGetFileSize(PDEVICE_EXTENSION DeviceExt,
765 PFILE_RECORD_HEADER FileRecord,
766 PCWSTR Stream,
767 ULONG StreamLength,
768 PULONGLONG AllocatedSize);
769
770 NTSTATUS
771 NtfsDirectoryControl(PNTFS_IRP_CONTEXT IrpContext);
772
773
774 /* dispatch.c */
775
776 DRIVER_DISPATCH NtfsFsdDispatch;
777 NTSTATUS NTAPI
778 NtfsFsdDispatch(PDEVICE_OBJECT DeviceObject,
779 PIRP Irp);
780
781
782 /* fastio.c */
783
784 BOOLEAN NTAPI
785 NtfsAcqLazyWrite(PVOID Context,
786 BOOLEAN Wait);
787
788 VOID NTAPI
789 NtfsRelLazyWrite(PVOID Context);
790
791 BOOLEAN NTAPI
792 NtfsAcqReadAhead(PVOID Context,
793 BOOLEAN Wait);
794
795 VOID NTAPI
796 NtfsRelReadAhead(PVOID Context);
797
798 FAST_IO_CHECK_IF_POSSIBLE NtfsFastIoCheckIfPossible;
799 FAST_IO_READ NtfsFastIoRead;
800 FAST_IO_WRITE NtfsFastIoWrite;
801
802
803 /* fcb.c */
804
805 PNTFS_FCB
806 NtfsCreateFCB(PCWSTR FileName,
807 PCWSTR Stream,
808 PNTFS_VCB Vcb);
809
810 VOID
811 NtfsDestroyFCB(PNTFS_FCB Fcb);
812
813 BOOLEAN
814 NtfsFCBIsDirectory(PNTFS_FCB Fcb);
815
816 BOOLEAN
817 NtfsFCBIsReparsePoint(PNTFS_FCB Fcb);
818
819 BOOLEAN
820 NtfsFCBIsCompressed(PNTFS_FCB Fcb);
821
822 BOOLEAN
823 NtfsFCBIsRoot(PNTFS_FCB Fcb);
824
825 VOID
826 NtfsGrabFCB(PNTFS_VCB Vcb,
827 PNTFS_FCB Fcb);
828
829 VOID
830 NtfsReleaseFCB(PNTFS_VCB Vcb,
831 PNTFS_FCB Fcb);
832
833 VOID
834 NtfsAddFCBToTable(PNTFS_VCB Vcb,
835 PNTFS_FCB Fcb);
836
837 PNTFS_FCB
838 NtfsGrabFCBFromTable(PNTFS_VCB Vcb,
839 PCWSTR FileName);
840
841 NTSTATUS
842 NtfsFCBInitializeCache(PNTFS_VCB Vcb,
843 PNTFS_FCB Fcb);
844
845 PNTFS_FCB
846 NtfsMakeRootFCB(PNTFS_VCB Vcb);
847
848 PNTFS_FCB
849 NtfsOpenRootFCB(PNTFS_VCB Vcb);
850
851 NTSTATUS
852 NtfsAttachFCBToFileObject(PNTFS_VCB Vcb,
853 PNTFS_FCB Fcb,
854 PFILE_OBJECT FileObject);
855
856 NTSTATUS
857 NtfsGetFCBForFile(PNTFS_VCB Vcb,
858 PNTFS_FCB *pParentFCB,
859 PNTFS_FCB *pFCB,
860 PCWSTR pFileName,
861 BOOLEAN CaseSensitive);
862
863 NTSTATUS
864 NtfsReadFCBAttribute(PNTFS_VCB Vcb,
865 PNTFS_FCB pFCB,
866 ULONG Type,
867 PCWSTR Name,
868 ULONG NameLength,
869 PVOID * Data);
870
871 NTSTATUS
872 NtfsMakeFCBFromDirEntry(PNTFS_VCB Vcb,
873 PNTFS_FCB DirectoryFCB,
874 PUNICODE_STRING Name,
875 PCWSTR Stream,
876 PFILE_RECORD_HEADER Record,
877 ULONGLONG MFTIndex,
878 PNTFS_FCB * fileFCB);
879
880
881 /* finfo.c */
882
883 NTSTATUS
884 NtfsQueryInformation(PNTFS_IRP_CONTEXT IrpContext);
885
886 NTSTATUS
887 NtfsSetEndOfFile(PNTFS_FCB Fcb,
888 PFILE_OBJECT FileObject,
889 PDEVICE_EXTENSION DeviceExt,
890 ULONG IrpFlags,
891 BOOLEAN CaseSensitive,
892 PLARGE_INTEGER NewFileSize);
893
894 NTSTATUS
895 NtfsSetInformation(PNTFS_IRP_CONTEXT IrpContext);
896
897 /* fsctl.c */
898
899 NTSTATUS
900 NtfsFileSystemControl(PNTFS_IRP_CONTEXT IrpContext);
901
902
903 /* mft.c */
904 NTSTATUS
905 NtfsAddFilenameToDirectory(PDEVICE_EXTENSION DeviceExt,
906 ULONGLONG DirectoryMftIndex,
907 ULONGLONG FileReferenceNumber,
908 PFILENAME_ATTRIBUTE FilenameAttribute,
909 BOOLEAN CaseSensitive);
910
911 NTSTATUS
912 AddNewMftEntry(PFILE_RECORD_HEADER FileRecord,
913 PDEVICE_EXTENSION DeviceExt,
914 PULONGLONG DestinationIndex,
915 BOOLEAN CanWait);
916
917 PNTFS_ATTR_CONTEXT
918 PrepareAttributeContext(PNTFS_ATTR_RECORD AttrRecord);
919
920 VOID
921 ReleaseAttributeContext(PNTFS_ATTR_CONTEXT Context);
922
923 ULONG
924 ReadAttribute(PDEVICE_EXTENSION Vcb,
925 PNTFS_ATTR_CONTEXT Context,
926 ULONGLONG Offset,
927 PCHAR Buffer,
928 ULONG Length);
929
930 NTSTATUS
931 WriteAttribute(PDEVICE_EXTENSION Vcb,
932 PNTFS_ATTR_CONTEXT Context,
933 ULONGLONG Offset,
934 const PUCHAR Buffer,
935 ULONG Length,
936 PULONG LengthWritten);
937
938 ULONGLONG
939 AttributeDataLength(PNTFS_ATTR_RECORD AttrRecord);
940
941 VOID
942 InternalSetResidentAttributeLength(PNTFS_ATTR_CONTEXT AttrContext,
943 PFILE_RECORD_HEADER FileRecord,
944 ULONG AttrOffset,
945 ULONG DataSize);
946
947 NTSTATUS
948 SetAttributeDataLength(PFILE_OBJECT FileObject,
949 PNTFS_FCB Fcb,
950 PNTFS_ATTR_CONTEXT AttrContext,
951 ULONG AttrOffset,
952 PFILE_RECORD_HEADER FileRecord,
953 PLARGE_INTEGER DataSize);
954
955 VOID
956 SetFileRecordEnd(PFILE_RECORD_HEADER FileRecord,
957 PNTFS_ATTR_RECORD AttrEnd,
958 ULONG EndMarker);
959
960 NTSTATUS
961 SetNonResidentAttributeDataLength(PDEVICE_EXTENSION Vcb,
962 PNTFS_ATTR_CONTEXT AttrContext,
963 ULONG AttrOffset,
964 PFILE_RECORD_HEADER FileRecord,
965 PLARGE_INTEGER DataSize);
966
967 NTSTATUS
968 SetResidentAttributeDataLength(PDEVICE_EXTENSION Vcb,
969 PNTFS_ATTR_CONTEXT AttrContext,
970 ULONG AttrOffset,
971 PFILE_RECORD_HEADER FileRecord,
972 PLARGE_INTEGER DataSize);
973
974 ULONGLONG
975 AttributeAllocatedLength(PNTFS_ATTR_RECORD AttrRecord);
976
977 BOOLEAN
978 CompareFileName(PUNICODE_STRING FileName,
979 PINDEX_ENTRY_ATTRIBUTE IndexEntry,
980 BOOLEAN DirSearch,
981 BOOLEAN CaseSensitive);
982
983 NTSTATUS
984 ReadFileRecord(PDEVICE_EXTENSION Vcb,
985 ULONGLONG index,
986 PFILE_RECORD_HEADER file);
987
988 NTSTATUS
989 UpdateIndexEntryFileNameSize(PDEVICE_EXTENSION Vcb,
990 PFILE_RECORD_HEADER MftRecord,
991 PCHAR IndexRecord,
992 ULONG IndexBlockSize,
993 PINDEX_ENTRY_ATTRIBUTE FirstEntry,
994 PINDEX_ENTRY_ATTRIBUTE LastEntry,
995 PUNICODE_STRING FileName,
996 PULONG StartEntry,
997 PULONG CurrentEntry,
998 BOOLEAN DirSearch,
999 ULONGLONG NewDataSize,
1000 ULONGLONG NewAllocatedSize,
1001 BOOLEAN CaseSensitive);
1002
1003 NTSTATUS
1004 UpdateFileNameRecord(PDEVICE_EXTENSION Vcb,
1005 ULONGLONG ParentMFTIndex,
1006 PUNICODE_STRING FileName,
1007 BOOLEAN DirSearch,
1008 ULONGLONG NewDataSize,
1009 ULONGLONG NewAllocationSize,
1010 BOOLEAN CaseSensitive);
1011
1012 NTSTATUS
1013 UpdateFileRecord(PDEVICE_EXTENSION Vcb,
1014 ULONGLONG MftIndex,
1015 PFILE_RECORD_HEADER FileRecord);
1016
1017 NTSTATUS
1018 FindAttribute(PDEVICE_EXTENSION Vcb,
1019 PFILE_RECORD_HEADER MftRecord,
1020 ULONG Type,
1021 PCWSTR Name,
1022 ULONG NameLength,
1023 PNTFS_ATTR_CONTEXT * AttrCtx,
1024 PULONG Offset);
1025
1026 VOID
1027 ReadVCN(PDEVICE_EXTENSION Vcb,
1028 PFILE_RECORD_HEADER file,
1029 ATTRIBUTE_TYPE type,
1030 ULONGLONG vcn,
1031 ULONG count,
1032 PVOID buffer);
1033
1034 NTSTATUS
1035 FixupUpdateSequenceArray(PDEVICE_EXTENSION Vcb,
1036 PNTFS_RECORD_HEADER Record);
1037
1038 NTSTATUS
1039 AddFixupArray(PDEVICE_EXTENSION Vcb,
1040 PNTFS_RECORD_HEADER Record);
1041
1042 NTSTATUS
1043 ReadLCN(PDEVICE_EXTENSION Vcb,
1044 ULONGLONG lcn,
1045 ULONG count,
1046 PVOID buffer);
1047
1048 VOID
1049 EnumerAttribute(PFILE_RECORD_HEADER file,
1050 PDEVICE_EXTENSION Vcb,
1051 PDEVICE_OBJECT DeviceObject);
1052
1053 NTSTATUS
1054 NtfsLookupFile(PDEVICE_EXTENSION Vcb,
1055 PUNICODE_STRING PathName,
1056 BOOLEAN CaseSensitive,
1057 PFILE_RECORD_HEADER *FileRecord,
1058 PULONGLONG MFTIndex);
1059
1060 NTSTATUS
1061 NtfsLookupFileAt(PDEVICE_EXTENSION Vcb,
1062 PUNICODE_STRING PathName,
1063 BOOLEAN CaseSensitive,
1064 PFILE_RECORD_HEADER *FileRecord,
1065 PULONGLONG MFTIndex,
1066 ULONGLONG CurrentMFTIndex);
1067
1068 VOID
1069 NtfsDumpFileRecord(PDEVICE_EXTENSION Vcb,
1070 PFILE_RECORD_HEADER FileRecord);
1071
1072 NTSTATUS
1073 NtfsFindFileAt(PDEVICE_EXTENSION Vcb,
1074 PUNICODE_STRING SearchPattern,
1075 PULONG FirstEntry,
1076 PFILE_RECORD_HEADER *FileRecord,
1077 PULONGLONG MFTIndex,
1078 ULONGLONG CurrentMFTIndex,
1079 BOOLEAN CaseSensitive);
1080
1081 NTSTATUS
1082 NtfsFindMftRecord(PDEVICE_EXTENSION Vcb,
1083 ULONGLONG MFTIndex,
1084 PUNICODE_STRING FileName,
1085 PULONG FirstEntry,
1086 BOOLEAN DirSearch,
1087 BOOLEAN CaseSensitive,
1088 ULONGLONG *OutMFTIndex);
1089
1090 /* misc.c */
1091
1092 BOOLEAN
1093 NtfsIsIrpTopLevel(PIRP Irp);
1094
1095 PNTFS_IRP_CONTEXT
1096 NtfsAllocateIrpContext(PDEVICE_OBJECT DeviceObject,
1097 PIRP Irp);
1098
1099 PVOID
1100 NtfsGetUserBuffer(PIRP Irp,
1101 BOOLEAN Paging);
1102
1103 NTSTATUS
1104 NtfsLockUserBuffer(IN PIRP Irp,
1105 IN ULONG Length,
1106 IN LOCK_OPERATION Operation);
1107
1108 #if 0
1109 BOOLEAN
1110 wstrcmpjoki(PWSTR s1, PWSTR s2);
1111
1112 VOID
1113 CdfsSwapString(PWCHAR Out,
1114 PUCHAR In,
1115 ULONG Count);
1116 #endif
1117
1118 VOID
1119 NtfsFileFlagsToAttributes(ULONG NtfsAttributes,
1120 PULONG FileAttributes);
1121
1122
1123 /* rw.c */
1124
1125 NTSTATUS
1126 NtfsRead(PNTFS_IRP_CONTEXT IrpContext);
1127
1128 NTSTATUS
1129 NtfsWrite(PNTFS_IRP_CONTEXT IrpContext);
1130
1131
1132 /* volinfo.c */
1133
1134 NTSTATUS
1135 NtfsAllocateClusters(PDEVICE_EXTENSION DeviceExt,
1136 ULONG FirstDesiredCluster,
1137 ULONG DesiredClusters,
1138 PULONG FirstAssignedCluster,
1139 PULONG AssignedClusters);
1140
1141 ULONGLONG
1142 NtfsGetFreeClusters(PDEVICE_EXTENSION DeviceExt);
1143
1144 NTSTATUS
1145 NtfsQueryVolumeInformation(PNTFS_IRP_CONTEXT IrpContext);
1146
1147 NTSTATUS
1148 NtfsSetVolumeInformation(PNTFS_IRP_CONTEXT IrpContext);
1149
1150
1151 /* ntfs.c */
1152
1153 DRIVER_INITIALIZE DriverEntry;
1154
1155 VOID
1156 NTAPI
1157 NtfsInitializeFunctionPointers(PDRIVER_OBJECT DriverObject);
1158
1159 #endif /* NTFS_H */