From 8f8e8fe0869b6da1278476101efd501cdfd13afd Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Sun, 9 Apr 2017 02:01:03 -0700 Subject: [PATCH] src: dotnet: testing --- src/dotnet/FileSystem.cs | 86 ++++++++++++++++++++++------------------ src/dotnet/Interop.cs | 19 +++++---- 2 files changed, 60 insertions(+), 45 deletions(-) diff --git a/src/dotnet/FileSystem.cs b/src/dotnet/FileSystem.cs index 17d235a3..0208405c 100644 --- a/src/dotnet/FileSystem.cs +++ b/src/dotnet/FileSystem.cs @@ -100,39 +100,39 @@ namespace Fsp } public void SetCaseSensitiveSearch(Boolean CaseSensitiveSearch) { - _VolumeParams.Flags = CaseSensitiveSearch ? VolumeParams.CaseSensitiveSearch : 0; + _VolumeParams.Flags |= CaseSensitiveSearch ? VolumeParams.CaseSensitiveSearch : 0; } public void SetCasePreservedNames(Boolean CasePreservedNames) { - _VolumeParams.Flags = CasePreservedNames ? VolumeParams.CasePreservedNames : 0; + _VolumeParams.Flags |= CasePreservedNames ? VolumeParams.CasePreservedNames : 0; } public void SetUnicodeOnDisk(Boolean UnicodeOnDisk) { - _VolumeParams.Flags = UnicodeOnDisk ? VolumeParams.UnicodeOnDisk : 0; + _VolumeParams.Flags |= UnicodeOnDisk ? VolumeParams.UnicodeOnDisk : 0; } public void SetPersistentAcls(Boolean PersistentAcls) { - _VolumeParams.Flags = PersistentAcls ? VolumeParams.PersistentAcls : 0; + _VolumeParams.Flags |= PersistentAcls ? VolumeParams.PersistentAcls : 0; } public void SetReparsePoints(Boolean ReparsePoints) { - _VolumeParams.Flags = ReparsePoints ? VolumeParams.ReparsePoints : 0; + _VolumeParams.Flags |= ReparsePoints ? VolumeParams.ReparsePoints : 0; } public void SetReparsePointsAccessCheck(Boolean ReparsePointsAccessCheck) { - _VolumeParams.Flags = ReparsePointsAccessCheck ? VolumeParams.ReparsePointsAccessCheck : 0; + _VolumeParams.Flags |= ReparsePointsAccessCheck ? VolumeParams.ReparsePointsAccessCheck : 0; } public void SetNamedStreams(Boolean NamedStreams) { - _VolumeParams.Flags = NamedStreams ? VolumeParams.NamedStreams : 0; + _VolumeParams.Flags |= NamedStreams ? VolumeParams.NamedStreams : 0; } public void SetPostCleanupWhenModifiedOnly(Boolean PostCleanupWhenModifiedOnly) { - _VolumeParams.Flags = PostCleanupWhenModifiedOnly ? VolumeParams.PostCleanupWhenModifiedOnly : 0; + _VolumeParams.Flags |= PostCleanupWhenModifiedOnly ? VolumeParams.PostCleanupWhenModifiedOnly : 0; } public void SetPassQueryDirectoryPattern(Boolean PassQueryDirectoryPattern) { - _VolumeParams.Flags = PassQueryDirectoryPattern ? VolumeParams.PassQueryDirectoryPattern : 0; + _VolumeParams.Flags |= PassQueryDirectoryPattern ? VolumeParams.PassQueryDirectoryPattern : 0; } public void SetPrefix(String Prefix) { @@ -158,7 +158,7 @@ namespace Fsp Int32 Result; Result = Api.FspFileSystemCreate( _VolumeParams.IsPrefixEmpty() ? "WinFsp.Disk" : "WinFsp.Net", - ref _VolumeParams, ref _FileSystemInterface, out _FileSystem); + ref _VolumeParams, _FileSystemInterface, out _FileSystem); if (0 <= Result) { Api.SetUserContext(_FileSystem, this); @@ -594,10 +594,14 @@ namespace Fsp FileName, out FileAttributes, ref SecurityDescriptorBytes); - if (IntPtr.Zero != PFileAttributes) - Marshal.WriteInt32(PFileAttributes, (Int32)FileAttributes); - return Api.CopySecurityDescriptor(SecurityDescriptorBytes, - SecurityDescriptor, PSecurityDescriptorSize); + if (0 <= Result) + { + if (IntPtr.Zero != PFileAttributes) + Marshal.WriteInt32(PFileAttributes, (Int32)FileAttributes); + Result = Api.CopySecurityDescriptor(SecurityDescriptorBytes, + SecurityDescriptor, PSecurityDescriptorSize); + } + return Result; } catch (Exception ex) { @@ -1187,32 +1191,38 @@ namespace Fsp static FileSystem() { - _FileSystemInterface.GetVolumeInfo = GetVolumeInfo; - _FileSystemInterface.SetVolumeLabel = SetVolumeLabel; - _FileSystemInterface.GetSecurityByName = GetSecurityByName; - _FileSystemInterface.Create = Create; - _FileSystemInterface.Open = Open; - _FileSystemInterface.Overwrite = Overwrite; - _FileSystemInterface.Cleanup = Cleanup; - _FileSystemInterface.Close = Close; - _FileSystemInterface.Read = Read; - _FileSystemInterface.Write = Write; - _FileSystemInterface.Flush = Flush; - _FileSystemInterface.GetFileInfo = GetFileInfo; - _FileSystemInterface.SetBasicInfo = SetBasicInfo; - _FileSystemInterface.SetFileSize = SetFileSize; - _FileSystemInterface.CanDelete = CanDelete; - _FileSystemInterface.Rename = Rename; - _FileSystemInterface.GetSecurity = GetSecurity; - _FileSystemInterface.SetSecurity = SetSecurity; - _FileSystemInterface.ReadDirectory = ReadDirectory; - _FileSystemInterface.ResolveReparsePoints = ResolveReparsePoints; - _FileSystemInterface.GetReparsePoint = GetReparsePoint; - _FileSystemInterface.SetReparsePoint = SetReparsePoint; - _FileSystemInterface.DeleteReparsePoint = DeleteReparsePoint; + FileSystemInterface FileSystemInterface; + FileSystemInterface = default(FileSystemInterface); + FileSystemInterface.GetVolumeInfo = GetVolumeInfo; + FileSystemInterface.SetVolumeLabel = SetVolumeLabel; + FileSystemInterface.GetSecurityByName = GetSecurityByName; + FileSystemInterface.Create = Create; + FileSystemInterface.Open = Open; + FileSystemInterface.Overwrite = Overwrite; + FileSystemInterface.Cleanup = Cleanup; + FileSystemInterface.Close = Close; + FileSystemInterface.Read = Read; + FileSystemInterface.Write = Write; + FileSystemInterface.Flush = Flush; + FileSystemInterface.GetFileInfo = GetFileInfo; + FileSystemInterface.SetBasicInfo = SetBasicInfo; + FileSystemInterface.SetFileSize = SetFileSize; + FileSystemInterface.CanDelete = CanDelete; + FileSystemInterface.Rename = Rename; + FileSystemInterface.GetSecurity = GetSecurity; + FileSystemInterface.SetSecurity = SetSecurity; + FileSystemInterface.ReadDirectory = ReadDirectory; + FileSystemInterface.ResolveReparsePoints = ResolveReparsePoints; + 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 IntPtr _FileSystem; } diff --git a/src/dotnet/Interop.cs b/src/dotnet/Interop.cs index 1e0aa909..e9096b65 100644 --- a/src/dotnet/Interop.cs +++ b/src/dotnet/Interop.cs @@ -64,7 +64,7 @@ namespace Fsp.Interop { fixed (UInt16 *P = Prefix) { - int Size = Value.Length; + int Size = null != Value ? Value.Length : 0; if (Size > PrefixSize - 1) Size = PrefixSize - 1; for (int I = 0; Size > I; I++) @@ -76,7 +76,7 @@ namespace Fsp.Interop { fixed (UInt16 *P = FileSystemName) { - int Size = Value.Length; + int Size = null != Value ? Value.Length : 0; if (Size > FileSystemNameSize - 1) Size = FileSystemNameSize - 1; for (int I = 0; Size > I; I++) @@ -105,7 +105,7 @@ namespace Fsp.Interop { fixed (UInt16 *P = VolumeLabel) { - int Size = Value.Length; + int Size = null != Value ? Value.Length : 0; if (Size > VolumeLabelSize) Size = VolumeLabelSize; for (int I = 0; Size > I; I++) @@ -153,6 +153,7 @@ namespace Fsp.Interop internal struct DirInfo { internal const int FileNameBufSize = 255; + internal static int FileNameBufOffset = (int)Marshal.OffsetOf(typeof(DirInfo), "FileNameBuf"); internal UInt16 Size; internal FileInfo FileInfo; @@ -164,12 +165,12 @@ namespace Fsp.Interop { fixed (UInt16 *P = FileNameBuf) { - int Size = Value.Length; + int Size = null != Value ? Value.Length : 0; if (Size > FileNameBufSize) Size = FileNameBufSize; for (int I = 0; Size > I; 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.SetReparsePoint SetReparsePoint; internal Proto.DeleteReparsePoint DeleteReparsePoint; - internal Proto.DeleteReparsePoint GetStreamInfo; + internal Proto.GetStreamInfo GetStreamInfo; internal unsafe fixed long/*IntPtr*/ Reserved[40]; /* NTSTATUS (*Reserved[40])(); */ } @@ -415,7 +416,7 @@ namespace Fsp.Interop internal delegate Int32 FspFileSystemCreate( [MarshalAs(UnmanagedType.LPWStr)] String DevicePath, ref VolumeParams VolumeParams, - ref FileSystemInterface Interface, + IntPtr Interface, out IntPtr PFileSystem); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] internal delegate void FspFileSystemDelete( @@ -847,6 +848,10 @@ namespace Fsp.Interop } static Api() { +#if DEBUG + if (Debugger.IsAttached) + Debugger.Break(); +#endif LoadProto(LoadDll()); }