src: dotnet: testing

This commit is contained in:
Bill Zissimopoulos 2017-04-09 02:01:03 -07:00
parent 0ac9a83026
commit 8f8e8fe086
2 changed files with 60 additions and 45 deletions

View File

@ -100,39 +100,39 @@ namespace Fsp
} }
public void SetCaseSensitiveSearch(Boolean CaseSensitiveSearch) public void SetCaseSensitiveSearch(Boolean CaseSensitiveSearch)
{ {
_VolumeParams.Flags = CaseSensitiveSearch ? VolumeParams.CaseSensitiveSearch : 0; _VolumeParams.Flags |= CaseSensitiveSearch ? VolumeParams.CaseSensitiveSearch : 0;
} }
public void SetCasePreservedNames(Boolean CasePreservedNames) public void SetCasePreservedNames(Boolean CasePreservedNames)
{ {
_VolumeParams.Flags = CasePreservedNames ? VolumeParams.CasePreservedNames : 0; _VolumeParams.Flags |= CasePreservedNames ? VolumeParams.CasePreservedNames : 0;
} }
public void SetUnicodeOnDisk(Boolean UnicodeOnDisk) public void SetUnicodeOnDisk(Boolean UnicodeOnDisk)
{ {
_VolumeParams.Flags = UnicodeOnDisk ? VolumeParams.UnicodeOnDisk : 0; _VolumeParams.Flags |= UnicodeOnDisk ? VolumeParams.UnicodeOnDisk : 0;
} }
public void SetPersistentAcls(Boolean PersistentAcls) public void SetPersistentAcls(Boolean PersistentAcls)
{ {
_VolumeParams.Flags = PersistentAcls ? VolumeParams.PersistentAcls : 0; _VolumeParams.Flags |= PersistentAcls ? VolumeParams.PersistentAcls : 0;
} }
public void SetReparsePoints(Boolean ReparsePoints) public void SetReparsePoints(Boolean ReparsePoints)
{ {
_VolumeParams.Flags = ReparsePoints ? VolumeParams.ReparsePoints : 0; _VolumeParams.Flags |= ReparsePoints ? VolumeParams.ReparsePoints : 0;
} }
public void SetReparsePointsAccessCheck(Boolean ReparsePointsAccessCheck) public void SetReparsePointsAccessCheck(Boolean ReparsePointsAccessCheck)
{ {
_VolumeParams.Flags = ReparsePointsAccessCheck ? VolumeParams.ReparsePointsAccessCheck : 0; _VolumeParams.Flags |= ReparsePointsAccessCheck ? VolumeParams.ReparsePointsAccessCheck : 0;
} }
public void SetNamedStreams(Boolean NamedStreams) public void SetNamedStreams(Boolean NamedStreams)
{ {
_VolumeParams.Flags = NamedStreams ? VolumeParams.NamedStreams : 0; _VolumeParams.Flags |= NamedStreams ? VolumeParams.NamedStreams : 0;
} }
public void SetPostCleanupWhenModifiedOnly(Boolean PostCleanupWhenModifiedOnly) public void SetPostCleanupWhenModifiedOnly(Boolean PostCleanupWhenModifiedOnly)
{ {
_VolumeParams.Flags = PostCleanupWhenModifiedOnly ? VolumeParams.PostCleanupWhenModifiedOnly : 0; _VolumeParams.Flags |= PostCleanupWhenModifiedOnly ? VolumeParams.PostCleanupWhenModifiedOnly : 0;
} }
public void SetPassQueryDirectoryPattern(Boolean PassQueryDirectoryPattern) public void SetPassQueryDirectoryPattern(Boolean PassQueryDirectoryPattern)
{ {
_VolumeParams.Flags = PassQueryDirectoryPattern ? VolumeParams.PassQueryDirectoryPattern : 0; _VolumeParams.Flags |= PassQueryDirectoryPattern ? VolumeParams.PassQueryDirectoryPattern : 0;
} }
public void SetPrefix(String Prefix) public void SetPrefix(String Prefix)
{ {
@ -158,7 +158,7 @@ namespace Fsp
Int32 Result; Int32 Result;
Result = Api.FspFileSystemCreate( Result = Api.FspFileSystemCreate(
_VolumeParams.IsPrefixEmpty() ? "WinFsp.Disk" : "WinFsp.Net", _VolumeParams.IsPrefixEmpty() ? "WinFsp.Disk" : "WinFsp.Net",
ref _VolumeParams, ref _FileSystemInterface, out _FileSystem); ref _VolumeParams, _FileSystemInterface, out _FileSystem);
if (0 <= Result) if (0 <= Result)
{ {
Api.SetUserContext(_FileSystem, this); Api.SetUserContext(_FileSystem, this);
@ -594,11 +594,15 @@ namespace Fsp
FileName, FileName,
out FileAttributes, out FileAttributes,
ref SecurityDescriptorBytes); ref SecurityDescriptorBytes);
if (0 <= Result)
{
if (IntPtr.Zero != PFileAttributes) if (IntPtr.Zero != PFileAttributes)
Marshal.WriteInt32(PFileAttributes, (Int32)FileAttributes); Marshal.WriteInt32(PFileAttributes, (Int32)FileAttributes);
return Api.CopySecurityDescriptor(SecurityDescriptorBytes, Result = Api.CopySecurityDescriptor(SecurityDescriptorBytes,
SecurityDescriptor, PSecurityDescriptorSize); SecurityDescriptor, PSecurityDescriptorSize);
} }
return Result;
}
catch (Exception ex) catch (Exception ex)
{ {
return self.ExceptionHandler(ex); return self.ExceptionHandler(ex);
@ -1187,32 +1191,38 @@ namespace Fsp
static FileSystem() static FileSystem()
{ {
_FileSystemInterface.GetVolumeInfo = GetVolumeInfo; FileSystemInterface FileSystemInterface;
_FileSystemInterface.SetVolumeLabel = SetVolumeLabel; FileSystemInterface = default(FileSystemInterface);
_FileSystemInterface.GetSecurityByName = GetSecurityByName; FileSystemInterface.GetVolumeInfo = GetVolumeInfo;
_FileSystemInterface.Create = Create; FileSystemInterface.SetVolumeLabel = SetVolumeLabel;
_FileSystemInterface.Open = Open; FileSystemInterface.GetSecurityByName = GetSecurityByName;
_FileSystemInterface.Overwrite = Overwrite; FileSystemInterface.Create = Create;
_FileSystemInterface.Cleanup = Cleanup; FileSystemInterface.Open = Open;
_FileSystemInterface.Close = Close; FileSystemInterface.Overwrite = Overwrite;
_FileSystemInterface.Read = Read; FileSystemInterface.Cleanup = Cleanup;
_FileSystemInterface.Write = Write; FileSystemInterface.Close = Close;
_FileSystemInterface.Flush = Flush; FileSystemInterface.Read = Read;
_FileSystemInterface.GetFileInfo = GetFileInfo; FileSystemInterface.Write = Write;
_FileSystemInterface.SetBasicInfo = SetBasicInfo; FileSystemInterface.Flush = Flush;
_FileSystemInterface.SetFileSize = SetFileSize; FileSystemInterface.GetFileInfo = GetFileInfo;
_FileSystemInterface.CanDelete = CanDelete; FileSystemInterface.SetBasicInfo = SetBasicInfo;
_FileSystemInterface.Rename = Rename; FileSystemInterface.SetFileSize = SetFileSize;
_FileSystemInterface.GetSecurity = GetSecurity; FileSystemInterface.CanDelete = CanDelete;
_FileSystemInterface.SetSecurity = SetSecurity; FileSystemInterface.Rename = Rename;
_FileSystemInterface.ReadDirectory = ReadDirectory; FileSystemInterface.GetSecurity = GetSecurity;
_FileSystemInterface.ResolveReparsePoints = ResolveReparsePoints; FileSystemInterface.SetSecurity = SetSecurity;
_FileSystemInterface.GetReparsePoint = GetReparsePoint; FileSystemInterface.ReadDirectory = ReadDirectory;
_FileSystemInterface.SetReparsePoint = SetReparsePoint; FileSystemInterface.ResolveReparsePoints = ResolveReparsePoints;
_FileSystemInterface.DeleteReparsePoint = DeleteReparsePoint; FileSystemInterface.GetReparsePoint = GetReparsePoint;
FileSystemInterface.SetReparsePoint = SetReparsePoint;
FileSystemInterface.DeleteReparsePoint = DeleteReparsePoint;
FileSystemInterface.GetStreamInfo = GetStreamInfo;
_FileSystemInterface = Marshal.AllocHGlobal(Marshal.SizeOf(FileSystemInterface));
Marshal.StructureToPtr(FileSystemInterface, _FileSystemInterface, false);
} }
private static FileSystemInterface _FileSystemInterface; private static IntPtr _FileSystemInterface;
private VolumeParams _VolumeParams; private VolumeParams _VolumeParams;
private IntPtr _FileSystem; private IntPtr _FileSystem;
} }

View File

@ -64,7 +64,7 @@ namespace Fsp.Interop
{ {
fixed (UInt16 *P = Prefix) fixed (UInt16 *P = Prefix)
{ {
int Size = Value.Length; int Size = null != Value ? Value.Length : 0;
if (Size > PrefixSize - 1) if (Size > PrefixSize - 1)
Size = PrefixSize - 1; Size = PrefixSize - 1;
for (int I = 0; Size > I; I++) for (int I = 0; Size > I; I++)
@ -76,7 +76,7 @@ namespace Fsp.Interop
{ {
fixed (UInt16 *P = FileSystemName) fixed (UInt16 *P = FileSystemName)
{ {
int Size = Value.Length; int Size = null != Value ? Value.Length : 0;
if (Size > FileSystemNameSize - 1) if (Size > FileSystemNameSize - 1)
Size = FileSystemNameSize - 1; Size = FileSystemNameSize - 1;
for (int I = 0; Size > I; I++) for (int I = 0; Size > I; I++)
@ -105,7 +105,7 @@ namespace Fsp.Interop
{ {
fixed (UInt16 *P = VolumeLabel) fixed (UInt16 *P = VolumeLabel)
{ {
int Size = Value.Length; int Size = null != Value ? Value.Length : 0;
if (Size > VolumeLabelSize) if (Size > VolumeLabelSize)
Size = VolumeLabelSize; Size = VolumeLabelSize;
for (int I = 0; Size > I; I++) for (int I = 0; Size > I; I++)
@ -153,6 +153,7 @@ namespace Fsp.Interop
internal struct DirInfo internal struct DirInfo
{ {
internal const int FileNameBufSize = 255; internal const int FileNameBufSize = 255;
internal static int FileNameBufOffset = (int)Marshal.OffsetOf(typeof(DirInfo), "FileNameBuf");
internal UInt16 Size; internal UInt16 Size;
internal FileInfo FileInfo; internal FileInfo FileInfo;
@ -164,12 +165,12 @@ namespace Fsp.Interop
{ {
fixed (UInt16 *P = FileNameBuf) fixed (UInt16 *P = FileNameBuf)
{ {
int Size = Value.Length; int Size = null != Value ? Value.Length : 0;
if (Size > FileNameBufSize) if (Size > FileNameBufSize)
Size = FileNameBufSize; Size = FileNameBufSize;
for (int I = 0; Size > I; I++) for (int I = 0; Size > I; I++)
P[I] = Value[I]; P[I] = Value[I];
this.Size = (UInt16)(sizeof(DirInfo) + Size); this.Size = (UInt16)(FileNameBufOffset + Size * 2);
} }
} }
} }
@ -396,7 +397,7 @@ namespace Fsp.Interop
internal Proto.GetReparsePoint GetReparsePoint; internal Proto.GetReparsePoint GetReparsePoint;
internal Proto.SetReparsePoint SetReparsePoint; internal Proto.SetReparsePoint SetReparsePoint;
internal Proto.DeleteReparsePoint DeleteReparsePoint; internal Proto.DeleteReparsePoint DeleteReparsePoint;
internal Proto.DeleteReparsePoint GetStreamInfo; internal Proto.GetStreamInfo GetStreamInfo;
internal unsafe fixed long/*IntPtr*/ Reserved[40]; internal unsafe fixed long/*IntPtr*/ Reserved[40];
/* NTSTATUS (*Reserved[40])(); */ /* NTSTATUS (*Reserved[40])(); */
} }
@ -415,7 +416,7 @@ namespace Fsp.Interop
internal delegate Int32 FspFileSystemCreate( internal delegate Int32 FspFileSystemCreate(
[MarshalAs(UnmanagedType.LPWStr)] String DevicePath, [MarshalAs(UnmanagedType.LPWStr)] String DevicePath,
ref VolumeParams VolumeParams, ref VolumeParams VolumeParams,
ref FileSystemInterface Interface, IntPtr Interface,
out IntPtr PFileSystem); out IntPtr PFileSystem);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate void FspFileSystemDelete( internal delegate void FspFileSystemDelete(
@ -847,6 +848,10 @@ namespace Fsp.Interop
} }
static Api() static Api()
{ {
#if DEBUG
if (Debugger.IsAttached)
Debugger.Break();
#endif
LoadProto(LoadDll()); LoadProto(LoadDll());
} }