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

            this.smbParameters.WordCount = packet.SmbParameters.WordCount;
            this.smbParameters.SearchAttributes = packet.SmbParameters.SearchAttributes;

            this.smbData.ByteCount = packet.SmbData.ByteCount;
            this.smbData.BufferFormat1 = packet.SmbData.BufferFormat1;

            if (packet.smbData.OldFileName != null)
            {
                this.smbData.OldFileName = new byte[packet.smbData.OldFileName.Length];
                Array.Copy(packet.smbData.OldFileName, this.smbData.OldFileName, packet.smbData.OldFileName.Length);
            }
            else
            {
                this.smbData.OldFileName = new byte[0];
            }
            this.smbData.BufferFormat2 = packet.SmbData.BufferFormat2;

            if (packet.smbData.NewFileName != null)
            {
                this.smbData.NewFileName = new byte[packet.smbData.NewFileName.Length];
                Array.Copy(packet.smbData.NewFileName, this.smbData.NewFileName, packet.smbData.NewFileName.Length);
            }
            else
            {
                this.smbData.NewFileName = new byte[0];
            }
        }
        /// <summary>
        /// Deep copy constructor.
        /// </summary>
        public SmbRenameRequestPacket(SmbRenameRequestPacket packet)
            : base(packet)
        {
            this.InitDefaultValue();

            this.smbParameters.WordCount        = packet.SmbParameters.WordCount;
            this.smbParameters.SearchAttributes = packet.SmbParameters.SearchAttributes;

            this.smbData.ByteCount     = packet.SmbData.ByteCount;
            this.smbData.BufferFormat1 = packet.SmbData.BufferFormat1;

            if (packet.smbData.OldFileName != null)
            {
                this.smbData.OldFileName = new byte[packet.smbData.OldFileName.Length];
                Array.Copy(packet.smbData.OldFileName, this.smbData.OldFileName, packet.smbData.OldFileName.Length);
            }
            else
            {
                this.smbData.OldFileName = new byte[0];
            }
            this.smbData.BufferFormat2 = packet.SmbData.BufferFormat2;

            if (packet.smbData.NewFileName != null)
            {
                this.smbData.NewFileName = new byte[packet.smbData.NewFileName.Length];
                Array.Copy(packet.smbData.NewFileName, this.smbData.NewFileName, packet.smbData.NewFileName.Length);
            }
            else
            {
                this.smbData.NewFileName = new byte[0];
            }
        }
        /// <summary>
        /// to create a Rename 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="searchAttributes">The file attributes of the file(s) to be deleted. If the value of this
        /// field is zero, then only normal files MUST be matched for deletion.  If the System or Hidden attributes
        /// MUST be specified, then entries with those attributes are matched in addition to the normal files. 
        /// Read-only files MAY NOT be deleted. The read-only attribute of the file MUST be cleared before the file
        /// MAY be deleted.</param>
        /// <param name="oldFileName">A null-terminated string containing the name of the file or files to be renamed.
        /// Wildcards MAY be used in the filename component of the path</param>
        /// <param name="newFileName">A null-terminated string containing the new name(s) to be given to the file(s)
        /// that matches OldFileName or the name of the destination directory into which the files matching 
        /// OldFileName MUST be moved.</param>
        /// <returns>a Rename request packet</returns>
        public SmbRenameRequestPacket CreateRenameRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            SmbFileAttributes searchAttributes,
            string oldFileName,
            string newFileName)
        {
            if (oldFileName == null)
            {
                oldFileName = string.Empty;
            }
            if (newFileName == null)
            {
                newFileName = string.Empty;
            }

            SmbRenameRequestPacket packet = new SmbRenameRequestPacket();

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

            SMB_COM_RENAME_Request_SMB_Parameters smbParameters = new SMB_COM_RENAME_Request_SMB_Parameters();
            smbParameters.SearchAttributes = searchAttributes;
            smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord);

            SMB_COM_RENAME_Request_SMB_Data smbData = new SMB_COM_RENAME_Request_SMB_Data();
            smbData.BufferFormat1 = (byte)DataBufferFormat.SmbString;
            smbData.OldFileName = CifsMessageUtils.ToSmbStringBytes(oldFileName,
                (flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE);
            smbData.BufferFormat2 = (byte)DataBufferFormat.SmbString;

            if ((flags2 & SmbFlags2.SMB_FLAGS2_UNICODE) == SmbFlags2.SMB_FLAGS2_UNICODE)
            {
                // if Unicode, add 1 byte pad for align on 16-bits.
                smbData.NewFileName = new byte[1 + (newFileName.Length + 1) * 2];
                Array.Copy(CifsMessageUtils.ToSmbStringBytes(newFileName, true), 0, smbData.NewFileName, 1,
                    (newFileName.Length + 1) * 2);
            }
            else
            {
                smbData.NewFileName = CifsMessageUtils.ToSmbStringBytes(newFileName, false);
            }
            smbData.ByteCount = (ushort)(Marshal.SizeOf(smbData.BufferFormat1) + smbData.OldFileName.Length
                + Marshal.SizeOf(smbData.BufferFormat2) + smbData.NewFileName.Length);

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

            return packet;
        }
        public SmbRenameResponsePacket CreateRenameResponse(
            CifsServerPerConnection connection,
            SmbRenameRequestPacket request)
        {
            SmbRenameResponsePacket response = new SmbRenameResponsePacket();
            response.SmbHeader = CifsMessageUtils.CreateSmbHeader(connection, request);

            return response;
        }