123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- public class DiskExtent
- {
- private Disk m_disk;
- private long m_firstSector;
- private long m_size;
- public DiskExtent(Disk disk, long firstSector, long size)
- {
- m_disk = disk;
- m_firstSector = firstSector;
- m_size = size;
- }
- public byte[] ReadSector(long sectorIndex)
- {
- return ReadSectors(sectorIndex, 1);
- }
- public byte[] ReadSectors(long sectorIndex, int sectorCount)
- {
- CheckBoundaries(sectorIndex, sectorCount);
- return m_disk.ReadSectors(m_firstSector + sectorIndex, sectorCount);
- }
- public void WriteSectors(long sectorIndex, byte[] data)
- {
- CheckBoundaries(sectorIndex, data.Length / this.BytesPerSector);
- m_disk.WriteSectors(m_firstSector + sectorIndex, data);
- }
- public void CheckBoundaries(long sectorIndex, int sectorCount)
- {
- if (sectorIndex < 0 || sectorIndex + (sectorCount - 1) >= this.TotalSectors)
- {
- throw new ArgumentOutOfRangeException("Attempted to access data outside of volume");
- }
- }
- public int BytesPerSector
- {
- get
- {
- return m_disk.BytesPerSector;
- }
- }
- public long Size
- {
- get
- {
- return m_size;
- }
- }
- public long FirstSector
- {
- get
- {
- return m_firstSector;
- }
- }
- public long TotalSectors
- {
- get
- {
- return this.Size / this.BytesPerSector;
- }
- }
- public long LastSector
- {
- get
- {
- return FirstSector + TotalSectors - 1;
- }
- }
- public Disk Disk
- {
- get
- {
- return m_disk;
- }
- }
- }
|