mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 21:36:11 +00:00
[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
This commit is contained in:
parent
68a48b2758
commit
5ab24a5aae
5 changed files with 22 additions and 20 deletions
|
@ -77,7 +77,7 @@ AddData(PFILE_RECORD_HEADER FileRecord,
|
||||||
|
|
||||||
AttributeAddress->Type = AttributeData;
|
AttributeAddress->Type = AttributeData;
|
||||||
AttributeAddress->Length = ResidentHeaderLength;
|
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.ValueLength = 0;
|
||||||
AttributeAddress->Resident.ValueOffset = ResidentHeaderLength;
|
AttributeAddress->Resident.ValueOffset = ResidentHeaderLength;
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@ AddFileName(PFILE_RECORD_HEADER FileRecord,
|
||||||
|
|
||||||
AttributeAddress->Length = ResidentHeaderLength +
|
AttributeAddress->Length = ResidentHeaderLength +
|
||||||
FIELD_OFFSET(FILENAME_ATTRIBUTE, Name) + FilenameNoPath.Length;
|
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.ValueLength = FIELD_OFFSET(FILENAME_ATTRIBUTE, Name) + FilenameNoPath.Length;
|
||||||
AttributeAddress->Resident.ValueOffset = ResidentHeaderLength;
|
AttributeAddress->Resident.ValueOffset = ResidentHeaderLength;
|
||||||
|
@ -363,7 +363,7 @@ AddRun(PNTFS_VCB Vcb,
|
||||||
|
|
||||||
// calculate position of end markers
|
// calculate position of end markers
|
||||||
NextAttributeOffset = AttrOffset + AttrContext->Record.NonResident.MappingPairsOffset + RunBufferSize;
|
NextAttributeOffset = AttrOffset + AttrContext->Record.NonResident.MappingPairsOffset + RunBufferSize;
|
||||||
NextAttributeOffset = ALIGN_UP_BY(NextAttributeOffset, 8);
|
NextAttributeOffset = ALIGN_UP_BY(NextAttributeOffset, ATTR_RECORD_ALIGNMENT);
|
||||||
|
|
||||||
// Update the length
|
// Update the length
|
||||||
DestinationAttribute->Length = NextAttributeOffset - AttrOffset;
|
DestinationAttribute->Length = NextAttributeOffset - AttrOffset;
|
||||||
|
@ -437,7 +437,7 @@ AddStandardInformation(PFILE_RECORD_HEADER FileRecord,
|
||||||
|
|
||||||
AttributeAddress->Type = AttributeStandardInformation;
|
AttributeAddress->Type = AttributeStandardInformation;
|
||||||
AttributeAddress->Length = sizeof(STANDARD_INFORMATION) + ResidentHeaderLength;
|
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.ValueLength = sizeof(STANDARD_INFORMATION);
|
||||||
AttributeAddress->Resident.ValueOffset = ResidentHeaderLength;
|
AttributeAddress->Resident.ValueOffset = ResidentHeaderLength;
|
||||||
AttributeAddress->Instance = FileRecord->NextAttributeNumber++;
|
AttributeAddress->Instance = FileRecord->NextAttributeNumber++;
|
||||||
|
@ -847,7 +847,8 @@ FreeClusters(PNTFS_VCB Vcb,
|
||||||
if (NextAttribute->Type == AttributeEnd)
|
if (NextAttribute->Type == AttributeEnd)
|
||||||
{
|
{
|
||||||
// update attribute length
|
// 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;
|
DestinationAttribute->Length = AttrContext->Record.Length;
|
||||||
|
|
||||||
// write end markers
|
// write end markers
|
||||||
|
@ -1459,7 +1460,6 @@ UCHAR
|
||||||
GetPackedByteCount(LONGLONG NumberToPack,
|
GetPackedByteCount(LONGLONG NumberToPack,
|
||||||
BOOLEAN IsSigned)
|
BOOLEAN IsSigned)
|
||||||
{
|
{
|
||||||
int bytes = 0;
|
|
||||||
if (!IsSigned)
|
if (!IsSigned)
|
||||||
{
|
{
|
||||||
if (NumberToPack >= 0x0100000000000000)
|
if (NumberToPack >= 0x0100000000000000)
|
||||||
|
@ -1496,7 +1496,6 @@ GetPackedByteCount(LONGLONG NumberToPack,
|
||||||
return 3;
|
return 3;
|
||||||
if (NumberToPack >= 0x0000000000000080)
|
if (NumberToPack >= 0x0000000000000080)
|
||||||
return 2;
|
return 2;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1515,9 +1514,8 @@ GetPackedByteCount(LONGLONG NumberToPack,
|
||||||
return 3;
|
return 3;
|
||||||
if (NumberToPack <= 0xffffffffffffff80)
|
if (NumberToPack <= 0xffffffffffffff80)
|
||||||
return 2;
|
return 2;
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
return bytes;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
|
|
|
@ -271,7 +271,7 @@ CreateIndexRootFromBTree(PDEVICE_EXTENSION DeviceExt,
|
||||||
PINDEX_ROOT_ATTRIBUTE *IndexRoot,
|
PINDEX_ROOT_ATTRIBUTE *IndexRoot,
|
||||||
ULONG *Length)
|
ULONG *Length)
|
||||||
{
|
{
|
||||||
int i;
|
ULONG i;
|
||||||
PB_TREE_KEY CurrentKey;
|
PB_TREE_KEY CurrentKey;
|
||||||
PINDEX_ENTRY_ATTRIBUTE CurrentNodeEntry;
|
PINDEX_ENTRY_ATTRIBUTE CurrentNodeEntry;
|
||||||
PINDEX_ROOT_ATTRIBUTE NewIndexRoot = ExAllocatePoolWithTag(NonPagedPool,
|
PINDEX_ROOT_ATTRIBUTE NewIndexRoot = ExAllocatePoolWithTag(NonPagedPool,
|
||||||
|
@ -366,7 +366,7 @@ DestroyBTreeNode(PB_TREE_FILENAME_NODE Node)
|
||||||
{
|
{
|
||||||
PB_TREE_KEY NextKey;
|
PB_TREE_KEY NextKey;
|
||||||
PB_TREE_KEY CurrentKey = Node->FirstKey;
|
PB_TREE_KEY CurrentKey = Node->FirstKey;
|
||||||
int i;
|
ULONG i;
|
||||||
for (i = 0; i < Node->KeyCount; i++)
|
for (i = 0; i < Node->KeyCount; i++)
|
||||||
{
|
{
|
||||||
NT_ASSERT(CurrentKey);
|
NT_ASSERT(CurrentKey);
|
||||||
|
@ -400,9 +400,9 @@ DestroyBTree(PB_TREE Tree)
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
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++)
|
for (i = 0; i < Depth; i++)
|
||||||
DbgPrint(" ");
|
DbgPrint(" ");
|
||||||
DbgPrint(" Key #%d", Number);
|
DbgPrint(" Key #%d", Number);
|
||||||
|
@ -420,10 +420,10 @@ DumpBTreeKey(PB_TREE_KEY Key, int Number, int Depth)
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
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;
|
PB_TREE_KEY CurrentKey;
|
||||||
int i;
|
ULONG i;
|
||||||
for (i = 0; i < Depth; i++)
|
for (i = 0; i < Depth; i++)
|
||||||
DbgPrint(" ");
|
DbgPrint(" ");
|
||||||
DbgPrint("Node #%d, Depth %d\n", Number, Depth);
|
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);
|
ULONG EntrySize = ALIGN_UP_BY(AttributeSize + FIELD_OFFSET(INDEX_ENTRY_ATTRIBUTE, FileName), 8);
|
||||||
PINDEX_ENTRY_ATTRIBUTE NewEntry;
|
PINDEX_ENTRY_ATTRIBUTE NewEntry;
|
||||||
PB_TREE_KEY NewKey, CurrentKey, PreviousKey;
|
PB_TREE_KEY NewKey, CurrentKey, PreviousKey;
|
||||||
int i;
|
ULONG i;
|
||||||
|
|
||||||
DPRINT1("NtfsInsertKey(0x%02I64, %p, %p, %s)\n",
|
DPRINT1("NtfsInsertKey(0x%02I64, %p, %p, %s)\n",
|
||||||
FileReference,
|
FileReference,
|
||||||
|
|
|
@ -699,7 +699,7 @@ NtfsCreateFileRecord(PDEVICE_EXTENSION DeviceExt,
|
||||||
// setup other file record fields
|
// setup other file record fields
|
||||||
FileRecord->SequenceNumber = 1;
|
FileRecord->SequenceNumber = 1;
|
||||||
FileRecord->AttributeOffset = FileRecord->Ntfs.UsaOffset + (2 * FileRecord->Ntfs.UsaCount);
|
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->Flags = FRH_IN_USE;
|
||||||
FileRecord->BytesInUse = FileRecord->AttributeOffset + sizeof(ULONG) * 2;
|
FileRecord->BytesInUse = FileRecord->AttributeOffset + sizeof(ULONG) * 2;
|
||||||
|
|
||||||
|
|
|
@ -373,7 +373,7 @@ InternalSetResidentAttributeLength(PNTFS_ATTR_CONTEXT AttrContext,
|
||||||
// Ensure NextAttributeOffset is aligned to an 8-byte boundary
|
// Ensure NextAttributeOffset is aligned to an 8-byte boundary
|
||||||
if (NextAttributeOffset % 8 != 0)
|
if (NextAttributeOffset % 8 != 0)
|
||||||
{
|
{
|
||||||
USHORT Padding = 8 - (NextAttributeOffset % 8);
|
USHORT Padding = ATTR_RECORD_ALIGNMENT - (NextAttributeOffset % ATTR_RECORD_ALIGNMENT);
|
||||||
NextAttributeOffset += Padding;
|
NextAttributeOffset += Padding;
|
||||||
AttrContext->Record.Length += Padding;
|
AttrContext->Record.Length += Padding;
|
||||||
Destination->Length += Padding;
|
Destination->Length += Padding;
|
||||||
|
@ -731,7 +731,7 @@ SetResidentAttributeDataLength(PDEVICE_EXTENSION Vcb,
|
||||||
// update the end of the file record
|
// update the end of the file record
|
||||||
// calculate position of end markers (1 byte for empty data run)
|
// calculate position of end markers (1 byte for empty data run)
|
||||||
EndAttributeOffset = AttrOffset + AttrContext->Record.NonResident.MappingPairsOffset + 1;
|
EndAttributeOffset = AttrOffset + AttrContext->Record.NonResident.MappingPairsOffset + 1;
|
||||||
EndAttributeOffset = ALIGN_UP_BY(EndAttributeOffset, 8);
|
EndAttributeOffset = ALIGN_UP_BY(EndAttributeOffset, ATTR_RECORD_ALIGNMENT);
|
||||||
|
|
||||||
// Update the length
|
// Update the length
|
||||||
Destination->Length = EndAttributeOffset - AttrOffset;
|
Destination->Length = EndAttributeOffset - AttrOffset;
|
||||||
|
|
|
@ -293,6 +293,10 @@ typedef struct
|
||||||
};
|
};
|
||||||
} NTFS_ATTR_RECORD, *PNTFS_ATTR_RECORD;
|
} 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
|
typedef struct
|
||||||
{
|
{
|
||||||
ULONGLONG CreationTime;
|
ULONGLONG CreationTime;
|
||||||
|
@ -408,7 +412,7 @@ typedef struct _B_TREE_KEY
|
||||||
// A key's sub-node precedes that key in the ordered list.
|
// A key's sub-node precedes that key in the ordered list.
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int KeyCount;
|
ULONG KeyCount;
|
||||||
PB_TREE_KEY FirstKey;
|
PB_TREE_KEY FirstKey;
|
||||||
} B_TREE_FILENAME_NODE, *PB_TREE_FILENAME_NODE;
|
} B_TREE_FILENAME_NODE, *PB_TREE_FILENAME_NODE;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue