Beispiel #1
0
        //TODO UNBUFF use FileAccess etc or do custom?
        public SafeFileHandle Create(string path, FileAccess acc, FileShare readWrite, FileMode mode, int flags)
        {
            var handle = WinNative.CreateFile(path,
                                              acc,
                                              FileShare.ReadWrite,
                                              IntPtr.Zero,
                                              mode,
                                              flags,
                                              IntPtr.Zero);

            if (handle.IsInvalid)
            {
                throw new Win32Exception();
            }

            return(handle);
        }
Beispiel #2
0
        public static SafeFileHandle CreateUnbufferedRW(string path, FileAccess acc, FileShare share, FileMode mode, bool writeThrough)
        {
#if !__MonoCS__ && !USE_UNIX_IO
            var flags = ExtendedFileOptions.NoBuffering;
            if (writeThrough)
            {
                flags = flags | ExtendedFileOptions.WriteThrough;
            }
            var handle = WinNative.CreateFile(path,
                                              acc,
                                              share,
                                              IntPtr.Zero,
                                              FileMode.OpenOrCreate,
                                              (int)flags,
                                              IntPtr.Zero);
            if (handle.IsInvalid)
            {
                throw new Win32Exception();
            }
            return(handle);
#else
            var ismac = OS.OsFlavor == OsFlavor.MacOS;
            //O_RDONLY is 0
            var direct = ismac ? OpenFlags.O_RDONLY : OpenFlags.O_DIRECT;
            var flags  = GetFlags(acc, mode) | direct;
            var han    = Syscall.open(path, flags, FilePermissions.S_IRWXU);
            if (han < 0)
            {
                throw new Win32Exception();
            }

            var handle = new SafeFileHandle((IntPtr)han, true);
            if (handle.IsInvalid)
            {
                throw new Exception("Invalid handle");
            }
            if (ismac)
            {
                TurnOffMacCaching(handle);
            }
            return(handle);
#endif
        }
Beispiel #3
0
        //TODO UNBUFF use FileAccess etc or do custom?
        public static SafeFileHandle Create(string path, FileAccess acc, FileShare readWrite, FileMode mode, int flags)
        {
#if !__MonoCS__ && !USE_UNIX_IO
            var handle = WinNative.CreateFile(path,
                                              acc,
                                              FileShare.ReadWrite,
                                              IntPtr.Zero,
                                              mode,
                                              flags,
                                              IntPtr.Zero);
            if (handle.IsInvalid)
            {
                throw new Win32Exception();
            }
            return(handle);
#else
            //TODO convert flags or separate methods?
            return(new SafeFileHandle((IntPtr)0, true));
#endif
        }
Beispiel #4
0
        public SafeFileHandle CreateUnbufferedRW(string path, FileAccess acc, FileShare share, FileMode mode,
                                                 bool writeThrough)
        {
            var flags = ExtendedFileOptions.NoBuffering;

            if (writeThrough)
            {
                flags = flags | ExtendedFileOptions.WriteThrough;
            }
            var handle = WinNative.CreateFile(path,
                                              acc,
                                              share,
                                              IntPtr.Zero,
                                              FileMode.OpenOrCreate,
                                              (int)flags,
                                              IntPtr.Zero);

            if (handle.IsInvalid)
            {
                throw new Win32Exception();
            }

            return(handle);
        }