-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
AttributeAddress->Type = AttributeData;
AttributeAddress->Length = ResidentHeaderLength;
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;
AttributeAddress->Resident.ValueLength = 0;
AttributeAddress->Resident.ValueOffset = ResidentHeaderLength;
AttributeAddress->Length = ResidentHeaderLength +
FIELD_OFFSET(FILENAME_ATTRIBUTE, Name) + FilenameNoPath.Length;
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;
AttributeAddress->Resident.ValueLength = FIELD_OFFSET(FILENAME_ATTRIBUTE, Name) + FilenameNoPath.Length;
AttributeAddress->Resident.ValueOffset = ResidentHeaderLength;
// calculate position of end markers
NextAttributeOffset = AttrOffset + AttrContext->Record.NonResident.MappingPairsOffset + RunBufferSize;
// 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;
// Update the length
DestinationAttribute->Length = NextAttributeOffset - AttrOffset;
AttributeAddress->Type = AttributeStandardInformation;
AttributeAddress->Length = sizeof(STANDARD_INFORMATION) + ResidentHeaderLength;
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++;
AttributeAddress->Resident.ValueLength = sizeof(STANDARD_INFORMATION);
AttributeAddress->Resident.ValueOffset = ResidentHeaderLength;
AttributeAddress->Instance = FileRecord->NextAttributeNumber++;
if (NextAttribute->Type == AttributeEnd)
{
// update attribute length
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
DestinationAttribute->Length = AttrContext->Record.Length;
// write end markers
GetPackedByteCount(LONGLONG NumberToPack,
BOOLEAN IsSigned)
{
GetPackedByteCount(LONGLONG NumberToPack,
BOOLEAN IsSigned)
{
if (!IsSigned)
{
if (NumberToPack >= 0x0100000000000000)
if (!IsSigned)
{
if (NumberToPack >= 0x0100000000000000)
return 3;
if (NumberToPack >= 0x0000000000000080)
return 2;
return 3;
if (NumberToPack >= 0x0000000000000080)
return 2;
return 3;
if (NumberToPack <= 0xffffffffffffff80)
return 2;
return 3;
if (NumberToPack <= 0xffffffffffffff80)
return 2;
PINDEX_ROOT_ATTRIBUTE *IndexRoot,
ULONG *Length)
{
PINDEX_ROOT_ATTRIBUTE *IndexRoot,
ULONG *Length)
{
PB_TREE_KEY CurrentKey;
PINDEX_ENTRY_ATTRIBUTE CurrentNodeEntry;
PINDEX_ROOT_ATTRIBUTE NewIndexRoot = ExAllocatePoolWithTag(NonPagedPool,
PB_TREE_KEY CurrentKey;
PINDEX_ENTRY_ATTRIBUTE CurrentNodeEntry;
PINDEX_ROOT_ATTRIBUTE NewIndexRoot = ExAllocatePoolWithTag(NonPagedPool,
{
PB_TREE_KEY NextKey;
PB_TREE_KEY CurrentKey = Node->FirstKey;
{
PB_TREE_KEY NextKey;
PB_TREE_KEY CurrentKey = Node->FirstKey;
for (i = 0; i < Node->KeyCount; i++)
{
NT_ASSERT(CurrentKey);
for (i = 0; i < Node->KeyCount; i++)
{
NT_ASSERT(CurrentKey);
-DumpBTreeKey(PB_TREE_KEY Key, int Number, int Depth)
+DumpBTreeKey(PB_TREE_KEY Key, ULONG Number, ULONG Depth)
for (i = 0; i < Depth; i++)
DbgPrint(" ");
DbgPrint(" Key #%d", Number);
for (i = 0; i < Depth; i++)
DbgPrint(" ");
DbgPrint(" Key #%d", Number);
-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;
for (i = 0; i < Depth; i++)
DbgPrint(" ");
DbgPrint("Node #%d, Depth %d\n", Number, Depth);
for (i = 0; i < Depth; i++)
DbgPrint(" ");
DbgPrint("Node #%d, Depth %d\n", Number, Depth);
ULONG EntrySize = ALIGN_UP_BY(AttributeSize + FIELD_OFFSET(INDEX_ENTRY_ATTRIBUTE, FileName), 8);
PINDEX_ENTRY_ATTRIBUTE NewEntry;
PB_TREE_KEY NewKey, CurrentKey, PreviousKey;
ULONG EntrySize = ALIGN_UP_BY(AttributeSize + FIELD_OFFSET(INDEX_ENTRY_ATTRIBUTE, FileName), 8);
PINDEX_ENTRY_ATTRIBUTE NewEntry;
PB_TREE_KEY NewKey, CurrentKey, PreviousKey;
DPRINT1("NtfsInsertKey(0x%02I64, %p, %p, %s)\n",
FileReference,
DPRINT1("NtfsInsertKey(0x%02I64, %p, %p, %s)\n",
FileReference,
// setup other file record fields
FileRecord->SequenceNumber = 1;
FileRecord->AttributeOffset = FileRecord->Ntfs.UsaOffset + (2 * FileRecord->Ntfs.UsaCount);
// 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;
FileRecord->Flags = FRH_IN_USE;
FileRecord->BytesInUse = FileRecord->AttributeOffset + sizeof(ULONG) * 2;
// Ensure NextAttributeOffset is aligned to an 8-byte boundary
if (NextAttributeOffset % 8 != 0)
{
// 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;
NextAttributeOffset += Padding;
AttrContext->Record.Length += Padding;
Destination->Length += Padding;
// 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;
// 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;
// Update the length
Destination->Length = EndAttributeOffset - AttrOffset;
};
} 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
{
ULONGLONG CreationTime;
typedef struct
{
ULONGLONG CreationTime;
// A key's sub-node precedes that key in the ordered list.
typedef struct
{
// A key's sub-node precedes that key in the ordered list.
typedef struct
{
PB_TREE_KEY FirstKey;
} B_TREE_FILENAME_NODE, *PB_TREE_FILENAME_NODE;
PB_TREE_KEY FirstKey;
} B_TREE_FILENAME_NODE, *PB_TREE_FILENAME_NODE;