SCSICommandDescriptorBlock6.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* Copyright (C) 2012-2017 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. /// 6-byte SCSI CDB
  15. /// </summary>
  16. public class SCSICommandDescriptorBlock6 : SCSICommandDescriptorBlock
  17. {
  18. public SCSICommandDescriptorBlock6(SCSIOpCodeName opCode) : base()
  19. {
  20. this.OpCode = opCode;
  21. }
  22. public SCSICommandDescriptorBlock6(byte[] buffer, int offset) : base()
  23. {
  24. OpCode = (SCSIOpCodeName)buffer[offset + 0];
  25. MiscellaneousCDBInformationHeader = (byte)((buffer[offset + 1] & 0xE0) >> 5);
  26. uint temp = BigEndianReader.ReadUInt24(buffer, offset + 1);
  27. LogicalBlockAddress = temp & 0x1FFFFF;
  28. TransferLength = buffer[offset + 4];
  29. Control = buffer[offset + 5];
  30. }
  31. public override byte[] GetBytes()
  32. {
  33. byte[] buffer = new byte[6];
  34. buffer[0] = (byte)OpCode;
  35. buffer[1] |= (byte)(MiscellaneousCDBInformationHeader << 5);
  36. buffer[1] |= (byte)((LogicalBlockAddress >> 16) & 0x1F);
  37. buffer[2] = (byte)((LogicalBlockAddress >> 8) & 0xFF);
  38. buffer[3] = (byte)((LogicalBlockAddress >> 0) & 0xFF);
  39. buffer[4] = (byte)TransferLength;
  40. buffer[5] = Control;
  41. return buffer;
  42. }
  43. }
  44. }