Author: tthompson Date: Wed Jul 5 16:29:16 2017 New Revision: 75288
URL: http://svn.reactos.org/svn/reactos?rev=75288&view=rev Log: [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.
Modified: branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/attrib.c branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/btree.c branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/create.c branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/mft.c branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/ntfs.h
Modified: branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/attrib.c URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2016/NTFS/drivers/filesyste... ============================================================================== --- branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/attrib.c [iso-8859-1] (original) +++ branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/attrib.c [iso-8859-1] Wed Jul 5 16:29:16 2017 @@ -77,7 +77,7 @@
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 @@
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 @@
// 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 @@
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 @@ 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 @@ GetPackedByteCount(LONGLONG NumberToPack, BOOLEAN IsSigned) { - int bytes = 0; if (!IsSigned) { if (NumberToPack >= 0x0100000000000000) @@ -1496,7 +1496,6 @@ return 3; if (NumberToPack >= 0x0000000000000080) return 2; - return 1; } else { @@ -1515,9 +1514,8 @@ return 3; if (NumberToPack <= 0xffffffffffffff80) return 2; - return 1; - } - return bytes; + } + return 1; }
NTSTATUS
Modified: branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/btree.c URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2016/NTFS/drivers/filesyste... ============================================================================== --- branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/btree.c [iso-8859-1] (original) +++ branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/btree.c [iso-8859-1] Wed Jul 5 16:29:16 2017 @@ -271,7 +271,7 @@ 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 @@ { 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 @@ }
VOID -DumpBTreeKey(PB_TREE_KEY Key, int Number, int Depth) -{ - int i; +DumpBTreeKey(PB_TREE_KEY Key, ULONG Number, ULONG Depth) +{ + ULONG i; for (i = 0; i < Depth; i++) DbgPrint(" "); DbgPrint(" Key #%d", Number); @@ -420,10 +420,10 @@ }
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 @@ 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,
Modified: branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/create.c URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2016/NTFS/drivers/filesyste... ============================================================================== --- branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/create.c [iso-8859-1] (original) +++ branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/create.c [iso-8859-1] Wed Jul 5 16:29:16 2017 @@ -699,7 +699,7 @@ // 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;
Modified: branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/mft.c URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2016/NTFS/drivers/filesyste... ============================================================================== --- branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/mft.c [iso-8859-1] (original) +++ branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/mft.c [iso-8859-1] Wed Jul 5 16:29:16 2017 @@ -373,7 +373,7 @@ // 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 @@ // 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;
Modified: branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/ntfs.h URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2016/NTFS/drivers/filesyste... ============================================================================== --- branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/ntfs.h [iso-8859-1] (original) +++ branches/GSoC_2016/NTFS/drivers/filesystems/ntfs/ntfs.h [iso-8859-1] Wed Jul 5 16:29:16 2017 @@ -293,6 +293,10 @@ }; } 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 @@ // 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;