Skip to content

Commit 6e5666b

Browse files
committed
NTFS: FileRecord: UpdateSegments: Set AttributeRecord's Instance value using NextAttributeInstance of the FileRecordSegment containing it
1 parent 97cd52b commit 6e5666b

File tree

3 files changed

+8
-20
lines changed

3 files changed

+8
-20
lines changed

DiskAccessLibrary/FileSystems/NTFS/AttributeData/AttributeData.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ public void Extend(ulong additionalLengthInBytes)
214214
throw new DiskFullException();
215215
}
216216
NonResidentAttributeRecord attributeRecord = NonResidentAttributeRecord.Create(m_attributeRecord.AttributeType, m_attributeRecord.Name);
217-
attributeRecord.Instance = m_attributeRecord.Instance;
218217
NonResidentAttributeData attributeData = new NonResidentAttributeData(m_volume, null, attributeRecord);
219218
attributeData.Extend(finalDataLength);
220219
attributeData.WriteClusters(0, data);

DiskAccessLibrary/FileSystems/NTFS/FileRecord/FileRecord.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public void UpdateSegments(int bytesPerFileRecordSegment, byte minorNTFSVersion)
4040
foreach (FileRecordSegment segment in m_segments)
4141
{
4242
segment.ImmediateAttributes.Clear();
43+
segment.NextAttributeInstance = 0;
4344
}
4445

4546
int segmentLength = bytesPerFileRecordSegment - FileRecordSegment.GetNumberOfBytesAvailable(bytesPerFileRecordSegment, minorNTFSVersion);
@@ -54,7 +55,7 @@ public void UpdateSegments(int bytesPerFileRecordSegment, byte minorNTFSVersion)
5455
// A single record segment is needed
5556
foreach (AttributeRecord attribute in attributes)
5657
{
57-
m_segments[0].ImmediateAttributes.Add(attribute);
58+
m_segments[0].AddAttributeRecord(attribute);
5859
}
5960

6061
// Free the rest of the segments, if there are any
@@ -86,8 +87,6 @@ public AttributeRecord CreateAttributeRecord(AttributeType type, string name)
8687
{
8788
bool isResident = (type != AttributeType.IndexAllocation);
8889
AttributeRecord attribute = AttributeRecord.Create(type, name, isResident);
89-
attribute.Instance = m_segments[0].NextAttributeInstance;
90-
m_segments[0].NextAttributeInstance++;
9190
FileRecordHelper.InsertSorted(this.Attributes, attribute);
9291
return attribute;
9392
}

DiskAccessLibrary/FileSystems/NTFS/FileRecord/FileRecordHelper.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ public static List<AttributeRecord> GetAssembledAttributes(List<FileRecordSegmen
4141

4242
if (!additionalFragment && fragments.Count > 0)
4343
{
44-
NonResidentAttributeRecord assembledAttribute = AssembleFragments(fragments, segments[0].NextAttributeInstance);
45-
segments[0].NextAttributeInstance++;
44+
NonResidentAttributeRecord assembledAttribute = AssembleFragments(fragments);
4645
result.Add(assembledAttribute);
4746
fragments.Clear();
4847
}
@@ -65,15 +64,14 @@ public static List<AttributeRecord> GetAssembledAttributes(List<FileRecordSegmen
6564

6665
if (fragments.Count > 0)
6766
{
68-
NonResidentAttributeRecord assembledAttribute = AssembleFragments(fragments, segments[0].NextAttributeInstance);
69-
segments[0].NextAttributeInstance++;
67+
NonResidentAttributeRecord assembledAttribute = AssembleFragments(fragments);
7068
result.Add(assembledAttribute);
7169
}
7270

7371
return result;
7472
}
7573

76-
private static NonResidentAttributeRecord AssembleFragments(List<NonResidentAttributeRecord> attributeFragments, ushort nextAttributeInstance)
74+
private static NonResidentAttributeRecord AssembleFragments(List<NonResidentAttributeRecord> attributeFragments)
7775
{
7876
// Attribute fragments are written to disk sorted by LowestVCN
7977
NonResidentAttributeRecord firstFragment = attributeFragments[0];
@@ -84,7 +82,6 @@ private static NonResidentAttributeRecord AssembleFragments(List<NonResidentAttr
8482
}
8583

8684
NonResidentAttributeRecord attribute = NonResidentAttributeRecord.Create(firstFragment.AttributeType, firstFragment.Name);
87-
attribute.Instance = nextAttributeInstance;
8885
attribute.Flags = firstFragment.Flags;
8986
attribute.LowestVCN = 0;
9087
attribute.HighestVCN = -1;
@@ -130,12 +127,12 @@ public static void SliceAttributes(List<FileRecordSegment> segments, List<Attrib
130127
if (attribute.AttributeType == AttributeType.StandardInformation ||
131128
attribute.AttributeType == AttributeType.FileName)
132129
{
133-
baseFileRecordSegment.ImmediateAttributes.Add(attribute);
130+
baseFileRecordSegment.AddAttributeRecord(attribute);
134131
}
135132
else if (isMftFileRecord && attribute.AttributeType == AttributeType.Data)
136133
{
137134
List<NonResidentAttributeRecord> slices = SliceAttributeRecord((NonResidentAttributeRecord)attribute, bytesPerFileRecordSegment / 2, bytesAvailableInSegment);
138-
baseFileRecordSegment.ImmediateAttributes.Add(slices[0]);
135+
baseFileRecordSegment.AddAttributeRecord(slices[0]);
139136
slices.RemoveAt(0);
140137
foreach (NonResidentAttributeRecord slice in slices)
141138
{
@@ -166,13 +163,8 @@ public static void SliceAttributes(List<FileRecordSegment> segments, List<Attrib
166163
if (attribute.RecordLength <= remainingLengthInCurrentSegment)
167164
{
168165
remainingLengthInCurrentSegment -= (int)attribute.RecordLength;
169-
segments[segmentIndex].ImmediateAttributes.Add(attribute);
166+
segments[segmentIndex].AddAttributeRecord(attribute);
170167
remainingAttributes.RemoveFirst();
171-
// Instead of renumbering each attribute slice in the new FileRecordSegment, we use the original Instance number.
172-
if (segments[segmentIndex].NextAttributeInstance <= attribute.Instance)
173-
{
174-
segments[segmentIndex].NextAttributeInstance = (ushort)(attribute.Instance + 1);
175-
}
176168
}
177169
else
178170
{
@@ -219,9 +211,7 @@ private static NonResidentAttributeRecord FitMaxNumberOfRuns(NonResidentAttribut
219211
{
220212
// Each attribute record is aligned to 8-byte boundary, we must have enough room for padding
221213
availableLength = (int)Math.Floor((double)availableLength / 8) * 8;
222-
// Note that we're using the original record Instance instead of using the FileRecordSegment.NextAttributeInstance
223214
NonResidentAttributeRecord slice = new NonResidentAttributeRecord(record.AttributeType, record.Name);
224-
slice.Instance = record.Instance;
225215
DataRunSequence dataRuns = record.DataRunSequence;
226216
long clusterCount = 0;
227217
for (int index = 0; index < runIndex; index++)

0 commit comments

Comments
 (0)