https://git.reactos.org/?p=reactos.git;a=commitdiff;h=5ab24a5aaed797d556384e...
commit 5ab24a5aaed797d556384e81047e9f75cb903e49 Author: Trevor Thompson tmt256@email.vccs.edu AuthorDate: Wed Jul 5 16:29:16 2017 +0000
[NTFS] - Add a few fixes and improvements, most from CR-123: -Add ATTR_RECORD_ALIGNMENT define to replace magic value of 8 when we need to adjust an attribute's beginning or length. -Don't use int's. -GetPackedByteCount() - Remove unused "bytes" variable.
svn path=/branches/GSoC_2016/NTFS/; revision=75288 --- drivers/filesystems/ntfs/attrib.c | 16 +++++++--------- drivers/filesystems/ntfs/btree.c | 14 +++++++------- drivers/filesystems/ntfs/create.c | 2 +- drivers/filesystems/ntfs/mft.c | 4 ++-- drivers/filesystems/ntfs/ntfs.h | 6 +++++- 5 files changed, 22 insertions(+), 20 deletions(-)
diff --git a/drivers/filesystems/ntfs/attrib.c b/drivers/filesystems/ntfs/attrib.c index 018c69b20f..7dcdabbea5 100644 --- a/drivers/filesystems/ntfs/attrib.c +++ b/drivers/filesystems/ntfs/attrib.c @@ -77,7 +77,7 @@ AddData(PFILE_RECORD_HEADER FileRecord,
AttributeAddress->Type = AttributeData; AttributeAddress->Length = ResidentHeaderLength; - AttributeAddress->Length = ALIGN_UP_BY(AttributeAddress->Length, 8); + AttributeAddress->Length = ALIGN_UP_BY(AttributeAddress->Length, ATTR_RECORD_ALIGNMENT); AttributeAddress->Resident.ValueLength = 0; AttributeAddress->Resident.ValueOffset = ResidentHeaderLength;
@@ -241,7 +241,7 @@ AddFileName(PFILE_RECORD_HEADER FileRecord,
AttributeAddress->Length = ResidentHeaderLength + FIELD_OFFSET(FILENAME_ATTRIBUTE, Name) + FilenameNoPath.Length; - AttributeAddress->Length = ALIGN_UP_BY(AttributeAddress->Length, 8); + AttributeAddress->Length = ALIGN_UP_BY(AttributeAddress->Length, ATTR_RECORD_ALIGNMENT);
AttributeAddress->Resident.ValueLength = FIELD_OFFSET(FILENAME_ATTRIBUTE, Name) + FilenameNoPath.Length; AttributeAddress->Resident.ValueOffset = ResidentHeaderLength; @@ -363,7 +363,7 @@ AddRun(PNTFS_VCB Vcb,
// calculate position of end markers NextAttributeOffset = AttrOffset + AttrContext->Record.NonResident.MappingPairsOffset + RunBufferSize; - NextAttributeOffset = ALIGN_UP_BY(NextAttributeOffset, 8); + NextAttributeOffset = ALIGN_UP_BY(NextAttributeOffset, ATTR_RECORD_ALIGNMENT);
// Update the length DestinationAttribute->Length = NextAttributeOffset - AttrOffset; @@ -437,7 +437,7 @@ AddStandardInformation(PFILE_RECORD_HEADER FileRecord,
AttributeAddress->Type = AttributeStandardInformation; AttributeAddress->Length = sizeof(STANDARD_INFORMATION) + ResidentHeaderLength; - AttributeAddress->Length = ALIGN_UP_BY(AttributeAddress->Length, 8); + AttributeAddress->Length = ALIGN_UP_BY(AttributeAddress->Length, ATTR_RECORD_ALIGNMENT); AttributeAddress->Resident.ValueLength = sizeof(STANDARD_INFORMATION); AttributeAddress->Resident.ValueOffset = ResidentHeaderLength; AttributeAddress->Instance = FileRecord->NextAttributeNumber++; @@ -847,7 +847,8 @@ FreeClusters(PNTFS_VCB Vcb, if (NextAttribute->Type == AttributeEnd) { // update attribute length - AttrContext->Record.Length = ALIGN_UP_BY(AttrContext->Record.NonResident.MappingPairsOffset + RunBufferSize, 8); + AttrContext->Record.Length = ALIGN_UP_BY(AttrContext->Record.NonResident.MappingPairsOffset + RunBufferSize, + ATTR_RECORD_ALIGNMENT); DestinationAttribute->Length = AttrContext->Record.Length;
// write end markers @@ -1459,7 +1460,6 @@ UCHAR GetPackedByteCount(LONGLONG NumberToPack, BOOLEAN IsSigned) { - int bytes = 0; if (!IsSigned) { if (NumberToPack >= 0x0100000000000000) @@ -1496,7 +1496,6 @@ GetPackedByteCount(LONGLONG NumberToPack, return 3; if (NumberToPack >= 0x0000000000000080) return 2; - return 1; } else { @@ -1515,9 +1514,8 @@ GetPackedByteCount(LONGLONG NumberToPack, return 3; if (NumberToPack <= 0xffffffffffffff80) return 2; - return 1; } - return bytes; + return 1; }
NTSTATUS diff --git a/drivers/filesystems/ntfs/btree.c b/drivers/filesystems/ntfs/btree.c index f4641d005c..eff2b157ad 100644 --- a/drivers/filesystems/ntfs/btree.c +++ b/drivers/filesystems/ntfs/btree.c @@ -271,7 +271,7 @@ CreateIndexRootFromBTree(PDEVICE_EXTENSION DeviceExt, PINDEX_ROOT_ATTRIBUTE *IndexRoot, ULONG *Length) { - int i; + ULONG i; PB_TREE_KEY CurrentKey; PINDEX_ENTRY_ATTRIBUTE CurrentNodeEntry; PINDEX_ROOT_ATTRIBUTE NewIndexRoot = ExAllocatePoolWithTag(NonPagedPool, @@ -366,7 +366,7 @@ DestroyBTreeNode(PB_TREE_FILENAME_NODE Node) { PB_TREE_KEY NextKey; PB_TREE_KEY CurrentKey = Node->FirstKey; - int i; + ULONG i; for (i = 0; i < Node->KeyCount; i++) { NT_ASSERT(CurrentKey); @@ -400,9 +400,9 @@ DestroyBTree(PB_TREE Tree) }
VOID -DumpBTreeKey(PB_TREE_KEY Key, int Number, int Depth) +DumpBTreeKey(PB_TREE_KEY Key, ULONG Number, ULONG Depth) { - int i; + ULONG i; for (i = 0; i < Depth; i++) DbgPrint(" "); DbgPrint(" Key #%d", Number); @@ -420,10 +420,10 @@ DumpBTreeKey(PB_TREE_KEY Key, int Number, int Depth) }
VOID -DumpBTreeNode(PB_TREE_FILENAME_NODE Node, int Number, int Depth) +DumpBTreeNode(PB_TREE_FILENAME_NODE Node, ULONG Number, ULONG Depth) { PB_TREE_KEY CurrentKey; - int i; + ULONG i; for (i = 0; i < Depth; i++) DbgPrint(" "); DbgPrint("Node #%d, Depth %d\n", Number, Depth); @@ -488,7 +488,7 @@ NtfsInsertKey(ULONGLONG FileReference, ULONG EntrySize = ALIGN_UP_BY(AttributeSize + FIELD_OFFSET(INDEX_ENTRY_ATTRIBUTE, FileName), 8); PINDEX_ENTRY_ATTRIBUTE NewEntry; PB_TREE_KEY NewKey, CurrentKey, PreviousKey; - int i; + ULONG i;
DPRINT1("NtfsInsertKey(0x%02I64, %p, %p, %s)\n", FileReference, diff --git a/drivers/filesystems/ntfs/create.c b/drivers/filesystems/ntfs/create.c index 3c8ba81f02..8274d97992 100644 --- a/drivers/filesystems/ntfs/create.c +++ b/drivers/filesystems/ntfs/create.c @@ -699,7 +699,7 @@ NtfsCreateFileRecord(PDEVICE_EXTENSION DeviceExt, // setup other file record fields FileRecord->SequenceNumber = 1; FileRecord->AttributeOffset = FileRecord->Ntfs.UsaOffset + (2 * FileRecord->Ntfs.UsaCount); - FileRecord->AttributeOffset = ALIGN_UP_BY(FileRecord->AttributeOffset, 8); + FileRecord->AttributeOffset = ALIGN_UP_BY(FileRecord->AttributeOffset, ATTR_RECORD_ALIGNMENT); FileRecord->Flags = FRH_IN_USE; FileRecord->BytesInUse = FileRecord->AttributeOffset + sizeof(ULONG) * 2;
diff --git a/drivers/filesystems/ntfs/mft.c b/drivers/filesystems/ntfs/mft.c index 539b8f225c..87820e6457 100644 --- a/drivers/filesystems/ntfs/mft.c +++ b/drivers/filesystems/ntfs/mft.c @@ -373,7 +373,7 @@ InternalSetResidentAttributeLength(PNTFS_ATTR_CONTEXT AttrContext, // Ensure NextAttributeOffset is aligned to an 8-byte boundary if (NextAttributeOffset % 8 != 0) { - USHORT Padding = 8 - (NextAttributeOffset % 8); + USHORT Padding = ATTR_RECORD_ALIGNMENT - (NextAttributeOffset % ATTR_RECORD_ALIGNMENT); NextAttributeOffset += Padding; AttrContext->Record.Length += Padding; Destination->Length += Padding; @@ -731,7 +731,7 @@ SetResidentAttributeDataLength(PDEVICE_EXTENSION Vcb, // update the end of the file record // calculate position of end markers (1 byte for empty data run) EndAttributeOffset = AttrOffset + AttrContext->Record.NonResident.MappingPairsOffset + 1; - EndAttributeOffset = ALIGN_UP_BY(EndAttributeOffset, 8); + EndAttributeOffset = ALIGN_UP_BY(EndAttributeOffset, ATTR_RECORD_ALIGNMENT);
// Update the length Destination->Length = EndAttributeOffset - AttrOffset; diff --git a/drivers/filesystems/ntfs/ntfs.h b/drivers/filesystems/ntfs/ntfs.h index eb4d6f3f9f..ddb876daf9 100644 --- a/drivers/filesystems/ntfs/ntfs.h +++ b/drivers/filesystems/ntfs/ntfs.h @@ -293,6 +293,10 @@ typedef struct }; } NTFS_ATTR_RECORD, *PNTFS_ATTR_RECORD;
+// The beginning and length of an attribute record are always aligned to an 8-byte boundary, +// relative to the beginning of the file record. +#define ATTR_RECORD_ALIGNMENT 8 + typedef struct { ULONGLONG CreationTime; @@ -408,7 +412,7 @@ typedef struct _B_TREE_KEY // A key's sub-node precedes that key in the ordered list. typedef struct { - int KeyCount; + ULONG KeyCount; PB_TREE_KEY FirstKey; } B_TREE_FILENAME_NODE, *PB_TREE_FILENAME_NODE;