Example #1
0
 internal static extern SafeFileHandle CreateFileTransacted(
     [In, MarshalAs(UnmanagedType.LPWStr)] string lpFileName,
     [In] WindowsNative.FileAccess dwDesiredAccess,
     [In] WindowsNative.FileShare dwShareMode,
     [In] IntPtr lpSecurityAttributes,
     [In] WindowsNative.FileMode dwCreationDisposition,
     [In] EFileAttributes dwFlagsAndAttributes,
     [In] IntPtr hTemplateFile,
     [In] KtmTransactionHandle hTransaction,
     [In] IntPtr pusMiniVersion,
     [In] IntPtr pExtendedParameter);
Example #2
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);
        }