mirror of
https://github.com/winfsp/winfsp.git
synced 2025-04-23 00:43:00 -05:00
src: dotnet: WIP
This commit is contained in:
parent
fa9ff37de9
commit
f2391d99d5
@ -36,13 +36,16 @@ namespace Fsp
|
|||||||
}
|
}
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
Dispose(true);
|
lock (this)
|
||||||
|
Dispose(true);
|
||||||
GC.SuppressFinalize(true);
|
GC.SuppressFinalize(true);
|
||||||
}
|
}
|
||||||
protected void Dispose(bool disposing)
|
protected virtual void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (IntPtr.Zero != _FileSystem)
|
if (IntPtr.Zero != _FileSystem)
|
||||||
{
|
{
|
||||||
|
Api.FspFileSystemStopDispatcher(_FileSystem);
|
||||||
|
Api.FspFileSystemSetUserContext(_FileSystem, null);
|
||||||
Api.FspFileSystemDelete(_FileSystem);
|
Api.FspFileSystemDelete(_FileSystem);
|
||||||
_FileSystem = IntPtr.Zero;
|
_FileSystem = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
@ -136,8 +139,8 @@ namespace Fsp
|
|||||||
ref _VolumeParams, ref _FileSystemInterface, out _FileSystem);
|
ref _VolumeParams, ref _FileSystemInterface, out _FileSystem);
|
||||||
if (0 <= Result)
|
if (0 <= Result)
|
||||||
{
|
{
|
||||||
|
Api.FspFileSystemSetUserContext(_FileSystem, this);
|
||||||
#if false
|
#if false
|
||||||
_FileSystem->UserContext = this;
|
|
||||||
FspFileSystemSetOperationGuardStrategy(_FileSystem, Synchronized ?
|
FspFileSystemSetOperationGuardStrategy(_FileSystem, Synchronized ?
|
||||||
FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_COARSE :
|
FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_COARSE :
|
||||||
FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_FINE);
|
FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_FINE);
|
||||||
@ -150,6 +153,7 @@ namespace Fsp
|
|||||||
}
|
}
|
||||||
if (0 > Result && IntPtr.Zero != _FileSystem)
|
if (0 > Result && IntPtr.Zero != _FileSystem)
|
||||||
{
|
{
|
||||||
|
Api.FspFileSystemSetUserContext(_FileSystem, null);
|
||||||
Api.FspFileSystemDelete(_FileSystem);
|
Api.FspFileSystemDelete(_FileSystem);
|
||||||
_FileSystem = IntPtr.Zero;
|
_FileSystem = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
@ -157,9 +161,7 @@ namespace Fsp
|
|||||||
}
|
}
|
||||||
public void Unmount()
|
public void Unmount()
|
||||||
{
|
{
|
||||||
Api.FspFileSystemStopDispatcher(_FileSystem);
|
Dispose();
|
||||||
Api.FspFileSystemDelete(_FileSystem);
|
|
||||||
_FileSystem = IntPtr.Zero;
|
|
||||||
}
|
}
|
||||||
#if false
|
#if false
|
||||||
PWSTR MountPoint()
|
PWSTR MountPoint()
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Security.AccessControl;
|
using System.Security.AccessControl;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
@ -409,6 +410,32 @@ namespace Fsp.Interop
|
|||||||
else
|
else
|
||||||
return FspFileSystemSetMountPointEx(FileSystem, MountPoint, IntPtr.Zero);
|
return FspFileSystemSetMountPointEx(FileSystem, MountPoint, IntPtr.Zero);
|
||||||
}
|
}
|
||||||
|
internal unsafe static Object FspFileSystemGetUserContext(
|
||||||
|
IntPtr FileSystem)
|
||||||
|
{
|
||||||
|
IntPtr UserContext = Marshal.ReadIntPtr(FileSystem, sizeof(IntPtr));
|
||||||
|
return IntPtr.Zero != UserContext ? ((GCHandle)UserContext).Target : null;
|
||||||
|
}
|
||||||
|
internal unsafe static void FspFileSystemSetUserContext(
|
||||||
|
IntPtr FileSystem,
|
||||||
|
Object Obj)
|
||||||
|
{
|
||||||
|
if (null != Obj)
|
||||||
|
{
|
||||||
|
Debug.Assert(IntPtr.Zero == Marshal.ReadIntPtr(FileSystem, sizeof(IntPtr)));
|
||||||
|
GCHandle Handle = GCHandle.Alloc(Obj, GCHandleType.Weak);
|
||||||
|
Marshal.WriteIntPtr(FileSystem, sizeof(IntPtr), (IntPtr)Handle);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IntPtr UserContext = Marshal.ReadIntPtr(FileSystem, sizeof(IntPtr));
|
||||||
|
if (IntPtr.Zero != UserContext)
|
||||||
|
{
|
||||||
|
((GCHandle)UserContext).Free();
|
||||||
|
Marshal.WriteIntPtr(FileSystem, sizeof(IntPtr), IntPtr.Zero);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* initialization */
|
/* initialization */
|
||||||
[DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
|
[DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user