Udostępnij za pośrednictwem


Junction Structures/Classes

Following are the classes I had to create for use in working with junctions:

 

[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)]
private class REPARSE_MOUNTPOINT_DATA_BUFFER
{
    [FieldOffset(0)]
    internal uint ReparseTag;
    [FieldOffset(4)]
    internal uint ReparseDataLength;
    [FieldOffset(8)]
    internal ushort Reserved;
    [FieldOffset(10)]
    internal ushort ReparseTargetLength;
    [FieldOffset(12)]
    internal ushort ReparseTargetMaximumLength;
    [FieldOffset(14)]
    internal ushort Reserved1;
    [FieldOffset(16)]
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_PATH * 3)]
    internal Char[] ReparseTarget = new Char[MAX_PATH * 3];
}

/// <summary>
/// REPARSE_DATA_BUFFER class
/// </summary>
[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)]
private class REPARSE_DATA_BUFFER
{
    [FieldOffset(0)]
    internal UInt32 ReparseTag;
    [FieldOffset(4)]
    internal ushort ReparseDataLength;
    [FieldOffset(6)]
    internal ushort Reserved;
    [FieldOffset(8)]
    internal ushort SSubstituteNameOffset;
    [FieldOffset(10)]
    internal ushort SSubstituteNameLength;
    [FieldOffset(12)]
    internal ushort SPrintNameOffset;
    [FieldOffset(14)]
    internal ushort SPrintNameLength;
    [FieldOffset(16)]
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_PATH)]
    internal Char[] SPathBuffer = new Char[MAX_PATH];
    [FieldOffset(8)]
    internal ushort MSubstituteNameOffset;
    [FieldOffset(10)]
    internal ushort MSubstituteNameLength;
    [FieldOffset(12)]
    internal ushort MPrintNameOffset;
    [FieldOffset(14)]
    internal ushort MPrintNameLength;
    [FieldOffset(16)]
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_PATH)]
    internal Char[] MPathBuffer = new Char[MAX_PATH];
}

/// <summary>
/// Class for GUID
/// </summary>
[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)]
private class aGUID
{
    [FieldOffset(0)]
    internal uint  Data1;
    [FieldOffset(4)]
    internal ushort Data2;
    [FieldOffset(6)]
    internal ushort Data3;
    [FieldOffset(8)]
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
    internal Char[] Data4 = new Char[8];
}

/// <summary>
/// From WINNT.H
/// The reparse GUID structure is used by all 3rd party layered drivers to
/// store data in a reparse point. For non-Microsoft tags, The GUID field
/// cannot be GUID_NULL.
/// The constraints on reparse tags are defined below.
/// Microsoft tags can also be used with this format of the reparse point buffer.
/// </summary>
[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)]
private class REPARSE_GUID_DATA_BUFFER
{
    [FieldOffset(0)]
    internal UInt32  ReparseTag;
    [FieldOffset(4)]
    internal ushort ReparseDataLength;
    [FieldOffset(6)]
    internal ushort Reserved;
    [FieldOffset(8)]
    internal aGUID  ReparseGuid;
    [FieldOffset(24)]
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_REPARSE_SIZE)]
    internal Char[] DataBuffer = new Char[MAX_REPARSE_SIZE];
}

In my next blog entry I will post some code that shows how to use all this to create, delete, and interrogate junctions.

Comments