dotnet: file change notification support

This commit is contained in:
Bill Zissimopoulos
2020-10-23 13:55:36 -07:00
parent 1b7a78edff
commit 5014e8bd35
2 changed files with 171 additions and 0 deletions

View File

@ -310,6 +310,44 @@ namespace Fsp.Interop
}
}
[StructLayout(LayoutKind.Sequential)]
internal struct NotifyInfoInternal
{
internal const int FileNameBufSize = 1024 * 2/*FSP_FSCTL_TRANSACT_PATH_SIZEMAX*/;
internal static int FileNameBufOffset =
(int)Marshal.OffsetOf(typeof(DirInfo), "FileNameBuf");
internal UInt16 Size;
internal UInt32 Filter;
internal UInt32 Action;
//internal unsafe fixed UInt16 FileNameBuf[];
internal unsafe fixed UInt16 FileNameBuf[FileNameBufSize];
internal unsafe void SetFileNameBuf(String Value)
{
fixed (UInt16 *P = FileNameBuf)
{
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)(FileNameBufOffset + Size * 2);
}
}
}
/// <summary>
/// Contains file change notification information.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct NotifyInfo
{
public String FileName;
public UInt32 Action;
public UInt32 Filter;
}
[StructLayout(LayoutKind.Sequential)]
internal struct FullEaInformation
{
@ -743,6 +781,18 @@ namespace Fsp.Interop
IntPtr FileSystem,
ref FspFsctlTransactRsp Response);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate Int32 FspFileSystemNotifyBegin(
IntPtr FileSystem,
UInt32 Timeout);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate Int32 FspFileSystemNotifyEnd(
IntPtr FileSystem);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate Int32 FspFileSystemNotify(
IntPtr FileSystem,
IntPtr NotifyInfo,
UIntPtr Size);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal unsafe delegate FspFileSystemOperationContext *FspFileSystemGetOperationContext();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate IntPtr FspFileSystemMountPointF(
@ -805,6 +855,13 @@ namespace Fsp.Interop
out UInt32 PBytesTransferred);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.U1)]
internal delegate Boolean FspFileSystemAddNotifyInfo(
IntPtr NotifyInfo,
IntPtr Buffer,
UInt32 Length,
out UInt32 PBytesTransferred);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.U1)]
internal delegate Boolean FspFileSystemAcquireDirectoryBuffer(
ref IntPtr PDirBuffer,
[MarshalAs(UnmanagedType.U1)] Boolean Reset,
@ -930,6 +987,9 @@ namespace Fsp.Interop
internal static Proto.FspFileSystemStartDispatcher FspFileSystemStartDispatcher;
internal static Proto.FspFileSystemStopDispatcher FspFileSystemStopDispatcher;
internal static Proto.FspFileSystemSendResponse FspFileSystemSendResponse;
internal static Proto.FspFileSystemNotifyBegin FspFileSystemNotifyBegin;
internal static Proto.FspFileSystemNotifyEnd FspFileSystemNotifyEnd;
internal static Proto.FspFileSystemNotify _FspFileSystemNotify;
internal static Proto.FspFileSystemGetOperationContext FspFileSystemGetOperationContext;
internal static Proto.FspFileSystemMountPointF FspFileSystemMountPoint;
internal static Proto.FspFileSystemSetOperationGuardStrategyF FspFileSystemSetOperationGuardStrategy;
@ -941,6 +1001,7 @@ namespace Fsp.Interop
internal static Proto.FspFileSystemCanReplaceReparsePoint _FspFileSystemCanReplaceReparsePoint;
internal static Proto.FspFileSystemAddStreamInfo _FspFileSystemAddStreamInfo;
internal static Proto.FspFileSystemAddEa _FspFileSystemAddEa;
internal static Proto.FspFileSystemAddNotifyInfo _FspFileSystemAddNotifyInfo;
internal static Proto.FspFileSystemAcquireDirectoryBuffer FspFileSystemAcquireDirectoryBuffer;
internal static Proto.FspFileSystemFillDirectoryBuffer FspFileSystemFillDirectoryBuffer;
internal static Proto.FspFileSystemReleaseDirectoryBuffer FspFileSystemReleaseDirectoryBuffer;
@ -1013,6 +1074,15 @@ namespace Fsp.Interop
{
return _FspFileSystemAddStreamInfo(IntPtr.Zero, Buffer, Length, out PBytesTransferred);
}
internal static unsafe Boolean FspFileSystemAddNotifyInfo(
ref NotifyInfoInternal NotifyInfo,
IntPtr Buffer,
UInt32 Length,
out UInt32 PBytesTransferred)
{
fixed (NotifyInfoInternal *P = &NotifyInfo)
return _FspFileSystemAddNotifyInfo((IntPtr)P, Buffer, Length, out PBytesTransferred);
}
internal delegate Int32 EnumerateEa(
Object FileNode,
@ -1070,6 +1140,34 @@ namespace Fsp.Interop
return _FspFileSystemAddEa(IntPtr.Zero, Buffer, Length, out PBytesTransferred);
}
internal static unsafe Int32 FspFileSystemNotify(
IntPtr FileSystem,
NotifyInfo[] NotifyInfoArray)
{
int Length = 0;
for (int I = 0; NotifyInfoArray.Length > I; I++)
{
Length = (Length + 7) & ~7; // align to next qword boundary
Length += NotifyInfoInternal.FileNameBufOffset +
NotifyInfoArray[I].FileName.Length * 2;
}
Byte[] Buffer = new Byte[Length];
UInt32 BytesTransferred = default(UInt32);
fixed (Byte *P = Buffer)
{
for (int I = 0; NotifyInfoArray.Length > I; I++)
{
NotifyInfoInternal Internal = default(NotifyInfoInternal);
Internal.Action = NotifyInfoArray[I].Action;
Internal.Filter = NotifyInfoArray[I].Filter;
Internal.SetFileNameBuf(NotifyInfoArray[I].FileName);
FspFileSystemAddNotifyInfo(
ref Internal, (IntPtr)P, (UInt32)Length, out BytesTransferred);
}
return _FspFileSystemNotify(FileSystem, (IntPtr)P, (UIntPtr)BytesTransferred);
}
}
internal unsafe static Object GetUserContext(
IntPtr NativePtr)
{
@ -1330,6 +1428,9 @@ namespace Fsp.Interop
FspFileSystemStartDispatcher = GetEntryPoint<Proto.FspFileSystemStartDispatcher>(Module);
FspFileSystemStopDispatcher = GetEntryPoint<Proto.FspFileSystemStopDispatcher>(Module);
FspFileSystemSendResponse = GetEntryPoint<Proto.FspFileSystemSendResponse>(Module);
FspFileSystemNotifyBegin = GetEntryPoint<Proto.FspFileSystemNotifyBegin>(Module);
FspFileSystemNotifyEnd = GetEntryPoint<Proto.FspFileSystemNotifyEnd>(Module);
_FspFileSystemNotify = GetEntryPoint<Proto.FspFileSystemNotify>(Module);
FspFileSystemGetOperationContext = GetEntryPoint<Proto.FspFileSystemGetOperationContext>(Module);
FspFileSystemMountPoint = GetEntryPoint<Proto.FspFileSystemMountPointF>(Module);
FspFileSystemSetOperationGuardStrategy = GetEntryPoint<Proto.FspFileSystemSetOperationGuardStrategyF>(Module);
@ -1341,6 +1442,7 @@ namespace Fsp.Interop
_FspFileSystemCanReplaceReparsePoint = GetEntryPoint<Proto.FspFileSystemCanReplaceReparsePoint>(Module);
_FspFileSystemAddStreamInfo = GetEntryPoint<Proto.FspFileSystemAddStreamInfo>(Module);
_FspFileSystemAddEa = GetEntryPoint<Proto.FspFileSystemAddEa>(Module);
_FspFileSystemAddNotifyInfo = GetEntryPoint<Proto.FspFileSystemAddNotifyInfo>(Module);
FspFileSystemAcquireDirectoryBuffer = GetEntryPoint<Proto.FspFileSystemAcquireDirectoryBuffer>(Module);
FspFileSystemFillDirectoryBuffer = GetEntryPoint<Proto.FspFileSystemFillDirectoryBuffer>(Module);
FspFileSystemReleaseDirectoryBuffer = GetEntryPoint<Proto.FspFileSystemReleaseDirectoryBuffer>(Module);