Skip to content

Commit 077a14d

Browse files
committed
NTFS: AttributeRecord: Added Clone method
1 parent 2b3b19f commit 077a14d

File tree

11 files changed

+78
-0
lines changed

11 files changed

+78
-0
lines changed

DiskAccessLibrary/FileSystems/NTFS/AttributeRecord/AttributeRecord.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ public void WriteHeader(byte[] buffer, ushort nameOffset)
7171
}
7272
}
7373

74+
public abstract AttributeRecord Clone();
75+
7476
public AttributeType AttributeType
7577
{
7678
get

DiskAccessLibrary/FileSystems/NTFS/AttributeRecord/FileNameAttributeRecord.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ public override byte[] GetBytes()
3434
return base.GetBytes();
3535
}
3636

37+
public override AttributeRecord Clone()
38+
{
39+
FileNameAttributeRecord clone = (FileNameAttributeRecord)base.Clone();
40+
clone.Record = this.Record.Clone();
41+
return clone;
42+
}
43+
3744
public override ulong DataLength
3845
{
3946
get

DiskAccessLibrary/FileSystems/NTFS/AttributeRecord/IndexRootRecord.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ public override byte[] GetBytes()
6161
return base.GetBytes();
6262
}
6363

64+
public override AttributeRecord Clone()
65+
{
66+
IndexRootRecord clone = (IndexRootRecord)base.Clone();
67+
clone.m_indexHeader = m_indexHeader.Clone();
68+
clone.IndexEntries = new List<IndexEntry>();
69+
foreach (IndexEntry entry in IndexEntries)
70+
{
71+
clone.IndexEntries.Add(entry.Clone());
72+
}
73+
return clone;
74+
}
75+
6476
public override ulong DataLength
6577
{
6678
get

DiskAccessLibrary/FileSystems/NTFS/AttributeRecord/NonResidentAttributeRecord.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ public KeyValuePairList<long, long> GetClustersInUse()
8787
return sequence;
8888
}
8989

90+
public override AttributeRecord Clone()
91+
{
92+
NonResidentAttributeRecord clone = (NonResidentAttributeRecord)this.MemberwiseClone();
93+
clone.m_dataRunSequence = m_dataRunSequence.Clone();
94+
return clone;
95+
}
96+
9097
/// <summary>
9198
/// Each attribute record must be aligned to 8-byte boundary, so RecordLength must be a multiple of 8.
9299
/// When reading attributes, they may contain additional padding,

DiskAccessLibrary/FileSystems/NTFS/AttributeRecord/ResidentAttributeRecord.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ public override byte[] GetBytes()
5858
return buffer;
5959
}
6060

61+
public override AttributeRecord Clone()
62+
{
63+
ResidentAttributeRecord clone = (ResidentAttributeRecord)this.MemberwiseClone();
64+
clone.Data = (byte[])this.Data.Clone();
65+
return clone;
66+
}
67+
6168
public override ulong DataLength
6269
{
6370
get

DiskAccessLibrary/FileSystems/NTFS/Index/IndexEntry.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ public void WriteBytes(byte[] buffer, int offset)
7373
}
7474
}
7575

76+
public IndexEntry Clone()
77+
{
78+
IndexEntry clone = (IndexEntry)this.MemberwiseClone();
79+
clone.FileReference = this.FileReference.Clone();
80+
return clone;
81+
}
82+
7683
public byte[] GetBytes()
7784
{
7885
byte[] buffer = new byte[Length];

DiskAccessLibrary/FileSystems/NTFS/Index/IndexHeader.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public void WriteBytes(byte[] buffer, int offset)
4141
ByteWriter.WriteByte(buffer, offset + 0x0C, (byte)IndexFlags);
4242
}
4343

44+
public IndexHeader Clone()
45+
{
46+
return (IndexHeader)this.MemberwiseClone();
47+
}
48+
4449
public bool IsParentNode
4550
{
4651
get

DiskAccessLibrary/FileSystems/NTFS/Structures/DataRun.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ public byte[] GetBytes()
7474
return buffer;
7575
}
7676

77+
public DataRun Clone()
78+
{
79+
return (DataRun)this.MemberwiseClone();
80+
}
81+
7782
private static long ReadVarLong(ref byte[] buffer, int offset, int size)
7883
{
7984
ulong val = 0;

DiskAccessLibrary/FileSystems/NTFS/Structures/DataRunSequence.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public DataRunSequence() : base()
2121
{
2222
}
2323

24+
public DataRunSequence(int capacity) : base(capacity)
25+
{
26+
}
27+
2428
public DataRunSequence(byte[] buffer, int offset, int length) : base()
2529
{
2630
int position = offset;
@@ -200,6 +204,16 @@ public long GetDataClusterLCN(long clusterVCN)
200204
throw new InvalidDataException("Invalid cluster VCN");
201205
}
202206

207+
public DataRunSequence Clone()
208+
{
209+
DataRunSequence clone = new DataRunSequence(this.Count);
210+
foreach (DataRun run in this)
211+
{
212+
clone.Add(run.Clone());
213+
}
214+
return clone;
215+
}
216+
203217
public override string ToString()
204218
{
205219
StringBuilder builder = new StringBuilder();

DiskAccessLibrary/FileSystems/NTFS/Structures/FileNameRecord.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ public byte[] GetBytes()
7878
return buffer;
7979
}
8080

81+
public FileNameRecord Clone()
82+
{
83+
FileNameRecord clone = (FileNameRecord)this.MemberwiseClone();
84+
clone.ParentDirectory = this.ParentDirectory.Clone();
85+
return clone;
86+
}
87+
8188
/// <param name="fileNameNamespace">POSIX or Win32 or DOS, multiple flags are not supported</param>
8289
public bool IsInNamespace(FileNameFlags fileNameNamespace)
8390
{

0 commit comments

Comments
 (0)