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
c782c4d668
commit
20b3ecd0cd
@ -46,7 +46,7 @@ namespace Fsp
|
|||||||
if (IntPtr.Zero != _FileSystem)
|
if (IntPtr.Zero != _FileSystem)
|
||||||
{
|
{
|
||||||
Api.FspFileSystemStopDispatcher(_FileSystem);
|
Api.FspFileSystemStopDispatcher(_FileSystem);
|
||||||
Api.FspFileSystemSetUserContext(_FileSystem, null);
|
Api.SetUserContext(_FileSystem, null);
|
||||||
Api.FspFileSystemDelete(_FileSystem);
|
Api.FspFileSystemDelete(_FileSystem);
|
||||||
_FileSystem = IntPtr.Zero;
|
_FileSystem = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
@ -140,7 +140,7 @@ namespace Fsp
|
|||||||
ref _VolumeParams, ref _FileSystemInterface, out _FileSystem);
|
ref _VolumeParams, ref _FileSystemInterface, out _FileSystem);
|
||||||
if (0 <= Result)
|
if (0 <= Result)
|
||||||
{
|
{
|
||||||
Api.FspFileSystemSetUserContext(_FileSystem, this);
|
Api.SetUserContext(_FileSystem, this);
|
||||||
#if false
|
#if false
|
||||||
FspFileSystemSetOperationGuardStrategy(_FileSystem, Synchronized ?
|
FspFileSystemSetOperationGuardStrategy(_FileSystem, Synchronized ?
|
||||||
FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_COARSE :
|
FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_COARSE :
|
||||||
@ -154,7 +154,7 @@ namespace Fsp
|
|||||||
}
|
}
|
||||||
if (0 > Result && IntPtr.Zero != _FileSystem)
|
if (0 > Result && IntPtr.Zero != _FileSystem)
|
||||||
{
|
{
|
||||||
Api.FspFileSystemSetUserContext(_FileSystem, null);
|
Api.SetUserContext(_FileSystem, null);
|
||||||
Api.FspFileSystemDelete(_FileSystem);
|
Api.FspFileSystemDelete(_FileSystem);
|
||||||
_FileSystem = IntPtr.Zero;
|
_FileSystem = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
@ -433,7 +433,7 @@ namespace Fsp
|
|||||||
IntPtr FileSystem,
|
IntPtr FileSystem,
|
||||||
out VolumeInfo VolumeInfo)
|
out VolumeInfo VolumeInfo)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return self.GetVolumeInfo(
|
return self.GetVolumeInfo(
|
||||||
@ -450,7 +450,7 @@ namespace Fsp
|
|||||||
String VolumeLabel,
|
String VolumeLabel,
|
||||||
out VolumeInfo VolumeInfo)
|
out VolumeInfo VolumeInfo)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return self.SetVolumeLabel(
|
return self.SetVolumeLabel(
|
||||||
@ -470,7 +470,7 @@ namespace Fsp
|
|||||||
IntPtr SecurityDescriptor,
|
IntPtr SecurityDescriptor,
|
||||||
IntPtr PSecurityDescriptorSize)
|
IntPtr PSecurityDescriptorSize)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
UInt32 FileAttributes;
|
UInt32 FileAttributes;
|
||||||
@ -503,7 +503,7 @@ namespace Fsp
|
|||||||
ref FullContext FullContext,
|
ref FullContext FullContext,
|
||||||
out OpenFileInfo OpenFileInfo)
|
out OpenFileInfo OpenFileInfo)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -535,7 +535,7 @@ namespace Fsp
|
|||||||
ref FullContext FullContext,
|
ref FullContext FullContext,
|
||||||
out OpenFileInfo OpenFileInfo)
|
out OpenFileInfo OpenFileInfo)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -564,7 +564,7 @@ namespace Fsp
|
|||||||
UInt64 AllocationSize,
|
UInt64 AllocationSize,
|
||||||
out FileInfo FileInfo)
|
out FileInfo FileInfo)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -589,7 +589,7 @@ namespace Fsp
|
|||||||
String FileName,
|
String FileName,
|
||||||
UInt32 Flags)
|
UInt32 Flags)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -609,7 +609,7 @@ namespace Fsp
|
|||||||
IntPtr FileSystem,
|
IntPtr FileSystem,
|
||||||
ref FullContext FullContext)
|
ref FullContext FullContext)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -632,7 +632,7 @@ namespace Fsp
|
|||||||
UInt32 Length,
|
UInt32 Length,
|
||||||
out UInt32 PBytesTransferred)
|
out UInt32 PBytesTransferred)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -662,7 +662,7 @@ namespace Fsp
|
|||||||
out UInt32 PBytesTransferred,
|
out UInt32 PBytesTransferred,
|
||||||
out FileInfo FileInfo)
|
out FileInfo FileInfo)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -690,7 +690,7 @@ namespace Fsp
|
|||||||
ref FullContext FullContext,
|
ref FullContext FullContext,
|
||||||
out FileInfo FileInfo)
|
out FileInfo FileInfo)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -711,7 +711,7 @@ namespace Fsp
|
|||||||
ref FullContext FullContext,
|
ref FullContext FullContext,
|
||||||
out FileInfo FileInfo)
|
out FileInfo FileInfo)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -737,7 +737,7 @@ namespace Fsp
|
|||||||
UInt64 ChangeTime,
|
UInt64 ChangeTime,
|
||||||
out FileInfo FileInfo)
|
out FileInfo FileInfo)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -765,7 +765,7 @@ namespace Fsp
|
|||||||
Boolean SetAllocationSize,
|
Boolean SetAllocationSize,
|
||||||
out FileInfo FileInfo)
|
out FileInfo FileInfo)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -788,7 +788,7 @@ namespace Fsp
|
|||||||
ref FullContext FullContext,
|
ref FullContext FullContext,
|
||||||
String FileName)
|
String FileName)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -810,7 +810,7 @@ namespace Fsp
|
|||||||
String NewFileName,
|
String NewFileName,
|
||||||
Boolean ReplaceIfExists)
|
Boolean ReplaceIfExists)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -833,7 +833,7 @@ namespace Fsp
|
|||||||
IntPtr SecurityDescriptor,
|
IntPtr SecurityDescriptor,
|
||||||
IntPtr PSecurityDescriptorSize)
|
IntPtr PSecurityDescriptorSize)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -860,7 +860,7 @@ namespace Fsp
|
|||||||
UInt32 SecurityInformation,
|
UInt32 SecurityInformation,
|
||||||
IntPtr ModificationDescriptor)
|
IntPtr ModificationDescriptor)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -885,7 +885,7 @@ namespace Fsp
|
|||||||
UInt32 Length,
|
UInt32 Length,
|
||||||
out UInt32 PBytesTransferred)
|
out UInt32 PBytesTransferred)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -914,7 +914,7 @@ namespace Fsp
|
|||||||
IntPtr Buffer,
|
IntPtr Buffer,
|
||||||
ref UIntPtr PSize)
|
ref UIntPtr PSize)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return self.ResolveReparsePoints(
|
return self.ResolveReparsePoints(
|
||||||
@ -939,7 +939,7 @@ namespace Fsp
|
|||||||
IntPtr Buffer,
|
IntPtr Buffer,
|
||||||
ref UIntPtr PSize)
|
ref UIntPtr PSize)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return self.GetReparsePointByName(
|
return self.GetReparsePointByName(
|
||||||
@ -960,7 +960,7 @@ namespace Fsp
|
|||||||
IntPtr Buffer,
|
IntPtr Buffer,
|
||||||
out UIntPtr PSize)
|
out UIntPtr PSize)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -985,7 +985,7 @@ namespace Fsp
|
|||||||
IntPtr Buffer,
|
IntPtr Buffer,
|
||||||
UIntPtr Size)
|
UIntPtr Size)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -1009,7 +1009,7 @@ namespace Fsp
|
|||||||
IntPtr Buffer,
|
IntPtr Buffer,
|
||||||
UIntPtr Size)
|
UIntPtr Size)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
@ -1033,7 +1033,7 @@ namespace Fsp
|
|||||||
UInt32 Length,
|
UInt32 Length,
|
||||||
out UInt32 PBytesTransferred)
|
out UInt32 PBytesTransferred)
|
||||||
{
|
{
|
||||||
FileSystem self = (FileSystem)Api.FspFileSystemGetUserContext(FileSystem);
|
FileSystem self = (FileSystem)Api.GetUserContext(FileSystem);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object FileNode, FileDesc;
|
Object FileNode, FileDesc;
|
||||||
|
@ -539,29 +539,30 @@ namespace Fsp.Interop
|
|||||||
else
|
else
|
||||||
return _FspFileSystemSetMountPointEx(FileSystem, MountPoint, IntPtr.Zero);
|
return _FspFileSystemSetMountPointEx(FileSystem, MountPoint, IntPtr.Zero);
|
||||||
}
|
}
|
||||||
internal unsafe static Object FspFileSystemGetUserContext(
|
|
||||||
IntPtr FileSystem)
|
internal unsafe static Object GetUserContext(
|
||||||
|
IntPtr NativePtr)
|
||||||
{
|
{
|
||||||
IntPtr UserContext = *(IntPtr *)((byte *)FileSystem + sizeof(IntPtr));
|
IntPtr UserContext = *(IntPtr *)((byte *)NativePtr + sizeof(IntPtr));
|
||||||
return IntPtr.Zero != UserContext ? GCHandle.FromIntPtr(UserContext).Target : null;
|
return IntPtr.Zero != UserContext ? GCHandle.FromIntPtr(UserContext).Target : null;
|
||||||
}
|
}
|
||||||
internal unsafe static void FspFileSystemSetUserContext(
|
internal unsafe static void SetUserContext(
|
||||||
IntPtr FileSystem,
|
IntPtr NativePtr,
|
||||||
Object Obj)
|
Object Obj)
|
||||||
{
|
{
|
||||||
if (null != Obj)
|
if (null != Obj)
|
||||||
{
|
{
|
||||||
Debug.Assert(IntPtr.Zero == *(IntPtr *)((byte *)FileSystem + sizeof(IntPtr)));
|
Debug.Assert(IntPtr.Zero == *(IntPtr *)((byte *)NativePtr + sizeof(IntPtr)));
|
||||||
GCHandle Handle = GCHandle.Alloc(Obj, GCHandleType.Weak);
|
GCHandle Handle = GCHandle.Alloc(Obj, GCHandleType.Weak);
|
||||||
*(IntPtr *)((byte *)FileSystem + sizeof(IntPtr)) = (IntPtr)Handle;
|
*(IntPtr *)((byte *)NativePtr + sizeof(IntPtr)) = (IntPtr)Handle;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IntPtr UserContext = *(IntPtr *)((byte *)FileSystem + sizeof(IntPtr));
|
IntPtr UserContext = *(IntPtr *)((byte *)NativePtr + sizeof(IntPtr));
|
||||||
if (IntPtr.Zero != UserContext)
|
if (IntPtr.Zero != UserContext)
|
||||||
{
|
{
|
||||||
GCHandle.FromIntPtr(UserContext).Free();
|
GCHandle.FromIntPtr(UserContext).Free();
|
||||||
*(IntPtr *)((byte *)FileSystem + sizeof(IntPtr)) = IntPtr.Zero;
|
*(IntPtr *)((byte *)NativePtr + sizeof(IntPtr)) = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -649,33 +650,6 @@ namespace Fsp.Interop
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal unsafe static Object FspServiceGetUserContext(
|
|
||||||
IntPtr Service)
|
|
||||||
{
|
|
||||||
IntPtr UserContext = *(IntPtr *)((byte *)Service + sizeof(IntPtr));
|
|
||||||
return IntPtr.Zero != UserContext ? GCHandle.FromIntPtr(UserContext).Target : null;
|
|
||||||
}
|
|
||||||
internal unsafe static void FspServiceSetUserContext(
|
|
||||||
IntPtr Service,
|
|
||||||
Object Obj)
|
|
||||||
{
|
|
||||||
if (null != Obj)
|
|
||||||
{
|
|
||||||
Debug.Assert(IntPtr.Zero == *(IntPtr *)((byte *)Service + sizeof(IntPtr)));
|
|
||||||
GCHandle Handle = GCHandle.Alloc(Obj, GCHandleType.Weak);
|
|
||||||
*(IntPtr *)((byte *)Service + sizeof(IntPtr)) = (IntPtr)Handle;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
IntPtr UserContext = *(IntPtr *)((byte *)Service + sizeof(IntPtr));
|
|
||||||
if (IntPtr.Zero != UserContext)
|
|
||||||
{
|
|
||||||
GCHandle.FromIntPtr(UserContext).Free();
|
|
||||||
*(IntPtr *)((byte *)Service + sizeof(IntPtr)) = IntPtr.Zero;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* initialization */
|
/* initialization */
|
||||||
private static IntPtr LoadDll()
|
private static IntPtr LoadDll()
|
||||||
{
|
{
|
||||||
|
@ -34,13 +34,13 @@ namespace Fsp
|
|||||||
Service(String ServiceName)
|
Service(String ServiceName)
|
||||||
{
|
{
|
||||||
_CreateResult = Api.FspServiceCreate(ServiceName, OnStart, OnStop, null, out _Service);
|
_CreateResult = Api.FspServiceCreate(ServiceName, OnStart, OnStop, null, out _Service);
|
||||||
Api.FspServiceSetUserContext(_Service, this);
|
Api.SetUserContext(_Service, this);
|
||||||
}
|
}
|
||||||
~Service()
|
~Service()
|
||||||
{
|
{
|
||||||
if (IntPtr.Zero != _Service)
|
if (IntPtr.Zero != _Service)
|
||||||
{
|
{
|
||||||
Api.FspServiceSetUserContext(_Service, null);
|
Api.SetUserContext(_Service, null);
|
||||||
Api.FspServiceDelete(_Service);
|
Api.FspServiceDelete(_Service);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ namespace Fsp
|
|||||||
UInt32 Argc,
|
UInt32 Argc,
|
||||||
String[] Argv)
|
String[] Argv)
|
||||||
{
|
{
|
||||||
Service self = (Service)Api.FspServiceGetUserContext(Service);
|
Service self = (Service)Api.GetUserContext(Service);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return self.OnStart(
|
return self.OnStart(
|
||||||
@ -110,7 +110,7 @@ namespace Fsp
|
|||||||
private static Int32 OnStop(
|
private static Int32 OnStop(
|
||||||
IntPtr Service)
|
IntPtr Service)
|
||||||
{
|
{
|
||||||
Service self = (Service)Api.FspServiceGetUserContext(Service);
|
Service self = (Service)Api.GetUserContext(Service);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return self.OnStop();
|
return self.OnStop();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user