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