/// <summary>
 /// to create a NtRename request packet.
 /// </summary>
 /// <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="searchAttributes">the attributes that the target file(s) MUST have.</param>
 /// <param name="informationLevel">the NtRenameInformationLevel of the operation.</param>
 /// <param name="oldFileName">the full path name of the file to be manipulated.</param>
 /// <param name="newFileName">the new full path name to be assigned to the  file provided in OldFileName 
 /// or the full path into which the file is to be moved.</param>
 /// <returns>a NtRename request packet</returns>
 /// <exception cref="System.NullReferenceException">There is no connection in context. </exception>
 public SmbNtRenameRequestPacket CreateNtRenameRequest(
     ushort uid,
     ushort treeId,
     SmbFileAttributes searchAttributes,
     NtRenameInformationLevel informationLevel,
     string oldFileName,
     string newFileName)
 {
     return this.CreateNtRenameRequest(this.Context.GetMessageId(this.connectionId),
         uid, treeId, this.defaultParameters.Flag, this.defaultParameters.Flag2,
         searchAttributes, informationLevel, oldFileName, newFileName);
 }
        /// <summary>
        /// to create a NtRename 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 attributes that the target file(s) MUST have.</param>
        /// <param name="informationLevel">the NtRenameInformationLevel of the operation.</param>
        /// <param name="oldFileName">the full path name of the file to be manipulated.</param>
        /// <param name="newFileName">the new full path name to be assigned to the  file provided in OldFileName 
        /// or the full path into which the file is to be moved.</param>
        /// <returns>a NtRename request packet</returns>
        public SmbNtRenameRequestPacket CreateNtRenameRequest(
            ushort messageId,
            ushort uid,
            ushort treeId,
            SmbFlags flags,
            SmbFlags2 flags2,
            SmbFileAttributes searchAttributes,
            NtRenameInformationLevel informationLevel,
            string oldFileName,
            string newFileName)
        {
            if (oldFileName == null)
            {
                oldFileName = string.Empty;
            }
            if (newFileName == null)
            {
                newFileName = string.Empty;
            }

            SmbNtRenameRequestPacket packet = new SmbNtRenameRequestPacket();

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

            SMB_COM_NT_RENAME_Request_SMB_Parameters smbParameters = new SMB_COM_NT_RENAME_Request_SMB_Parameters();
            smbParameters.SearchAttributes = searchAttributes;
            smbParameters.InformationLevel = informationLevel;
            smbParameters.Reserved = 0;
            smbParameters.WordCount = (byte)(Marshal.SizeOf(smbParameters) / NumBytesOfWord);

            SMB_COM_NT_RENAME_Request_SMB_Data smbData = new SMB_COM_NT_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;
        }