Example #1
0
        /// <remarks>
        /// https://blogs.technet.microsoft.com/askcore/2009/10/16/the-four-stages-of-ntfs-file-growth/
        /// </remarks>
        public void UpdateSegments(int bytesPerFileRecordSegment, byte minorNTFSVersion)
        {
            m_segments[0].ReferenceCount = ReferenceCount;
            m_segments[0].IsInUse        = IsInUse;
            m_segments[0].IsDirectory    = IsDirectory;
            List <AttributeRecord> attributes = this.Attributes;

            foreach (FileRecordSegment segment in m_segments)
            {
                segment.ImmediateAttributes.Clear();
                segment.NextAttributeInstance = 0;
            }

            int segmentLength = bytesPerFileRecordSegment - FileRecordSegment.GetNumberOfBytesAvailable(bytesPerFileRecordSegment, minorNTFSVersion);

            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].AddAttributeRecord(attribute.Clone());
                }

                // 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);
            }
        }
Example #2
0
        /// <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);
            }
        }