diff --git a/src/dotnet/FileSystem.cs b/src/dotnet/FileSystem.cs index a2f3aa01..c3d97132 100644 --- a/src/dotnet/FileSystem.cs +++ b/src/dotnet/FileSystem.cs @@ -123,13 +123,13 @@ namespace Fsp } /* control */ - Int32 Preflight(String MountPoint) + public Int32 Preflight(String MountPoint) { return Api.FspFileSystemPreflight( _VolumeParams.IsPrefixEmpty() ? "WinFsp.Disk" : "WinFsp.Net", MountPoint); } - Int32 Mount(String MountPoint, + public Int32 Mount(String MountPoint, Byte[] SecurityDescriptor = null, Boolean Synchronized = false, UInt32 DebugLog = 0) @@ -164,13 +164,14 @@ namespace Fsp { Dispose(); } -#if false - PWSTR MountPoint() + public String MountPoint() { + return "UNKNOWN"; +#if false return 0 != _FileSystem ? FspFileSystemMountPoint(_FileSystem) : 0; - } #endif - IntPtr FileSystemHandle() + } + public IntPtr FileSystemHandle() { return _FileSystem; } @@ -184,9 +185,9 @@ namespace Fsp { return Api.FspWin32FromNtStatus(Status); } - public static void FspDebugLogSetHandle(IntPtr Handle) + public static Int32 SetDebugLogFile(String FileName) { - Api.FspDebugLogSetHandle(Handle); + return Api.SetDebugLogFile(FileName); } /* operations */ diff --git a/src/dotnet/Interop.cs b/src/dotnet/Interop.cs index ede2d672..dd42f7cc 100644 --- a/src/dotnet/Interop.cs +++ b/src/dotnet/Interop.cs @@ -20,6 +20,7 @@ using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; using System.Security; +using System.Security.AccessControl; namespace Fsp.Interop { @@ -663,6 +664,26 @@ namespace Fsp.Interop return null; } + internal static Int32 SetDebugLogFile(String FileName) + { + IntPtr Handle; + if ("-" == FileName) + Handle = GetStdHandle(unchecked((UInt32)(-12))/*STD_ERROR_HANDLE*/); + else + Handle = CreateFileW( + FileName, + (UInt32)FileSystemRights.AppendData, + (UInt32)(FileShare.Read | FileShare.Write), + IntPtr.Zero, + (UInt32)FileMode.OpenOrCreate, + (UInt32)FileAttributes.Normal, + IntPtr.Zero); + if ((IntPtr)(-1) == Handle) + return FspNtStatusFromWin32((UInt32)Marshal.GetLastWin32Error()); + Api.FspDebugLogSetHandle(Handle); + return 0/*STATUS_SUCCESS*/; + } + /* initialization */ private static IntPtr LoadDll() { @@ -738,6 +759,17 @@ namespace Fsp.Interop [MarshalAs(UnmanagedType.LPStr)] String lpProcName); [DllImport("advapi32.dll", CallingConvention = CallingConvention.StdCall)] private static extern UInt32 GetSecurityDescriptorLength(IntPtr SecurityDescriptor); + [DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)] + private static extern IntPtr GetStdHandle(UInt32 nStdHandle); + [DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)] + private static extern IntPtr CreateFileW( + [MarshalAs(UnmanagedType.LPWStr)] String lpFileName, + UInt32 dwDesiredAccess, + UInt32 dwShareMode, + IntPtr lpSecurityAttributes, + UInt32 dwCreationDisposition, + UInt32 dwFlagsAndAttributes, + IntPtr hTemplateFile); } }