Volume.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Copyright (C) 2014 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. public abstract class Volume
  11. {
  12. /// <summary>
  13. /// Sector refers to physical disk sector, we can only read complete sectors
  14. /// </summary>
  15. public abstract byte[] ReadSectors(long sectorIndex, int sectorCount);
  16. public abstract void WriteSectors(long sectorIndex, byte[] data);
  17. public byte[] ReadSector(long sectorIndex)
  18. {
  19. return ReadSectors(sectorIndex, 1);
  20. }
  21. public void CheckBoundaries(long sectorIndex, int sectorCount)
  22. {
  23. if (sectorIndex < 0 || sectorIndex + sectorCount - 1 >= this.TotalSectors)
  24. {
  25. throw new ArgumentOutOfRangeException("Attempted to access data outside of volume");
  26. }
  27. }
  28. public abstract int BytesPerSector
  29. {
  30. get;
  31. }
  32. public abstract long Size
  33. {
  34. get;
  35. }
  36. public abstract List<DiskExtent> Extents
  37. {
  38. get;
  39. }
  40. public long TotalSectors
  41. {
  42. get
  43. {
  44. return this.Size / this.BytesPerSector;
  45. }
  46. }
  47. }