ReadCapacity16Parameter.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* Copyright (C) 2012-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 SCSI
  12. {
  13. public class ReadCapacity16Parameter
  14. {
  15. public const int Length = 32;
  16. public ulong ReturnedLBA; // the LBA of the last logical block on the direct-access block device
  17. public uint BlockLengthInBytes; // block size
  18. public ReadCapacity16Parameter()
  19. {
  20. }
  21. public ReadCapacity16Parameter(byte[] buffer)
  22. {
  23. ReturnedLBA = BigEndianConverter.ToUInt64(buffer, 0);
  24. BlockLengthInBytes = BigEndianConverter.ToUInt32(buffer, 8);
  25. }
  26. public ReadCapacity16Parameter(long diskSize, uint blockSizeInBytes)
  27. {
  28. ReturnedLBA = (ulong)diskSize / blockSizeInBytes - 1; // zero-based LBA of the last logical block
  29. BlockLengthInBytes = blockSizeInBytes;
  30. }
  31. public byte[] GetBytes()
  32. {
  33. byte[] buffer = new byte[Length];
  34. BigEndianWriter.WriteUInt64(buffer, 0, ReturnedLBA);
  35. BigEndianWriter.WriteUInt32(buffer, 8, BlockLengthInBytes);
  36. return buffer;
  37. }
  38. }
  39. }