Example #1
0
        public byte[] ReadSectors(long firstSectorIndex, int count)
        {
            if (m_attributeRecord is NonResidentAttributeRecord)
            {
                NonResidentAttributeData attributeData = new NonResidentAttributeData(m_volume, m_fileRecord, (NonResidentAttributeRecord)m_attributeRecord);
                return(attributeData.ReadSectors(firstSectorIndex, count));
            }
            else
            {
                byte[] data               = ((ResidentAttributeRecord)m_attributeRecord).Data;
                long   totalSectors       = (long)Math.Ceiling((double)data.Length / m_volume.BytesPerSector);
                long   highestSectorIndex = Math.Max(totalSectors - 1, 0);
                if (firstSectorIndex < 0 || firstSectorIndex > highestSectorIndex)
                {
                    throw new ArgumentOutOfRangeException("firstSectorIndex is not within the valid range");
                }

                int offset = (int)firstSectorIndex * m_volume.BytesPerSector;
                int bytesToRead;
                if (offset + count * m_volume.BytesPerSector <= data.Length)
                {
                    bytesToRead = count * m_volume.BytesPerCluster;
                }
                else
                {
                    bytesToRead = data.Length - offset;
                }
                return(ByteReader.ReadBytes(data, offset, bytesToRead));
            }
        }
Example #2
0
        private IndexRecord ReadIndexRecord(long subnodeVBN)
        {
            long sectorIndex = ConvertToSectorIndex(subnodeVBN);

            byte[]      recordBytes = m_indexAllocationData.ReadSectors(sectorIndex, this.SectorsPerIndexRecord);
            IndexRecord record      = new IndexRecord(recordBytes, 0);

            return(record);
        }
        internal IndexRecord ReadIndexRecord(long subnodeVBN)
        {
            long sectorIndex = ConvertToSectorIndex(subnodeVBN);

            byte[] recordBytes = m_indexAllocationData.ReadSectors(sectorIndex, this.SectorsPerIndexRecord);
            MultiSectorHelper.RevertUsaProtection(recordBytes, 0);
            IndexRecord record = new IndexRecord(recordBytes, 0);

            return(record);
        }