コード例 #1
0
        public void WriteRecord(FileRecord record)
        {
            int recordSize = record.Size;

            if (recordSize > RecordSize)
            {
                throw new IOException("Attempting to write over-sized MFT record");
            }

            byte[] buffer = new byte[RecordSize];
            record.ToBytes(buffer, 0);

            _recordStream.Position = record.MasterFileTableIndex * RecordSize;
            _recordStream.Write(buffer, 0, RecordSize);
            _recordStream.Flush();

            // We may have modified our own meta-data by extending the data stream, so
            // make sure our records are up-to-date.
            if (_self.MftRecordIsDirty)
            {
                DirectoryEntry dirEntry = _self.DirectoryEntry;
                if (dirEntry != null)
                {
                    dirEntry.UpdateFrom(_self);
                }

                _self.UpdateRecordInMft();
            }

            // Need to update Mirror.  OpenRaw is OK because this is short duration, and we don't
            // extend or otherwise modify any meta-data, just the content of the Data stream.
            if (record.MasterFileTableIndex < 4 && _self.Context.GetFileByIndex != null)
            {
                File mftMirror = _self.Context.GetFileByIndex(MftMirrorIndex);
                if (mftMirror != null)
                {
                    using (Stream s = mftMirror.OpenStream(AttributeType.Data, null, FileAccess.ReadWrite))
                    {
                        s.Position = record.MasterFileTableIndex * RecordSize;
                        s.Write(buffer, 0, RecordSize);
                    }
                }
            }
        }
コード例 #2
0
        private void UpdateMetadata()
        {
            if (!_file.Context.ReadOnly)
            {
                // Update the standard information attribute - so it reflects the actual file state
                if (_isDirty)
                {
                    _file.Modified();
                }
                else
                {
                    _file.Accessed();
                }

                // Update the directory entry used to open the file, so it's accurate
                _entry.UpdateFrom(_file);

                // Write attribute changes back to the Master File Table
                _file.UpdateRecordInMft();
                _isDirty = false;
            }
        }
コード例 #3
0
ファイル: NtfsFileSystem.cs プロジェクト: alexcmd/DiscUtils
        private static void UpdateStandardInformation(DirectoryEntry dirEntry, File file, StandardInformationModifier modifier)
        {
            // Update the standard information attribute - so it reflects the actual file state
            NtfsStream stream = file.GetStream(AttributeType.StandardInformation, null);
            StandardInformation si = stream.GetContent<StandardInformation>();
            modifier(si);
            stream.SetContent(si);

            // Update the directory entry used to open the file, so it's accurate
            dirEntry.UpdateFrom(file);

            // Write attribute changes back to the Master File Table
            file.UpdateRecordInMft();
        }