LockRequest.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Copyright (C) 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 Utilities;
  10. namespace SMBLibrary.SMB2
  11. {
  12. /// <summary>
  13. /// SMB2 LOCK Request
  14. /// </summary>
  15. public class LockRequest : SMB2Command
  16. {
  17. public const int DeclaredSize = 48;
  18. private ushort StructureSize;
  19. // ushort LockCount;
  20. public byte LSN; // 4 bits
  21. public uint LockSequenceIndex; // 28 bits
  22. public FileID FileId;
  23. public List<LockElement> Locks;
  24. public LockRequest() : base(SMB2CommandName.Lock)
  25. {
  26. StructureSize = DeclaredSize;
  27. }
  28. public LockRequest(byte[] buffer, int offset) : base(buffer, offset)
  29. {
  30. StructureSize = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 0);
  31. ushort lockCount = LittleEndianConverter.ToUInt16(buffer, offset + SMB2Header.Length + 2);
  32. uint temp = LittleEndianConverter.ToUInt32(buffer, offset + SMB2Header.Length + 4);
  33. LSN = (byte)(temp >> 28);
  34. LockSequenceIndex = (temp & 0x0FFFFFFF);
  35. FileId = new FileID(buffer, offset + SMB2Header.Length + 8);
  36. Locks = LockElement.ReadLockList(buffer, offset + SMB2Header.Length + 24, (int)lockCount);
  37. }
  38. public override void WriteCommandBytes(byte[] buffer, int offset)
  39. {
  40. LittleEndianWriter.WriteUInt16(buffer, offset + 0, StructureSize);
  41. LittleEndianWriter.WriteUInt16(buffer, offset + 2, (ushort)Locks.Count);
  42. LittleEndianWriter.WriteUInt32(buffer, offset + 4, (uint)(LSN & 0x0F) << 28 | (uint)(LockSequenceIndex & 0x0FFFFFFF));
  43. FileId.WriteBytes(buffer, offset + 8);
  44. LockElement.WriteLockList(buffer, offset + 24, Locks);
  45. }
  46. public override int CommandLength
  47. {
  48. get
  49. {
  50. return 48 + Locks.Count * LockElement.StructureLength;
  51. }
  52. }
  53. }
  54. }