src: dotnet: WIP

This commit is contained in:
Bill Zissimopoulos 2017-04-02 15:13:05 -07:00
parent 47b81a8025
commit 89324d2327
3 changed files with 63 additions and 16 deletions

View File

@ -24,7 +24,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>

View File

@ -111,18 +111,18 @@ namespace Fsp
} }
public void SetPrefix(String Prefix) public void SetPrefix(String Prefix)
{ {
_VolumeParams.Prefix = Prefix; _VolumeParams.SetPrefix(Prefix);
} }
public void SetFileSystemName(String FileSystemName) public void SetFileSystemName(String FileSystemName)
{ {
_VolumeParams.FileSystemName = FileSystemName; _VolumeParams.SetFileSystemName(FileSystemName);
} }
/* control */ /* control */
Int32 Preflight(String MountPoint) Int32 Preflight(String MountPoint)
{ {
return Api.FspFileSystemPreflight( return Api.FspFileSystemPreflight(
0 < _VolumeParams.Prefix.Length ? "WinFsp.Net" : "WinFsp.Disk", _VolumeParams.IsPrefixEmpty() ? "WinFsp.Disk" : "WinFsp.Net",
MountPoint); MountPoint);
} }
Int32 Mount(String MountPoint, Int32 Mount(String MountPoint,
@ -130,11 +130,10 @@ namespace Fsp
Boolean Synchronized = false, Boolean Synchronized = false,
UInt32 DebugLog = 0) UInt32 DebugLog = 0)
{ {
FileSystemInterface Intf; // ???: padding
Int32 Result; Int32 Result;
Result = Api.FspFileSystemCreate( Result = Api.FspFileSystemCreate(
0 < _VolumeParams.Prefix.Length ? "WinFsp.Net" : "WinFsp.Disk", _VolumeParams.IsPrefixEmpty() ? "WinFsp.Disk" : "WinFsp.Net",
ref _VolumeParams, ref Intf, out _FileSystem); ref _VolumeParams, ref _FileSystemInterface, out _FileSystem);
if (0 <= Result) if (0 <= Result)
{ {
#if false #if false
@ -144,7 +143,8 @@ namespace Fsp
FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_FINE); FSP_FILE_SYSTEM_OPERATION_GUARD_STRATEGY_FINE);
FspFileSystemSetDebugLog(_FileSystem, DebugLog); FspFileSystemSetDebugLog(_FileSystem, DebugLog);
#endif #endif
Result = Api.FspFileSystemSetMountPointEx(_FileSystem, MountPoint, IntPtr.Zero); Result = Api.FspFileSystemSetMountPointEx(_FileSystem, MountPoint,
SecurityDescriptor);
if (0 <= Result) if (0 <= Result)
Result = Api.FspFileSystemStartDispatcher(_FileSystem, 0); Result = Api.FspFileSystemStartDispatcher(_FileSystem, 0);
} }
@ -172,6 +172,7 @@ namespace Fsp
return _FileSystem; return _FileSystem;
} }
private static FileSystemInterface _FileSystemInterface;
private VolumeParams _VolumeParams; private VolumeParams _VolumeParams;
private IntPtr _FileSystem; private IntPtr _FileSystem;
} }

View File

@ -16,6 +16,7 @@
*/ */
using System; using System;
using System.Security.AccessControl;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
@ -56,10 +57,39 @@ namespace Fsp.Interop
internal UInt32 IrpCapacity; internal UInt32 IrpCapacity;
internal UInt32 FileInfoTimeout; internal UInt32 FileInfoTimeout;
internal UInt32 Flags; internal UInt32 Flags;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = PrefixSize)] internal unsafe fixed UInt16 Prefix[PrefixSize];
internal String Prefix; internal unsafe fixed UInt16 FileSystemName[FileSystemNameSize];
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = FileSystemNameSize)]
internal String FileSystemName; /* helpers */
internal unsafe void SetPrefix(String Value)
{
fixed (UInt16 *P = Prefix)
{
int Size = Value.Length;
if (Size > PrefixSize - 1)
Size = PrefixSize - 1;
for (int I = 0; Size > I; I++)
P[I] = Value[I];
P[Size] = 0;
}
}
internal unsafe void SetFileSystemName(String Value)
{
fixed (UInt16 *P = FileSystemName)
{
int Size = Value.Length;
if (Size > FileSystemNameSize - 1)
Size = FileSystemNameSize - 1;
for (int I = 0; Size > I; I++)
P[I] = Value[I];
P[Size] = 0;
}
}
internal unsafe Boolean IsPrefixEmpty()
{
fixed (UInt16 *P = Prefix)
return 0 == *P;
}
} }
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
@ -70,8 +100,7 @@ namespace Fsp.Interop
internal UInt64 TotalSize; internal UInt64 TotalSize;
internal UInt64 FreeSize; internal UInt64 FreeSize;
internal UInt16 VolumeLabelLength; internal UInt16 VolumeLabelLength;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = VolumeLabelSize)] internal unsafe fixed UInt16 VolumeLabel[VolumeLabelSize];
internal String VolumeLabel;
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
@ -102,7 +131,7 @@ namespace Fsp.Interop
{ {
internal UInt16 Size; internal UInt16 Size;
internal FileInfo FileInfo; internal FileInfo FileInfo;
//internal unsafe fixed Byte Padding[24]; internal unsafe fixed Byte Padding[24];
//internal unsafe fixed UInt16 FileNameBuf[]; //internal unsafe fixed UInt16 FileNameBuf[];
} }
@ -309,7 +338,8 @@ namespace Fsp.Interop
UInt32 Length, UInt32 Length,
out UInt32 PBytesTransferred); out UInt32 PBytesTransferred);
//internal unsafe fixed IntPtr Reserved[40]; internal unsafe fixed long/*IntPtr*/ Reserved[40];
/* NTSTATUS (*Reserved[40])(); */
} }
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
@ -367,6 +397,22 @@ namespace Fsp.Interop
[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)] [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
internal static extern UInt32 FspWin32FromNtStatus( internal static extern UInt32 FspWin32FromNtStatus(
Int32 Status); Int32 Status);
internal static unsafe Int32 FspFileSystemSetMountPointEx(
IntPtr FileSystem,
String MountPoint,
GenericSecurityDescriptor SecurityDescriptor)
{
if (null != SecurityDescriptor)
{
byte[] Bytes = new byte[SecurityDescriptor.BinaryLength];
SecurityDescriptor.GetBinaryForm(Bytes, 0);
fixed (byte *P = Bytes)
return FspFileSystemSetMountPointEx(FileSystem, MountPoint, (IntPtr)P);
}
else
return FspFileSystemSetMountPointEx(FileSystem, MountPoint, IntPtr.Zero);
}
} }
internal static class Initializer internal static class Initializer