@@ -12,12 +12,14 @@ public class NonResidentAttributeData
1212 private NTFSVolume m_volume ;
1313 private FileRecord m_fileRecord ;
1414 private NonResidentAttributeRecord m_attributeRecord ;
15+ private ContentType m_contentType ;
1516
1617 public NonResidentAttributeData ( NTFSVolume volume , FileRecord fileRecord , NonResidentAttributeRecord attributeRecord )
1718 {
1819 m_volume = volume ;
1920 m_fileRecord = fileRecord ;
2021 m_attributeRecord = attributeRecord ;
22+ m_contentType = GetContentType ( fileRecord , attributeRecord . AttributeType ) ;
2123 }
2224
2325 /// <param name="clusterVCN">Cluster index</param>
@@ -68,7 +70,7 @@ public byte[] ReadSectors(long firstSectorIndex, int count)
6870 long bytesRead = 0 ;
6971 foreach ( KeyValuePair < long , int > run in sequence )
7072 {
71- byte [ ] data = m_volume . ReadSectors ( run . Key , run . Value ) ;
73+ byte [ ] data = m_volume . ReadSectors ( run . Key , run . Value , m_contentType ) ;
7274 Array . Copy ( data , 0 , result , bytesRead , data . Length ) ;
7375 bytesRead += data . Length ;
7476 }
@@ -164,7 +166,7 @@ public void WriteSectors(long firstSectorIndex, byte[] data)
164166 {
165167 byte [ ] sectors = new byte [ run . Value * bytesPerSector ] ;
166168 Array . Copy ( data , bytesWritten , sectors , 0 , sectors . Length ) ;
167- m_volume . WriteSectors ( run . Key , sectors ) ;
169+ m_volume . WriteSectors ( run . Key , sectors , m_contentType ) ;
168170 bytesWritten += sectors . Length ;
169171 }
170172
@@ -324,5 +326,42 @@ public NonResidentAttributeRecord AttributeRecord
324326 return m_attributeRecord ;
325327 }
326328 }
329+
330+ public static ContentType GetContentType ( FileRecord fileRecord , AttributeType attributeType )
331+ {
332+ if ( fileRecord != null )
333+ {
334+ long baseSegmentNumber = fileRecord . BaseSegmentNumber ;
335+ if ( baseSegmentNumber == MasterFileTable . MasterFileTableSegmentNumber || baseSegmentNumber == MasterFileTable . MftMirrorSegmentNumber )
336+ {
337+ return ( attributeType == AttributeType . Data ) ? ContentType . MftData : ContentType . MftBitmap ;
338+ }
339+ else if ( baseSegmentNumber == MasterFileTable . VolumeSegmentNumber )
340+ {
341+ return ContentType . VolumeBitmap ;
342+ }
343+ }
344+ return GetContentType ( attributeType ) ;
345+ }
346+
347+ public static ContentType GetContentType ( AttributeType attributeType )
348+ {
349+ if ( attributeType == AttributeType . AttributeList )
350+ {
351+ return ContentType . MftData ;
352+ }
353+ else if ( attributeType == AttributeType . IndexAllocation )
354+ {
355+ return ContentType . IndexData ;
356+ }
357+ else if ( attributeType == AttributeType . Bitmap )
358+ {
359+ return ContentType . IndexBitmap ;
360+ }
361+ else
362+ {
363+ return ContentType . FileData ;
364+ }
365+ }
327366 }
328367}
0 commit comments