SCSICommandDescriptorBlock10.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. /// <summary>
  14. /// 10-byte SCSI CDB
  15. /// </summary>
  16. public class SCSICommandDescriptorBlock10 : SCSICommandDescriptorBlock
  17. {
  18. public SCSICommandDescriptorBlock10(SCSIOpCodeName opCode) : base()
  19. {
  20. this.OpCode = opCode;
  21. }
  22. public SCSICommandDescriptorBlock10(byte[] buffer, int offset) : base()
  23. {
  24. OpCode = (SCSIOpCodeName)buffer[offset + 0];
  25. MiscellaneousCDBInformationHeader = (byte)((buffer[offset + 1] & 0xE0) >> 5);
  26. ServiceAction = (ServiceAction)((buffer[offset + 1] & 0x1F));
  27. LogicalBlockAddress = BigEndianConverter.ToUInt32(buffer, offset + 2);
  28. MiscellaneousCDBinformation = buffer[offset + 6];
  29. TransferLength = BigEndianConverter.ToUInt16(buffer, offset + 7);
  30. Control = buffer[offset + 9];
  31. }
  32. public override byte[] GetBytes()
  33. {
  34. byte[] buffer = new byte[10];
  35. buffer[0] = (byte)OpCode;
  36. buffer[1] |= (byte)(MiscellaneousCDBInformationHeader << 5);
  37. buffer[1] |= (byte)((byte)ServiceAction & 0x1F);
  38. BigEndianWriter.WriteUInt32(buffer, 2, LogicalBlockAddress);
  39. buffer[6] = MiscellaneousCDBinformation;
  40. BigEndianWriter.WriteUInt16(buffer, 7, (ushort)TransferLength);
  41. buffer[9] = Control;
  42. return buffer;
  43. }
  44. }
  45. }