Esempio n. 1
0
        public NTFSVolume(Volume volume, bool useMftMirror)
        {
            m_volume = volume;

            byte[] bootSector = m_volume.ReadSector(0);
            m_bootRecord = NTFSBootRecord.ReadRecord(bootSector);
            if (m_bootRecord == null)
            {
                throw new InvalidDataException("The volume does not contain a valid NTFS boot record");
            }
            m_mft = new MasterFileTable(this, useMftMirror);
            m_volumeInformation = GetVolumeInformationRecord();
            if (m_volumeInformation.IsDirty)
            {
                throw new NotSupportedException("The volume is marked dirty, please run CHKDSK to repair the volume");
            }
            // Note: We could support NTFS v1.2 with minimal effort, but there isn't really any point.
            if (!(m_volumeInformation.MajorVersion == 3 && m_volumeInformation.MinorVersion == 0) &&
                !(m_volumeInformation.MajorVersion == 3 && m_volumeInformation.MinorVersion == 1))
            {
                throw new NotSupportedException(String.Format("NTFS v{0}.{1} is not supported", m_volumeInformation.MajorVersion, m_volumeInformation.MinorVersion));
            }
            m_logFile   = new LogFile(this);
            m_logClient = new NTFSLogClient(m_logFile);
            m_bitmap    = new VolumeBitmap(this);
            NumberOfClustersRequiredToExtendIndex = (int)Math.Ceiling((double)(IndexData.ExtendGranularity * m_bootRecord.BytesPerIndexRecord) / m_bootRecord.BytesPerCluster);
        }
Esempio n. 2
0
        public NTFSVolume(Volume volume, bool useMftMirror)
        {
            m_volume = volume;

            byte[] bootSector = m_volume.ReadSector(0);
            m_bootRecord = NTFSBootRecord.ReadRecord(bootSector);
            if (m_bootRecord != null)
            {
                m_mft               = new MasterFileTable(this, useMftMirror);
                m_bitmap            = new VolumeBitmap(this);
                m_volumeInformation = GetVolumeInformationRecord();
            }
        }
Esempio n. 3
0
        private static void WriteVolumeBitmap(Volume volume, long volumeBitmapStartSector, long volumeClusterCount, long numberOfClustersInUse)
        {
            int transferSize = (int)Math.Ceiling((double)numberOfClustersInUse / (volume.BytesPerSector * 8));

            byte[] transferBytes = new byte[transferSize * volume.BytesPerSector];
            for (int clusterIndex = 0; clusterIndex < numberOfClustersInUse; clusterIndex++)
            {
                VolumeBitmap.SetBit(transferBytes, clusterIndex);
            }
            volume.WriteSectors(volumeBitmapStartSector, transferBytes);

            long numberOfVolumeBitmapSectors = (long)Math.Ceiling((double)volumeClusterCount / (volume.BytesPerSector * 8));
            long sectorOffset = transferSize;

            while (sectorOffset < numberOfVolumeBitmapSectors)
            {
                long sectorsRemaining = numberOfVolumeBitmapSectors - sectorOffset;
                transferSize  = (int)Math.Min(Settings.MaximumTransferSizeLBA, sectorsRemaining);
                transferBytes = new byte[transferSize * volume.BytesPerSector];
                volume.WriteSectors(volumeBitmapStartSector + sectorOffset, transferBytes);
                sectorOffset += transferSize;
            }
        }