Beispiel #1
0
        private static SafeFileHandle GetFileHandle(LongPath path, FileMode mode, FileAccess access, FileShare share, FileOptions options)
        {
            SafeFileHandle handle;

            if (KtmTransaction.IsInTransaction)
            {
                WindowsNative.FileMode   internalMode   = WindowsNative.TranslateFileMode(mode);
                WindowsNative.FileShare  internalShare  = WindowsNative.TranslateFileShare(share);
                WindowsNative.FileAccess internalAccess = WindowsNative.TranslateFileAccess(access);

                KtmTransactionHandle ktmTx = KtmTransaction.Current.Hanlde;

                // Create the transacted file using P/Invoke.
                handle = WindowsNative.CreateFileTransacted(
                    path.PathString,
                    internalAccess,
                    internalShare,
                    IntPtr.Zero,
                    internalMode,
                    WindowsNative.EFileAttributes.Normal,
                    IntPtr.Zero,
                    KtmTransaction.Current.Hanlde,
                    IntPtr.Zero,
                    IntPtr.Zero);
            }
            else
            {
                WindowsNative.EFileAccess underlyingAccess = WindowsNative.GetUnderlyingAccess(access);
                handle = WindowsNative.CreateFile(path.PathString, underlyingAccess, (uint)share, IntPtr.Zero, (uint)mode, (uint)options, IntPtr.Zero);
            }

            if (handle.IsInvalid)
            {
                WindowsNative.HandleWindowsError();
            }

            return(handle);
        }