Volume.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Copyright (C) 2014-2018 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. public abstract class Volume
  10. {
  11. /// <summary>
  12. /// Sector refers to physical disk sector, we can only read complete sectors
  13. /// </summary>
  14. public abstract byte[] ReadSectors(long sectorIndex, int sectorCount);
  15. public abstract void WriteSectors(long sectorIndex, byte[] data);
  16. public byte[] ReadSector(long sectorIndex)
  17. {
  18. return ReadSectors(sectorIndex, 1);
  19. }
  20. public void CheckBoundaries(long sectorIndex, int sectorCount)
  21. {
  22. if (sectorIndex < 0 || sectorIndex + sectorCount - 1 >= this.TotalSectors)
  23. {
  24. throw new ArgumentOutOfRangeException("Attempted to access data outside of volume");
  25. }
  26. }
  27. public abstract int BytesPerSector
  28. {
  29. get;
  30. }
  31. public abstract long Size
  32. {
  33. get;
  34. }
  35. public virtual bool IsReadOnly
  36. {
  37. get
  38. {
  39. return false;
  40. }
  41. }
  42. public abstract List<DiskExtent> Extents
  43. {
  44. get;
  45. }
  46. public long TotalSectors
  47. {
  48. get
  49. {
  50. return this.Size / this.BytesPerSector;
  51. }
  52. }
  53. }