public int GetNumberOfBytesFree(int bytesPerFileRecordSegment, ushort minorNTFSVersion) { int firstAttributeOffset = FileRecordSegment.GetFirstAttributeOffset(bytesPerFileRecordSegment, minorNTFSVersion); int numberOfBytesAvailable = bytesPerFileRecordSegment - firstAttributeOffset - EndMarkerLength; foreach (AttributeRecord attribute in m_immediateAttributes) { numberOfBytesAvailable -= attribute.RecordLength; } return(numberOfBytesAvailable); }
public void UpdateSegments(int maximumSegmentLength, int bytesPerSector, ushort minorNTFSVersion) { foreach (FileRecordSegment segment in m_segments) { segment.ImmediateAttributes.Clear(); } int segmentLength = FileRecordSegment.GetFirstAttributeOffset(maximumSegmentLength, minorNTFSVersion); segmentLength += FileRecordSegment.EndMarkerLength; foreach (AttributeRecord attribute in this.Attributes) { segmentLength += (int)attribute.RecordLength; } if (segmentLength <= maximumSegmentLength) { // a single record segment is needed FileRecordSegment baseRecordSegment = m_segments[0]; foreach (AttributeRecord attribute in this.Attributes) { baseRecordSegment.ImmediateAttributes.Add(attribute); } // free the rest of the segments, if there are any for (int index = 1; index < m_segments.Count; index++) { m_segments[index].IsInUse = false; } } else { // we have to check if we can make some data streams non-resident, // otherwise we have to use child segments and create an attribute list throw new NotImplementedException(); } }
/// <remarks> /// https://blogs.technet.microsoft.com/askcore/2009/10/16/the-four-stages-of-ntfs-file-growth/ /// </remarks> public void UpdateSegments(int bytesPerFileRecordSegment, ushort minorNTFSVersion) { List <AttributeRecord> attributes = this.Attributes; foreach (FileRecordSegment segment in m_segments) { segment.ImmediateAttributes.Clear(); } int segmentLength = FileRecordSegment.GetFirstAttributeOffset(bytesPerFileRecordSegment, minorNTFSVersion); segmentLength += FileRecordSegment.EndMarkerLength; foreach (AttributeRecord attribute in attributes) { segmentLength += (int)attribute.RecordLength; } if (segmentLength <= bytesPerFileRecordSegment) { // A single record segment is needed foreach (AttributeRecord attribute in attributes) { m_segments[0].ImmediateAttributes.Add(attribute); } // free the rest of the segments, if there are any for (int index = 1; index < m_segments.Count; index++) { m_segments[index].IsInUse = false; } } else { // We slice the attributes and put them in segments, the attribute list will be built by the caller after the new segments will be allocated FileRecordHelper.SliceAttributes(m_segments, attributes, bytesPerFileRecordSegment, minorNTFSVersion); } }
public static int GetNumberOfBytesAvailable(int bytesPerFileRecordSegment, ushort minorNTFSVersion) { int firstAttributeOffset = FileRecordSegment.GetFirstAttributeOffset(bytesPerFileRecordSegment, minorNTFSVersion); return(bytesPerFileRecordSegment - firstAttributeOffset - AttributesEndMarkerLength); }