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