/// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbLockingAndxRequestPacket(SmbLockingAndxRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount                = packet.SmbParameters.WordCount;
            this.smbParameters.AndXCommand              = packet.SmbParameters.AndXCommand;
            this.smbParameters.AndXReserved             = packet.SmbParameters.AndXReserved;
            this.smbParameters.AndXOffset               = packet.SmbParameters.AndXOffset;
            this.smbParameters.FID                      = packet.SmbParameters.FID;
            this.smbParameters.TypeOfLock               = packet.SmbParameters.TypeOfLock;
            this.smbParameters.NewOplockLevel           = packet.SmbParameters.NewOplockLevel;
            this.smbParameters.Timeout                  = packet.SmbParameters.Timeout;
            this.smbParameters.NumberOfRequestedUnlocks = packet.SmbParameters.NumberOfRequestedUnlocks;
            this.smbParameters.NumberOfRequestedLocks   = packet.SmbParameters.NumberOfRequestedLocks;

            this.smbData.ByteCount = packet.SmbData.ByteCount;
            if (packet.smbData.Unlocks != null)
            {
                this.smbData.Unlocks = new Object[packet.smbData.Unlocks.Length];
                for (int i = 0; i < packet.smbData.Unlocks.Length; i++)
                {
                    this.smbData.Unlocks[i] = packet.smbData.Unlocks[i];
                }
            }
            if (packet.smbData.Locks != null)
            {
                this.smbData.Locks = new Object[packet.smbData.Locks.Length];
                for (int i = 0; i < packet.smbData.Locks.Length; i++)
                {
                    this.smbData.Locks[i] = packet.smbData.Locks[i];
                }
            }
        }
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbLockingAndxRequestPacket(SmbLockingAndxRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount = packet.SmbParameters.WordCount;
            this.smbParameters.AndXCommand = packet.SmbParameters.AndXCommand;
            this.smbParameters.AndXReserved = packet.SmbParameters.AndXReserved;
            this.smbParameters.AndXOffset = packet.SmbParameters.AndXOffset;
            this.smbParameters.FID = packet.SmbParameters.FID;
            this.smbParameters.TypeOfLock = packet.SmbParameters.TypeOfLock;
            this.smbParameters.NewOplockLevel = packet.SmbParameters.NewOplockLevel;
            this.smbParameters.Timeout = packet.SmbParameters.Timeout;
            this.smbParameters.NumberOfRequestedUnlocks = packet.SmbParameters.NumberOfRequestedUnlocks;
            this.smbParameters.NumberOfRequestedLocks = packet.SmbParameters.NumberOfRequestedLocks;

            this.smbData.ByteCount = packet.SmbData.ByteCount;
            if (packet.smbData.Unlocks != null)
            {
                this.smbData.Unlocks = new Object[packet.smbData.Unlocks.Length];
                for (int i = 0; i < packet.smbData.Unlocks.Length; i++)
                {
                    this.smbData.Unlocks[i] = packet.smbData.Unlocks[i];
                }
            }
            if (packet.smbData.Locks != null)
            {
                this.smbData.Locks = new Object[packet.smbData.Locks.Length];
                for (int i = 0; i < packet.smbData.Locks.Length; i++)
                {
                    this.smbData.Locks[i] = packet.smbData.Locks[i];
                }
            }
        }
        public SmbLockingAndxResponsePacket CreateLockingAndxResponse(
            CifsServerPerConnection connection,
            SmbLockingAndxRequestPacket request,
            SmbPacket andxPacket)
        {
            SmbLockingAndxResponsePacket response = new SmbLockingAndxResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            SMB_COM_LOCKING_ANDX_Response_SMB_Parameters smbParameters = response.SmbParameters;
            smbParameters.AndXCommand =
                andxPacket != null ? andxPacket.SmbHeader.Command : SmbCommand.SMB_COM_NO_ANDX_COMMAND;
            smbParameters.AndXReserved = 0x00;
            smbParameters.AndXOffset = (ushort)(response.HeaderSize + Marshal.SizeOf(response.SmbParameters)
                    + Marshal.SizeOf(response.SmbData));
            smbParameters.WordCount = (byte)(TypeMarshal.GetBlockMemorySize(smbParameters) / 2);
            response.SmbParameters = smbParameters;

            response.AndxPacket = andxPacket;
            response.UpdateHeader();

            return response;
        }
        /// <summary>
        /// to create a LockingAndx request packet.
        /// </summary>
        /// <param name="messageId">This field SHOULD be the multiplex ID that is used to associate a response with a
        /// request.</param>
        /// <param name="uid">This field SHOULD identify the authenticated instance of the user.</param>
        /// <param name="treeId">This field identifies the subdirectory (or tree) on the server that the client is
        /// accessing.</param>
        /// <param name="flags">An 8-bit field of 1-bit flags describing various features in effect for the
        /// message</param>
        /// <param name="flags2">A 16-bit field of 1-bit flags that represent various features in effect for the
        /// message. Unspecified bits are reserved and MUST be zero.</param>
        /// <param name="fid">This field MUST be a valid 16-bit signed integer indicating the file from which the data
        /// SHOULD be read</param>
        /// <param name="typeOfLock">This field is a 8-bit unsigned integer bit mask indicating the nature of the lock
        /// request and the format of the LOCKING_ANDX_RANGE data</param>
        /// <param name="newOplockLevel">This field is valid only in SMB_COM_LOCKING_ANDX SMB requests sent from the
        /// server to the client in response to a change in the existing Oplock's state</param>
        /// <param name="timeout">This field is a 32-bit unsigned integer value</param>
        /// <param name="unlocks">An array of byte ranges to be unlocked. If 32-bit offsets are being used, this field
        /// uses LOCKING_ANDX_RANGE32 (see below) and is (10 * NumberOfRequestedUnlocks) bytes in length. If 64-bit
        /// offsets are being used, this field uses LOCKING_ANDX_RANGE64 (see below) and is (20 *
        /// NumberOfRequestedUnlocks) bytes in length.</param>
        /// <param name="locks">An array of byte ranges to be locked. If 32-bit offsets are being used, this field uses
        /// LOCKING_ANDX_RANGE32 (see below) and is (10 * NumberOfRequestedUnlocks) bytes in length. If 64-bit offsets
        /// are being used, this field uses LOCKING_ANDX_RANGE64 (see below) and is (20 * NumberOfRequestedUnlocks)
        /// bytes in length</param>
        /// <param name="andxPacket">the andx packet.</param>
        /// <returns>a LockingAndx request packet</returns>
        public SmbLockingAndxRequestPacket CreateLockingAndxRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            ushort fid,
            LockingAndxTypeOfLock typeOfLock,
            NewOplockLevelValue newOplockLevel,
            uint timeout,
            Object[] unlocks,
            Object[] locks,
            SmbPacket andxPacket)
        {
            if (unlocks == null)
            {
                unlocks = new Object[0];
            }
            if (locks == null)
            {
                locks = new Object[0];
            }

            SmbLockingAndxRequestPacket packet = new SmbLockingAndxRequestPacket();

            packet.SmbHeader = CifsMessageUtils.CreateSmbHeader(SmbCommand.SMB_COM_LOCKING_ANDX,
                messageId, uid, treeId, flags, flags2);

            SMB_COM_LOCKING_ANDX_Request_SMB_Parameters smbParameters =
                new SMB_COM_LOCKING_ANDX_Request_SMB_Parameters();
            if (andxPacket == null)
            {
                smbParameters.AndXCommand = SmbCommand.SMB_COM_NO_ANDX_COMMAND;
            }
            else
            {
                smbParameters.AndXCommand = andxPacket.SmbHeader.Command;
            }
            smbParameters.AndXReserved = 0;
            smbParameters.FID = fid;
            smbParameters.TypeOfLock = typeOfLock;
            smbParameters.NewOplockLevel = newOplockLevel;
            smbParameters.Timeout = timeout;
            smbParameters.NumberOfRequestedUnlocks = (ushort)unlocks.Length;
            smbParameters.NumberOfRequestedLocks = (ushort)locks.Length;
            smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord);

            SMB_COM_LOCKING_ANDX_Request_SMB_Data smbData = new SMB_COM_LOCKING_ANDX_Request_SMB_Data();
            smbData.Locks = locks;
            smbData.Unlocks = unlocks;
            smbData.ByteCount = 0;
            foreach (object lockItem in unlocks)
            {
                smbData.ByteCount += (ushort)Marshal.SizeOf(lockItem);
            }
            foreach (object lockItem in locks)
            {
                smbData.ByteCount += (ushort)Marshal.SizeOf(lockItem);
            }

            packet.SmbParameters = smbParameters;
            packet.SmbData = smbData;
            packet.AndxPacket = andxPacket;

            return packet;
        }
        public SmbLockingAndxRequestPacket CreateLockingAndxRequest(
            CifsServerPerOpenFile open,
            NewOplockLevelValue newOplockLevel)
        {
            SmbLockingAndxRequestPacket request = new SmbLockingAndxRequestPacket();
            SmbHeader smbHeader = new SmbHeader();
            smbHeader.Protocol = CifsMessageUtils.SMB_PROTOCOL_IDENTIFIER;
            smbHeader.Command = SmbCommand.SMB_COM_LOCKING_ANDX;
            smbHeader.Uid = (ushort)open.Session.SessionId;
            smbHeader.Tid = (ushort)open.TreeConnect.TreeConnectId;
            smbHeader.Mid = CifsMessageUtils.INVALID_MID;

            request.SmbHeader = smbHeader;

            SMB_COM_LOCKING_ANDX_Request_SMB_Parameters smbParameters = request.SmbParameters;
            smbParameters.FID = (ushort)open.FileId;
            smbParameters.NewOplockLevel = newOplockLevel;
            smbParameters.TypeOfLock = LockingAndxTypeOfLock.OPLOCK_RELEASE;
            smbParameters.WordCount = (byte)(TypeMarshal.GetBlockMemorySize(smbParameters) / 2);
            request.SmbParameters = smbParameters;

            request.AndxPacket = null;

            return request;
        }