public static extern IntPtr CreateFile(
     string lpFileName,                             // File name
     FileDesiredAccess dwDesiredAccess,             // Access mode
     FileShareMode dwShareMode,                     // Share mode
     IntPtr SecurityAttributes,                     // Security attributes
     FileCreationDisposition dwCreationDisposition, // How to create
     uint dwFlagsAndAttributes,                     // File attributes
     IntPtr hTemplateFile                           // Handle to template file
     );
        public static NamedPipeHandle Create(
            FileAccess access,
            string fileName,
            ObjectFlags objectFlags,
            NativeHandle rootDirectory,
            FileShareMode shareMode,
            FileCreationDisposition creationDisposition,
            FileCreateOptions createOptions,
            PipeType type,
            PipeType readMode,
            PipeCompletionMode completionMode,
            int maximumInstances,
            int inboundQuota,
            int outboundQuota,
            long defaultTimeout
            )
        {
            NtStatus         status;
            ObjectAttributes oa = new ObjectAttributes(fileName, objectFlags, rootDirectory);
            IoStatusBlock    isb;
            IntPtr           handle;

            // If a timeout wasn't specified, use a default value.
            if (defaultTimeout == 0)
            {
                defaultTimeout = -50 * Win32.TimeMsTo100Ns; // 50 milliseconds
            }
            try
            {
                if ((status = Win32.NtCreateNamedPipeFile(
                         out handle,
                         access,
                         ref oa,
                         out isb,
                         shareMode,
                         creationDisposition,
                         createOptions,
                         type,
                         readMode,
                         completionMode,
                         maximumInstances,
                         inboundQuota,
                         outboundQuota,
                         ref defaultTimeout
                         )) >= NtStatus.Error)
                {
                    Win32.Throw(status);
                }
            }
            finally
            {
                oa.Dispose();
            }

            return(new NamedPipeHandle(handle, true));
        }
Exemple #3
0
 /// <summary>
 /// Open a file with the Win32 CreateFile API.
 /// </summary>
 /// <param name="filename">The filename to open.</param>
 /// <param name="desired_access">The desired access.</param>
 /// <param name="share_mode">The share mode.</param>
 /// <param name="creation_disposition">Creation disposition.</param>
 /// <param name="flags_and_attributes">Flags and attributes.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The opened file handle.</returns>
 public static NtResult <NtFile> CreateFile(string filename,
                                            FileAccessRights desired_access,
                                            FileShareMode share_mode,
                                            CreateFileDisposition creation_disposition,
                                            CreateFileFlagsAndAttributes flags_and_attributes,
                                            bool throw_on_error)
 {
     return(CreateFile(filename, desired_access, share_mode, null, false,
                       creation_disposition, flags_and_attributes, null, throw_on_error));
 }
 public MailslotHandle(
     string fileName,
     ObjectFlags objectFlags,
     FileHandle rootDirectory,
     FileShareMode shareMode,
     FileCreateOptions openOptions,
     FileAccess access
     )
     : base(fileName, objectFlags, rootDirectory, shareMode, openOptions, access)
 {
 }
Exemple #5
0
 public MailslotHandle(
     string fileName,
     ObjectFlags objectFlags,
     NativeHandle rootDirectory,
     FileShareMode shareMode,
     FileCreateOptions openOptions,
     FileAccess access
     )
     : base(fileName, objectFlags, rootDirectory, shareMode, openOptions, access)
 {
 }
 public Task TransmitFile(string path, long offset, long count, FileShareMode fileShareMode, CancellationToken cancellationToken)
 {
     if (_supportsDirectSocketAccess && offset == 0 && count == 0 && !_response.SendChunked && _response.ContentLength64 > 8192)
     {
         if (EnableSendFileWithSocket)
         {
             return(TransmitFileOverSocket(path, offset, count, fileShareMode, cancellationToken));
         }
     }
     return(TransmitFileManaged(path, offset, count, fileShareMode, cancellationToken));
 }
Exemple #7
0
 /// <summary>
 /// Open a file with the Win32 CreateFile API.
 /// </summary>
 /// <param name="filename">The filename to open.</param>
 /// <param name="desired_access">The desired access.</param>
 /// <param name="share_mode">The share mode.</param>
 /// <param name="security_descriptor">Optional security descriptor.</param>
 /// <param name="inherit_handle">True to set the handle as inheritable.</param>
 /// <param name="creation_disposition">Creation disposition.</param>
 /// <param name="flags_and_attributes">Flags and attributes.</param>
 /// <param name="template_file">Optional template file.</param>
 /// <returns>The opened file handle.</returns>
 public static NtFile CreateFile(string filename,
                                 FileAccessRights desired_access,
                                 FileShareMode share_mode,
                                 SecurityDescriptor security_descriptor,
                                 bool inherit_handle,
                                 CreateFileDisposition creation_disposition,
                                 CreateFileFlagsAndAttributes flags_and_attributes,
                                 NtFile template_file)
 {
     return(CreateFile(filename, desired_access, share_mode, security_descriptor, inherit_handle,
                       creation_disposition, flags_and_attributes, template_file, true).Result);
 }
Exemple #8
0
 public static extern NtStatus NtCreateFile(
     out SafeKernelObjectHandle FileHandle,
     FileAccessRights DesiredAccess,
     ObjectAttributes ObjAttr,
     [Out] IoStatus IoStatusBlock,
     LargeInteger AllocationSize,
     FileAttributes FileAttributes,
     FileShareMode ShareAccess,
     FileDisposition CreateDisposition,
     FileOpenOptions CreateOptions,
     byte[] EaBuffer,
     int EaLength);
        public static NamedPipeHandle Create(
            FileAccess access,
            string fileName,
            ObjectFlags objectFlags,
            NativeHandle rootDirectory,
            FileShareMode shareMode,
            FileCreationDisposition creationDisposition,
            FileCreateOptions createOptions,
            PipeType type,
            PipeType readMode,
            PipeCompletionMode completionMode,
            int maximumInstances,
            int inboundQuota,
            int outboundQuota,
            long defaultTimeout
            )
        {
            NtStatus status;
            ObjectAttributes oa = new ObjectAttributes(fileName, objectFlags, rootDirectory);
            IoStatusBlock isb;
            IntPtr handle;

            // If a timeout wasn't specified, use a default value.
            if (defaultTimeout == 0)
                defaultTimeout = -50 * Win32.TimeMsTo100Ns; // 50 milliseconds

            try
            {
                if ((status = Win32.NtCreateNamedPipeFile(
                    out handle,
                    access,
                    ref oa,
                    out isb,
                    shareMode,
                    creationDisposition,
                    createOptions,
                    type,
                    readMode,
                    completionMode,
                    maximumInstances,
                    inboundQuota,
                    outboundQuota,
                    ref defaultTimeout
                    )) >= NtStatus.Error)
                    Win32.Throw(status);
            }
            finally
            {
                oa.Dispose();
            }

            return new NamedPipeHandle(handle, true);
        }
        public static NamedPipeHandle Create(
            FileAccess access,
            string fileName,
            ObjectFlags objectFlags,
            FileHandle rootDirectory,
            FileShareMode shareMode,
            FileCreationDisposition creationDisposition,
            FileCreateOptions createOptions,
            PipeType type,
            PipeType readMode,
            PipeCompletionMode completionMode,
            int maximumInstances,
            int inboundQuota,
            int outboundQuota,
            long defaultTimeout
            )
        {
            NtStatus         status;
            ObjectAttributes oa = new ObjectAttributes(fileName, objectFlags, rootDirectory);
            IoStatusBlock    isb;
            IntPtr           handle;

            try
            {
                if ((status = Win32.NtCreateNamedPipeFile(
                         out handle,
                         access,
                         ref oa,
                         out isb,
                         shareMode,
                         creationDisposition,
                         createOptions,
                         type,
                         readMode,
                         completionMode,
                         maximumInstances,
                         inboundQuota,
                         outboundQuota,
                         ref defaultTimeout
                         )) >= NtStatus.Error)
                {
                    Win32.ThrowLastError(status);
                }
            }
            finally
            {
                oa.Dispose();
            }

            return(new NamedPipeHandle(handle, true));
        }
        private async Task TransmitFileManaged(string path, long offset, long count, FileShareMode fileShareMode, CancellationToken cancellationToken)
        {
            var allowAsync = _environment.OperatingSystem != MediaBrowser.Model.System.OperatingSystem.Windows;

            //if (count <= 0)
            //{
            //    allowAsync = true;
            //}

            var fileOpenOptions = FileOpenOptions.SequentialScan;

            if (allowAsync)
            {
                fileOpenOptions |= FileOpenOptions.Asynchronous;
            }

            // use non-async filestream along with read due to https://github.com/dotnet/corefx/issues/6039

            using (var fs = _fileSystem.GetFileStream(path, FileOpenMode.Open, FileAccessMode.Read, fileShareMode, fileOpenOptions))
            {
                if (offset > 0)
                {
                    fs.Position = offset;
                }

                var targetStream = this;

                if (count > 0)
                {
                    if (allowAsync)
                    {
                        await CopyToInternalAsync(fs, targetStream, count, cancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        await CopyToInternalAsyncWithSyncRead(fs, targetStream, count, cancellationToken).ConfigureAwait(false);
                    }
                }
                else
                {
                    if (allowAsync)
                    {
                        await fs.CopyToAsync(targetStream, StreamCopyToBufferSize, cancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        fs.CopyTo(targetStream, StreamCopyToBufferSize);
                    }
                }
            }
        }
            public static IntPtr OpenColorProfile(
                ref Profile profile,
                ProfileAccess desiredAccess = ProfileAccess.Read,
                FileShareMode shareMode     = FileShareMode.Read,
                CreatationMode creationMode = CreatationMode.OpenExisting)
            {
                var hProfile = _OpenColorProfile(ref profile, desiredAccess, shareMode, creationMode);

                if (hProfile == IntPtr.Zero)
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
                return(hProfile);
            }
Exemple #13
0
        /// <summary>
        /// Open a file by its object ID
        /// </summary>
        /// <param name="volume">A handle to the volume on which the file resides.</param>
        /// <param name="id">The object ID as a binary string</param>
        /// <param name="DesiredAccess">The desired access for the file</param>
        /// <param name="ShareAccess">File share access</param>
        /// <param name="OpenOptions">Open options.</param>
        /// <returns>The opened file object</returns>
        /// <exception cref="NtException">Thrown on error.</exception>
        public static NtFile OpenFileById(NtFile volume, string id,
                                          FileAccessRights DesiredAccess, FileShareMode ShareAccess, FileOpenOptions OpenOptions)
        {
            StringBuilder name_builder = new StringBuilder();

            using (ObjectAttributes obja = new ObjectAttributes(id, AttributeFlags.CaseInsensitive, volume, null, null))
            {
                SafeKernelObjectHandle handle;
                IoStatus iostatus = new IoStatus();
                NtSystemCalls.NtOpenFile(out handle, DesiredAccess, obja,
                                         iostatus, ShareAccess, OpenOptions | FileOpenOptions.OpenByFileId).ToNtException();
                return(new NtFile(handle));
            }
        }
Exemple #14
0
        public Task <object> GetStaticFileResult(IRequest requestContext,
                                                 string path,
                                                 FileShareMode fileShare = FileShareMode.Read)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            return(GetStaticFileResult(requestContext, new StaticFileResultOptions
            {
                Path = path,
                FileShare = fileShare
            }));
        }
Exemple #15
0
        private Task TransmitFileOverSocket(string path, long offset, long count, FileShareMode fileShareMode, CancellationToken cancellationToken)
        {
            var ms = GetHeaders(false);

            byte[] preBuffer;
            if (ms != null)
            {
                using (var msCopy = new MemoryStream())
                {
                    ms.CopyTo(msCopy);
                    preBuffer = msCopy.ToArray();
                }
            }
            else
            {
                return(TransmitFileManaged(path, offset, count, fileShareMode, cancellationToken));
            }

            _stream.Flush();

            _logger.Info("Socket sending file {0}", path);

            var taskCompletion = new TaskCompletionSource <bool>();

            Action <IAsyncResult> callback = callbackResult =>
            {
                try
                {
                    _socket.EndSendFile(callbackResult);
                    taskCompletion.TrySetResult(true);
                }
                catch (Exception ex)
                {
                    taskCompletion.TrySetException(ex);
                }
            };

            var result = _socket.BeginSendFile(path, preBuffer, _emptyBuffer, TransmitFileOptions.UseDefaultWorkerThread, new AsyncCallback(callback), null);

            if (result.CompletedSynchronously)
            {
                callback(result);
            }

            cancellationToken.Register(() => taskCompletion.TrySetCanceled());

            return(taskCompletion.Task);
        }
Exemple #16
0
 public static extern NtStatus NtCreateNamedPipeFile(
     out SafeKernelObjectHandle FileHandle,
     FileAccessRights DesiredAccess,
     [In] ObjectAttributes ObjectAttributes,
     [Out] IoStatus IoStatusBlock,
     FileShareMode ShareAccess,
     FileDisposition CreateDisposition,
     FileOpenOptions CreateOptions,
     NamedPipeType NamedPipeType,
     NamedPipeReadMode ReadMode,
     NamedPipeCompletionMode CompletionMode,
     int MaximumInstances,
     int InboundQuota,
     int OutboundQuota,
     LargeInteger DefaultTimeout
     );
Exemple #17
0
        private static SafeMailslotHandle CreateFile(string name,
                                                     IntPtr securityAttributes,
                                                     IntPtr hTemplateFile,
                                                     FileDesiredAccess access = FileDesiredAccess.GenericWrite,
                                                     FileShareMode shareMode  = FileShareMode.FileShareRead,
                                                     FileCreationDisposition creationDisposition = FileCreationDisposition.OpenExisting,
                                                     int flagsAndAttributes = 0
                                                     )
        {
            var ret = CreateFile(name, access, shareMode, securityAttributes, creationDisposition, flagsAndAttributes, hTemplateFile);

            if (ret.IsInvalid)
            {
                throw Throw("Unable to create new mailslot");
            }
            return(ret);
        }
Exemple #18
0
        internal static IntPtr CreateFile_Hooked(
            String lpFileName,
            UInt32 dwDesiredAccess,
            FileShareMode dwShareMode,
            /*ref SECURITY_ATTRIBUTES*/ IntPtr lpSecurityAttributes,
            CreateFileCreationDisposition dwCreationDisposition,
            UInt32 dwFlagsAndAttributes,
            IntPtr hTemplateFile)
        {
            IntPtr result = new HookContext <IntPtr>(
                func => ((CreateFile_Delegate)func)(lpFileName, dwDesiredAccess,
                                                    dwShareMode, lpSecurityAttributes, dwCreationDisposition,
                                                    dwFlagsAndAttributes, hTemplateFile),
                helper =>
            {
                IntPtr helperResult = FileEncryptionLayer.CreateFile(lpFileName, dwDesiredAccess, dwShareMode,
                                                                     lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes,
                                                                     hTemplateFile);
                // Path rewriting for .NET host app
                if (helperResult == Win32Api.INVALID_HANDLE_VALUE)
                {
                    uint errorCode = Win32Api.GetLastError();
                    if (IsPathInExeDirOfNETHost(lpFileName))
                    {
                        lpFileName = AdjustPathToAssemblyExeDir(lpFileName);
                        // log it before anything crashes.
                        helperResult = FileEncryptionLayer.CreateFile(lpFileName, dwDesiredAccess, dwShareMode,
                                                                      lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes,
                                                                      hTemplateFile);
                    }
                    else
                    {
                        Win32Api.SetLastError(errorCode);
                    }
                }
                return(helperResult);
            },
                errorCode =>
            {
                SetLastError(unchecked ((uint)errorCode));
                return(IntPtr.Zero);
            },
                HookLogging.DefaultLogging, "[FILENAME]: {0}", lpFileName).Call();

            return(result);
        }
Exemple #19
0
        private bool OpenDevice()
        {
            try
            {
                FileShareMode           shareModeExclusive  = FileShareMode.FILE_SHARE_NONE;
                FileShareMode           shareModeNormal     = FileShareMode.FILE_SHARE_READ | FileShareMode.FILE_SHARE_WRITE;
                FileDesiredAccess       desiredAccess       = FileDesiredAccess.GENERIC_READ | FileDesiredAccess.GENERIC_WRITE;
                FileCreationDisposition creationDisposition = FileCreationDisposition.OPEN_EXISTING;
                FileFlagsAndAttributes  flagsAttributes     = FileFlagsAndAttributes.FILE_FLAG_NORMAL | FileFlagsAndAttributes.FILE_FLAG_OVERLAPPED | FileFlagsAndAttributes.FILE_FLAG_NO_BUFFERING;

                //Try to open the device exclusively
                FileHandle = CreateFile(DevicePath, desiredAccess, shareModeExclusive, IntPtr.Zero, creationDisposition, flagsAttributes, IntPtr.Zero);
                Exclusive  = true;

                //Try to open the device normally
                if (FileHandle == null || FileHandle.IsInvalid || FileHandle.IsClosed)
                {
                    //Debug.WriteLine("Failed to open device exclusively, opening normally.");
                    FileHandle = CreateFile(DevicePath, desiredAccess, shareModeNormal, IntPtr.Zero, creationDisposition, flagsAttributes, IntPtr.Zero);
                    Exclusive  = false;
                }

                //Check if the device is opened
                if (FileHandle == null || FileHandle.IsInvalid || FileHandle.IsClosed)
                {
                    //Debug.WriteLine("Failed to open hid device: " + DevicePath);
                    Connected = false;
                    Installed = false;
                    return(false);
                }
                else
                {
                    //Debug.WriteLine("Opened hid device: " + DevicePath + ", exclusively: " + Exclusive);
                    Connected = true;
                    Installed = true;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to open hid device: " + ex.Message);
                Connected = false;
                Installed = false;
                return(false);
            }
        }
Exemple #20
0
        private FileShare GetFileShare(FileShareMode mode)
        {
            switch (mode)
            {
            case FileShareMode.ReadWrite:
                return(FileShare.ReadWrite);

            case FileShareMode.Write:
                return(FileShare.Write);

            case FileShareMode.Read:
                return(FileShare.Read);

            case FileShareMode.None:
                return(FileShare.None);

            default:
                throw new Exception("Unrecognized FileShareMode");
            }
        }
Exemple #21
0
        /// <summary>Initializes a new instance of the <see cref="FileDescriptor" /> class.</summary>
        /// <param name="fileDescriptorByte">The file descriptor byte that shall be parsed.</param>
        public FileDescriptor(byte fileDescriptorByte) {
            _fileDescriptor = fileDescriptorByte;

            _type = SCardHelper.IsSet(_fileDescriptor, FILE_TYPE_MASK, FILE_TYPE_DF)
                ? FileType.Dedicated
                : FileType.Elementary;

            // ExtendedType
            if (SCardHelper.IsSet(_fileDescriptor, FILE_TYPE_MASK, FILE_TYPE_DF)) {
                _extendedType = ExtendedFileType.Dedicated;
            } else if (SCardHelper.IsSet(_fileDescriptor, FILE_TYPE_MASK, FILE_TYPE_WORKING_EF)) {
                _extendedType = ExtendedFileType.WorkingElementary;
            } else if (SCardHelper.IsSet(_fileDescriptor, FILE_TYPE_MASK, FILE_TYPE_INTERNAL_EF)) {
                _extendedType = ExtendedFileType.InternalElementary;
            } else {
                _extendedType = ExtendedFileType.Proprietary;
            }

            _shareMode = SCardHelper.IsSet(_fileDescriptor, FILE_SHARE_MODE_MASK, FILE_SHARE_MODE_SHAREABLE)
                ? FileShareMode.Shareable
                : FileShareMode.NotShareable;

            _fileStructureInfoCache = null;
        }
 public MailslotHandle(string fileName, FileShareMode shareMode, FileAccess access)
     : base(fileName, shareMode, access)
 { }
 public MailslotHandle(string fileName, FileShareMode shareMode, FileCreateOptions openOptions, FileAccess access)
     : base(fileName, shareMode, openOptions, access)
 { }
 public static extern SafePipeHandle CreateFile(string fileName,
     FileDesiredAccess desiredAccess, FileShareMode shareMode,
     SECURITY_ATTRIBUTES securityAttributes,
     FileCreationDisposition creationDisposition,
     int flagsAndAttributes, IntPtr hTemplateFile);
Exemple #25
0
 public static extern SafeMailslotHandle CreateFile(string fileName,
     FileDesiredAccess desiredAccess, FileShareMode shareMode,
     IntPtr securityAttributes,
     FileCreationDisposition creationDisposition,
     int flagsAndAttributes, IntPtr hTemplateFile);
Exemple #26
0
 public static extern SafeMailslotHandle CreateFile(string fileName,
                                                    FileDesiredAccess desiredAccess, FileShareMode shareMode,
                                                    IntPtr securityAttributes,
                                                    FileCreationDisposition creationDisposition,
                                                    int flagsAndAttributes, IntPtr hTemplateFile);
Exemple #27
0
 public MailslotHandle(string fileName, FileShareMode shareMode, FileCreateOptions openOptions, FileAccess access)
     : base(fileName, shareMode, openOptions, access)
 {
 }
Exemple #28
0
 public virtual Stream GetFileStream(string path, FileOpenMode mode, FileAccessMode access, FileShareMode share, FileOpenOptions fileOpenOptions)
 => new FileStream(path, GetFileMode(mode), GetFileAccess(access), GetFileShare(share), 4096, GetFileOptions(fileOpenOptions));
Exemple #29
0
        /// <summary>
        /// Gets the file stream.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="access">The access.</param>
        /// <param name="share">The share.</param>
        /// <param name="isAsync">if set to <c>true</c> [is asynchronous].</param>
        /// <returns>FileStream.</returns>
        public virtual Stream GetFileStream(string path, FileOpenMode mode, FileAccessMode access, FileShareMode share, bool isAsync = false)
        {
            if (isAsync)
            {
                return(GetFileStream(path, mode, access, share, FileOpenOptions.Asynchronous));
            }

            return(GetFileStream(path, mode, access, share, FileOpenOptions.None));
        }
 public NamedPipeHandle(string fileName, FileShareMode shareMode, FileAccess access)
     : base(fileName, shareMode, access)
 { }
Exemple #31
0
        /// <summary>
        /// Gets the file stream.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="access">The access.</param>
        /// <param name="share">The share.</param>
        /// <param name="isAsync">if set to <c>true</c> [is asynchronous].</param>
        /// <returns>FileStream.</returns>
        public Stream GetFileStream(string path, FileOpenMode mode, FileAccessMode access, FileShareMode share, bool isAsync = false)
        {
            if (_sharpCifsFileSystem.IsEnabledForPath(path))
            {
                return(_sharpCifsFileSystem.GetFileStream(path, mode, access, share));
            }

            if (_supportsAsyncFileStreams && isAsync)
            {
                return(GetFileStream(path, mode, access, share, FileOpenOptions.Asynchronous));
            }

            return(GetFileStream(path, mode, access, share, FileOpenOptions.None));
        }
Exemple #32
0
 /// <summary>
 /// Gets the file stream.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="fileShare">The file share.</param>
 /// <returns>Stream.</returns>
 private Stream GetFileStream(string path, FileShareMode fileShare)
 {
     return(_fileSystem.GetFileStream(path, FileOpenMode.Open, FileAccessMode.Read, fileShare));
 }
 public static extern SafeFileHandle CreateFile(string path, FileAccessMask accessMask, FileShareMode shareMode,
                                                IntPtr sd, CreationDisposition disposition, CreateFileFlags flags, IntPtr hTemplateFile);
 public Task TransmitFile(string path, long offset, long count, FileShareMode fileShareMode, CancellationToken cancellationToken)
 {
     return(TransmitFileManaged(path, offset, count, fileShareMode, cancellationToken));
 }
Exemple #35
0
 internal static extern IntPtr CreateFile(
     string lpFileName,
     FileDesiredAccess dwDesiredAccess,
     FileShareMode dwShareMode,
     IntPtr lpSecurityAttributes,
     FileCreationDisposition dwCreationDisposition,
     FileAttributes dwFlagsAndAttributes,
     IntPtr hTemplateFile);
Exemple #36
0
 public MailslotHandle(string fileName, FileShareMode shareMode, FileAccess access)
     : base(fileName, shareMode, access)
 {
 }
 public static extern IntPtr CreateFile(
     String lpFileName,                  // File name
     FileDesiredAccess dwDesiredAccess,  // Access mode
     FileShareMode dwShareMode,          // Share mode
     IntPtr fileSecurityAttributes,      // Security Attributes
     FileCreationDisposition dwCreationDisposition,// How to create
     uint dwFlagsAndAttributes,          // File attributes
     uint hTemplateFile);
Exemple #38
0
        public Stream GetFileStream(string path, FileOpenMode mode, FileAccessMode access, FileShareMode share, FileOpenOptions fileOpenOptions)
        {
            if (_sharpCifsFileSystem.IsEnabledForPath(path))
            {
                return(_sharpCifsFileSystem.GetFileStream(path, mode, access, share));
            }

            var defaultBufferSize = 4096;

            return(new FileStream(path, GetFileMode(mode), GetFileAccess(access), GetFileShare(share), defaultBufferSize, GetFileOptions(fileOpenOptions)));
        }
Exemple #39
0
 public Task TransmitFile(string path, long offset, long count, FileShareMode fileShareMode, CancellationToken cancellationToken)
 {
     return(((HttpResponseStream)OutputStream).TransmitFile(path, offset, count, fileShareMode, cancellationToken));
 }
Exemple #40
0
 private static extern uint CreateFile(string filename, AccessMode desiredAccess, FileShareMode shareMode, IntPtr attributes, OpenMode creationDisposition, uint flagsAndAttributes, IntPtr templateFile);
Exemple #41
0
        protected void UpdateFileInfo()
        {
            // Type
            if (SCardHelper.IsSet(filedescriptor, FILE_TYPE_MASK, FILE_TYPE_DF))
                _type = FileType.Dedicated;
            else
                _type = FileType.Elementary;

            // ExtendedType
            if (SCardHelper.IsSet(filedescriptor, FILE_TYPE_MASK, FILE_TYPE_DF))
                _extendedtype = ExtendedFileType.Dedicated;
            else if (SCardHelper.IsSet(filedescriptor, FILE_TYPE_MASK, FILE_TYPE_WORKING_EF))
                _extendedtype = ExtendedFileType.WorkingElementary;
            else if (SCardHelper.IsSet(filedescriptor, FILE_TYPE_MASK, FILE_TYPE_INTERNAL_EF))
                _extendedtype = ExtendedFileType.InternalElementary;
            else _extendedtype = ExtendedFileType.Proprietary;

            // ShareMode
            if (SCardHelper.IsSet(filedescriptor, FILE_SHARE_MODE_MASK, FILE_SHARE_MODE_SHAREABLE))
                _sharemode = FileShareMode.Shareable;
            else
                _sharemode = FileShareMode.NotShareable;

            _filestructureinfo = null;
        }