RAMDisk.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* Copyright (C) 2016 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. using Utilities;
  11. namespace DiskAccessLibrary
  12. {
  13. public class RAMDisk : Disk
  14. {
  15. public const int BytesPerRAMDiskSector = 512;
  16. private byte[] m_diskBytes;
  17. /// <summary>
  18. /// A single-dimensional byte array cannot contain more than 0X7FFFFFC7 bytes (2047.999 MiB).
  19. /// https://msdn.microsoft.com/en-us/library/System.Array(v=vs.110).aspx
  20. /// </summary>
  21. public RAMDisk(int size)
  22. {
  23. m_diskBytes = new byte[size];
  24. }
  25. public override byte[] ReadSectors(long sectorIndex, int sectorCount)
  26. {
  27. return ByteReader.ReadBytes(m_diskBytes, (int)sectorIndex * BytesPerRAMDiskSector, sectorCount * BytesPerRAMDiskSector);
  28. }
  29. public override void WriteSectors(long sectorIndex, byte[] data)
  30. {
  31. ByteWriter.WriteBytes(m_diskBytes, (int)sectorIndex * BytesPerRAMDiskSector, data);
  32. }
  33. public override int BytesPerSector
  34. {
  35. get
  36. {
  37. return BytesPerRAMDiskSector;
  38. }
  39. }
  40. public override long Size
  41. {
  42. get
  43. {
  44. return m_diskBytes.Length;
  45. }
  46. }
  47. }
  48. }