// // Copyright (c) 2008-2011, Kenneth Bell // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. // namespace DiscUtils.Ntfs.Internals { using System.Collections.Generic; using InternalMasterFileTable = DiscUtils.Ntfs.MasterFileTable; /// /// Provides read-only access to the Master File Table of an NTFS file system. /// public sealed class MasterFileTable { /// /// Index of the Master File Table itself. /// public const long MasterFileTableIndex = 0; /// /// Index of the Master File Table Mirror file. /// public const long MasterFileTableMirrorIndex = 1; /// /// Index of the Log file. /// public const long LogFileIndex = 2; /// /// Index of the Volume file. /// public const long VolumeIndex = 3; /// /// Index of the Attribute Definition file. /// public const long AttributeDefinitionIndex = 4; /// /// Index of the Root Directory. /// public const long RootDirectoryIndex = 5; /// /// Index of the Bitmap file. /// public const long BitmapIndex = 6; /// /// Index of the Boot sector(s). /// public const long BootIndex = 7; /// /// Index of the Bad Cluster file. /// public const long BadClusterIndex = 8; /// /// Index of the Security Descriptor file. /// public const long SecureIndex = 9; /// /// Index of the Uppercase mapping file. /// public const long UppercaseIndex = 10; /// /// Index of the Optional Extensions directory. /// public const long ExtendDirectoryIndex = 11; /// /// First index available for 'normal' files. /// private const uint FirstNormalFileIndex = 24; private INtfsContext _context; private InternalMasterFileTable _mft; internal MasterFileTable(INtfsContext context, InternalMasterFileTable mft) { _context = context; _mft = mft; } /// /// Gets an entry by index. /// /// The index of the entry. /// The entry. public MasterFileTableEntry this[long index] { get { FileRecord mftRecord = _mft.GetRecord(index, true, true); if (mftRecord != null) { return new MasterFileTableEntry(_context, mftRecord); } else { return null; } } } /// /// Enumerates all entries. /// /// Filter controlling which entries are returned. /// An enumeration of entries matching the filter. public IEnumerable GetEntries(EntryStates filter) { foreach (var record in _mft.Records) { EntryStates state; if ((record.Flags & FileRecordFlags.InUse) != 0) { state = EntryStates.InUse; } else { state = EntryStates.NotInUse; } if ((state & filter) != 0) { yield return new MasterFileTableEntry(_context, record); } } } } }