/// <summary>
        /// Open the shared virtual disk file
        /// Send smb2 create request to server
        /// </summary>
        /// <param name="vhdxName">Name of the shared virtual disk file</param>
        /// <param name="createOption">CreateOption in create request</param>
        /// <param name="contexts">Create Contexts to be sent together with Create Request</param>
        /// <param name="status">Status of create response</param>
        /// <param name="serverContexts">Create contexts returned in create response</param>
        /// <param name="response">Create Response returned by server</param>
        /// <returns>Create Response returned by server</returns>
        public uint OpenSharedVirtualDisk(
            string vhdxName,
            FsCreateOption createOption,
            Smb2CreateContextRequest[] contexts,
            out Smb2CreateContextResponse[] serverContexts,
            out CREATE_Response response)
        {
            uint status;

            transport.Create(
                vhdxName,
                // The desired access is set the same as Windows client's behavior
                FsFileDesiredAccess.FILE_READ_DATA | FsFileDesiredAccess.FILE_WRITE_DATA | FsFileDesiredAccess.FILE_READ_ATTRIBUTES | FsFileDesiredAccess.READ_CONTROL,
                ShareAccess_Values.FILE_SHARE_DELETE | ShareAccess_Values.FILE_SHARE_READ | ShareAccess_Values.FILE_SHARE_WRITE,
                FsImpersonationLevel.Impersonation,
                FsFileAttribute.NONE,
                FsCreateDisposition.FILE_OPEN,
                createOption,
                contexts,
                out status,
                out serverContexts,
                out response);
            return(status);
        }
        /// <summary>
        /// Create a file with create context
        /// </summary>
        /// <param name="fileName">Name of the file</param>
        /// <param name="desiredAccess">The desired access</param>
        /// <param name="shareAccess">Sharing mode for the open</param>
        /// <param name="impersonationLevel">The impersonation level</param>
        /// <param name="fileAttribute">The file attribute, this field is only valid when create file.</param>
        /// <param name="createDisposition">Defines the action the server MUST take if the file that is specified in the name field already exists</param>
        /// <param name="createOption">Specifies the options to be applied when creating or opening the file</param>
        /// <param name="contextRequest">Create contexts to be sent in the create request</param>
        /// <param name="status">Status of the response packet</param>
        /// <param name="serverCreateContexts">Create contexts to be received in the create response</param>
        /// <param name="contextResponse">Create response payload to be received in the create response</param>
        public void Create(
            string fileName,
            FsFileDesiredAccess desiredAccess,
            ShareAccess_Values shareAccess,
            FsImpersonationLevel impersonationLevel,
            FsFileAttribute fileAttribute,
            FsCreateDisposition createDisposition,
            FsCreateOption createOption,
            Smb2CreateContextRequest[] contextRequest,
            out uint status,
            out Smb2CreateContextResponse[] serverCreateContexts,
            out CREATE_Response createResponse)
        {
            if (createOption.HasFlag(FsCreateOption.FILE_DIRECTORY_FILE))
            {
                throw new ArgumentException("createOption can not contain FILE_DIRECTORY_FILE when creating file.");
            }

            Packet_Header header;

            status = client.Create(
                        1,
                        1,
                        headerFlags,
                        messageId++,
                        sessionId,
                        treeId,
                        fileName,
                        (AccessMask)desiredAccess,
                        shareAccess,
                        (CreateOptions_Values)createOption,
                        (CreateDisposition_Values)createDisposition,
                        (File_Attributes)fileAttribute,
                        (ImpersonationLevel_Values)impersonationLevel,
                        SecurityFlags_Values.NONE,
                        RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE,
                        contextRequest,
                        out fileId,
                        out serverCreateContexts,
                        out header,
                        out createResponse);
        }
 /// <summary>
 /// Create directory. One transport can only create one directory
 /// </summary>
 /// <param name="directoryName">The directory name</param>
 /// <param name="desiredAccess">The desired access</param>
 /// <param name="impersonationLevel">The impersonation level</param>
 /// <param name="fileAttribute">The file attribute, this field is only valid when create file.
 /// </param>
 /// <param name="createDisposition">Defines the action the server MUST take if the file that is
 /// specified in the name field already exists</param>
 /// <param name="createOption">Specifies the options to be applied when creating or opening the file</param>
 /// <exception cref="System.InvalidOperationException">Thrown if there is any error occurred</exception>
 public abstract void Create(string directoryName, FsDirectoryDesiredAccess desiredAccess, FsImpersonationLevel impersonationLevel,
                             FsFileAttribute fileAttribute, FsCreateDisposition createDisposition, FsCreateOption createOption);
        /// <summary>
        /// Create File, named pipe, directory. One transport can only create one file.
        /// </summary>
        /// <param name="fileName">The file, namedpipe, directory name</param>
        /// <param name="desiredAccess">The desired access</param>
        /// <param name="impersonationLevel">The impersonation level</param>
        /// <param name="fileAttribute">The file attribute, this field is only valid when create file.
        /// </param>
        /// <param name="createDisposition">Defines the action the server MUST take if the file that is
        /// specified in the name field already exists</param>
        /// <param name="createOption">Specifies the options to be applied when creating or opening the file</param>
        /// <exception cref="System.InvalidOperationException">Thrown if there is any error occurred</exception>
        private void InternalCreate(string fileName, uint desiredAccess, FsImpersonationLevel impersonationLevel,
            FsFileAttribute fileAttribute, FsCreateDisposition createDisposition, FsCreateOption createOption)
        {
            Packet_Header header;
            CREATE_Response createResponse;
            Smb2CreateContextResponse[] serverCreateContexts;

            CheckStatusCode(
                client.Create(
                    1,
                    1,
                    headerFlags,
                    messageId++,
                    sessionId,
                    treeId,
                    fileName,
                    (AccessMask)desiredAccess,
                    ShareAccess_Values.NONE,
                    (CreateOptions_Values)createOption,
                    (CreateDisposition_Values)createDisposition,
                    (File_Attributes)fileAttribute,
                    (ImpersonationLevel_Values)impersonationLevel,
                    SecurityFlags_Values.NONE,
                    RequestedOplockLevel_Values.OPLOCK_LEVEL_NONE,
                    null,
                    out fileId,
                    out serverCreateContexts,
                    out header,
                    out createResponse));
        }
        /// <summary>
        /// Create directory. One transport can only create one directory
        /// </summary>
        /// <param name="directoryName">The directory name</param>
        /// <param name="desiredAccess">The desired access</param>
        /// <param name="impersonationLevel">The impersonation level</param>
        /// <param name="fileAttribute">The file attribute, this field is only valid when create file.
        /// </param>
        /// <param name="createDisposition">Defines the action the server MUST take if the file that is
        /// specified in the name field already exists</param>
        /// <param name="createOption">Specifies the options to be applied when creating or opening the file</param>
        /// <exception cref="System.InvalidOperationException">Thrown if there is any error occurred</exception>
        public override void Create(string directoryName, FsDirectoryDesiredAccess desiredAccess, FsImpersonationLevel impersonationLevel,
            FsFileAttribute fileAttribute, FsCreateDisposition createDisposition, FsCreateOption createOption)
        {
            if (createOption.HasFlag(FsCreateOption.FILE_NON_DIRECTORY_FILE))
            {
                throw new ArgumentException("createOption cannot contain FILE_NON_DIRECTORY_FILE when creating Directory.");
            }

            InternalCreate(directoryName, (uint)desiredAccess, impersonationLevel, fileAttribute, createDisposition, createOption);
        }
Example #6
0
 /// <summary>
 /// Create directory. One transport can only create one directory
 /// </summary>
 /// <param name="directoryName">The directory name</param>
 /// <param name="desiredAccess">The desired access</param>
 /// <param name="impersonationLevel">The impersonation level</param>
 /// <param name="fileAttribute">The file attribute, this field is only valid when create file.
 /// </param>
 /// <param name="createDisposition">Defines the action the server MUST take if the file that is
 /// specified in the name field already exists</param>
 /// <param name="createOption">Specifies the options to be applied when creating or opening the file</param>
 /// <exception cref="System.InvalidOperationException">Thrown if there is any error occurred</exception>
 public override void Create(string directoryName, FsDirectoryDesiredAccess desiredAccess, FsImpersonationLevel impersonationLevel,
                             FsFileAttribute fileAttribute, FsCreateDisposition createDisposition, FsCreateOption createOption)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Create directory. One transport can only create one directory
 /// </summary>
 /// <param name="directoryName">The directory name</param>
 /// <param name="desiredAccess">The desired access</param>
 /// <param name="impersonationLevel">The impersonation level</param>
 /// <param name="fileAttribute">The file attribute, this field is only valid when create file.
 /// </param>
 /// <param name="createDisposition">Defines the action the server MUST take if the file that is
 /// specified in the name field already exists</param>
 /// <param name="createOption">Specifies the options to be applied when creating or opening the file</param>
 /// <exception cref="System.InvalidOperationException">Thrown if there is any error occurred</exception>
 public override void Create(string directoryName, FsDirectoryDesiredAccess desiredAccess, FsImpersonationLevel impersonationLevel,
     FsFileAttribute fileAttribute, FsCreateDisposition createDisposition, FsCreateOption createOption)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Create directory. One transport can only create one directory
 /// </summary>
 /// <param name="directoryName">The directory name</param>
 /// <param name="desiredAccess">The desired access</param>
 /// <param name="impersonationLevel">The impersonation level</param>
 /// <param name="fileAttribute">The file attribute, this field is only valid when create file.
 /// </param>
 /// <param name="createDisposition">Defines the action the server MUST take if the file that is
 /// specified in the name field already exists</param>
 /// <param name="createOption">Specifies the options to be applied when creating or opening the file</param>
 /// <exception cref="System.InvalidOperationException">Thrown if there is any error occurred</exception>
 public abstract void Create(string directoryName, FsDirectoryDesiredAccess desiredAccess, FsImpersonationLevel impersonationLevel,
     FsFileAttribute fileAttribute, FsCreateDisposition createDisposition, FsCreateOption createOption);
        /// <summary>
        /// Create directory. One transport can only create one directory
        /// </summary>
        /// <param name="directoryName">The directory name</param>
        /// <param name="desiredAccess">The desired access</param>
        /// <param name="impersonationLevel">The impersonation level</param>
        /// <param name="fileAttribute">The file attribute, this field is only valid when create file.
        /// </param>
        /// <param name="createDisposition">Defines the action the server MUST take if the file that is
        /// specified in the name field already exists</param>
        /// <param name="createOption">Specifies the options to be applied when creating or opening the file</param>
        /// <exception cref="ArgumentException">
        /// createOption can not contain FILE_NON_DIRECTORY_FILE when creating directory.
        /// </exception>
        /// <exception cref="System.InvalidOperationException">Thrown if there is any error occurred</exception>
        public override void Create(string directoryName,
            FsDirectoryDesiredAccess desiredAccess, FsImpersonationLevel impersonationLevel,
            FsFileAttribute fileAttribute, FsCreateDisposition createDisposition, FsCreateOption createOption)
        {
            if ((createOption & FsCreateOption.FILE_NON_DIRECTORY_FILE) == FsCreateOption.FILE_NON_DIRECTORY_FILE)
            {
                throw new ArgumentException(
                    "createOption can not contain FILE_NON_DIRECTORY_FILE when creating directory.", "createOption");
            }

            InternalCreate(
                directoryName,
                (NtTransactDesiredAccess)desiredAccess,
                (NtTransactImpersonationLevel)impersonationLevel,
                (SMB_EXT_FILE_ATTR)fileAttribute,
                (NtTransactCreateDisposition)createDisposition,
                (NtTransactCreateOptions)createOption);
        }
        /// <summary>
        /// Create directory. One transport can only create one directory
        /// </summary>
        /// <param name="directoryName">The directory name</param>
        /// <param name="desiredAccess">The desired access</param>
        /// <param name="impersonationLevel">The impersonation level</param>
        /// <param name="fileAttribute">The file attribute, this field is only valid when create file.
        /// </param>
        /// <param name="createDisposition">Defines the action the server MUST take if the file that is
        /// specified in the name field already exists</param>
        /// <param name="createOption">Specifies the options to be applied when creating or opening the file</param>
        /// <exception cref="ArgumentException">
        /// createOption can not contain FILE_NON_DIRECTORY_FILE when creating directory.
        /// </exception>
        /// <exception cref="System.InvalidOperationException">Thrown if there is any error occurred</exception>
        public override void Create(string directoryName,
                                    FsDirectoryDesiredAccess desiredAccess, FsImpersonationLevel impersonationLevel,
                                    FsFileAttribute fileAttribute, FsCreateDisposition createDisposition, FsCreateOption createOption)
        {
            if ((createOption & FsCreateOption.FILE_NON_DIRECTORY_FILE) == FsCreateOption.FILE_NON_DIRECTORY_FILE)
            {
                throw new ArgumentException(
                          "createOption can not contain FILE_NON_DIRECTORY_FILE when creating directory.", "createOption");
            }

            InternalCreate(
                directoryName,
                (NtTransactDesiredAccess)desiredAccess,
                (NtTransactImpersonationLevel)impersonationLevel,
                (SMB_EXT_FILE_ATTR)fileAttribute,
                (NtTransactCreateDisposition)createDisposition,
                (NtTransactCreateOptions)createOption);
        }