VirtualHardDisk.Win32.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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.IO;
  10. using System.Text;
  11. using Utilities;
  12. using DiskAccessLibrary.VHD;
  13. namespace DiskAccessLibrary
  14. {
  15. public partial class VirtualHardDisk : DiskImage, IDiskGeometry
  16. {
  17. public override void ExtendFast(long additionalNumberOfBytes)
  18. {
  19. if (additionalNumberOfBytes % this.BytesPerSector > 0)
  20. {
  21. throw new ArgumentException("additionalNumberOfBytes must be a multiple of BytesPerSector");
  22. }
  23. if (m_vhdFooter.DiskType == VirtualHardDiskType.Fixed)
  24. {
  25. long length = this.Size; // does not include the footer
  26. m_file.ExtendFast(additionalNumberOfBytes);
  27. m_vhdFooter.CurrentSize += (ulong)additionalNumberOfBytes;
  28. byte[] footerBytes = m_vhdFooter.GetBytes();
  29. m_file.WriteSectors((length + additionalNumberOfBytes) / this.BytesPerSector, footerBytes);
  30. }
  31. else
  32. {
  33. throw new NotImplementedException();
  34. }
  35. }
  36. }
  37. }