Ignore:
Timestamp:
3/19/2012 8:06:33 AM (3 years ago)
Author:
lowjoel
Message:

Forward-port from Eraser 6.0: We need to recursively dereference all reparse points before we call GetVolumeNameForVolumeMountPoint?. This prevents a situation where we we get an invalid parameter error from GetVolumeNameForVolumeMountPoint? when we hand it a reparse point but it is not a volume reparse point.

Fixes bug in https://eraser.heidi.ie/forum/viewtopic.php?f=2&t=8684.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser/Eraser.Util/NativeMethods/Kernel.cs

    r2516 r2549  
    652652        [DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] 
    653653        [return: MarshalAs(UnmanagedType.Bool)] 
    654         public static extern bool DeviceIoControl(SafeFileHandle hDevice, 
     654        public extern static bool DeviceIoControl(SafeFileHandle hDevice, 
    655655            uint dwIoControlCode, IntPtr lpInBuffer, uint nInBufferSize, 
    656656            out NTFS_VOLUME_DATA_BUFFER lpOutBuffer, uint nOutBufferSize, 
     
    764764            /// </summary> 
    765765            public long ExtentLength; 
     766        } 
     767 
     768        public const uint FSCTL_GET_REPARSE_POINT = (9 << 16) | (42 << 2); 
     769 
     770        /// <summary> 
     771        /// The REPARSE_DATA_BUFFER structure contains reparse point data for a 
     772        /// Microsoft reparse point. (Third-party reparse point owners must use 
     773        /// the REPARSE_GUID_DATA_BUFFER structure instead.)  
     774        /// </summary> 
     775        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 
     776        public struct REPARSE_DATA_BUFFER 
     777        { 
     778            /// <summary> 
     779            /// Contains the reparse point information for a Symbolic Link. 
     780            /// </summary> 
     781            /// <remarks>The PathBuffer member found at the end of the C structure 
     782            /// declaration is appended at the end of this structure.</remarks> 
     783            [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 
     784            public struct SymbolicLinkReparseBuffer 
     785            { 
     786                /// <summary> 
     787                /// Offset, in bytes, of the substitute name string in the PathBuffer 
     788                /// array. Note that this offset must be divided by sizeof(char) to 
     789                /// get the array index. 
     790                /// </summary> 
     791                public ushort SubstituteNameOffset; 
     792 
     793                /// <summary> 
     794                /// Length, in bytes, of the substitute name string. If this string is 
     795                /// NULL-terminated, SubstituteNameLength does not include space for 
     796                /// the UNICODE_NULL character. 
     797                /// </summary> 
     798                public ushort SubstituteNameLength; 
     799 
     800                /// <summary> 
     801                /// Offset, in bytes, of the print name string in the PathBuffer array. 
     802                /// Note that this offset must be divided by sizeof(char) to get the 
     803                /// array index. 
     804                /// </summary> 
     805                public ushort PrintNameOffset; 
     806 
     807                /// <summary> 
     808                /// Length, in bytes, of the print name string. If this string is 
     809                /// NULL-terminated, PrintNameLength does not include space for the 
     810                /// UNICODE_NULL character. 
     811                /// </summary> 
     812                public ushort PrintNameLength; 
     813 
     814                /// <summary> 
     815                /// Used to indicate if the given symbolic link is an absolute or relative 
     816                /// symbolic link. If Flags contains SYMLINK_FLAG_RELATIVE, the symbolic 
     817                /// link contained in the PathBuffer array (at offset SubstitueNameOffset) 
     818                /// is processed as a relative symbolic link; otherwise, it is processed 
     819                /// as an absolute symbolic link. 
     820                /// </summary> 
     821                public SymbolicLinkFlags Flags; 
     822            } 
     823 
     824            /// <summary> 
     825            /// Contains the reparse point information for a Directory Junction. 
     826            /// </summary> 
     827            /// <remarks>The PathBuffer member found at the end of the C structure 
     828            /// declaration is appended at the end of this structure.</remarks> 
     829            [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 
     830            public struct MountPointReparseBuffer 
     831            { 
     832                /// <summary> 
     833                /// Offset, in bytes, of the substitute name string in the PathBuffer 
     834                /// array. Note that this offset must be divided by sizeof(char) to 
     835                /// get the array index. 
     836                /// </summary> 
     837                public ushort SubstituteNameOffset; 
     838 
     839                /// <summary> 
     840                /// Length, in bytes, of the substitute name string. If this string is 
     841                /// NULL-terminated, SubstituteNameLength does not include space for 
     842                /// the UNICODE_NULL character. 
     843                /// </summary> 
     844                public ushort SubstituteNameLength; 
     845 
     846                /// <summary> 
     847                /// Offset, in bytes, of the print name string in the PathBuffer array. 
     848                /// Note that this offset must be divided by sizeof(char) to get the 
     849                /// array index. 
     850                /// </summary> 
     851                public ushort PrintNameOffset; 
     852 
     853                /// <summary> 
     854                /// Length, in bytes, of the print name string. If this string is 
     855                /// NULL-terminated, PrintNameLength does not include space for the 
     856                /// UNICODE_NULL character. 
     857                /// </summary> 
     858                public ushort PrintNameLength; 
     859            } 
     860 
     861            [Flags] 
     862            public enum SymbolicLinkFlags 
     863            { 
     864                /// <summary> 
     865                /// <see cref="SymbolicLinkReparseBuffer.Flags"/> 
     866                /// </summary> 
     867                SYMLINK_FLAG_RELATIVE = 0x00000001 
     868            } 
     869 
     870            /// <summary> 
     871            /// Reparse point tag. Must be a Microsoft reparse point tag. (See the following Remarks section.) 
     872            /// </summary> 
     873            public REPARSE_DATA_TAG ReparseTag; 
     874 
     875            /// <summary> 
     876            /// Size, in bytes, of the reparse data in the DataBuffer member. 
     877            /// </summary> 
     878            public ushort ReparseDataLength; 
     879            ushort Reserved; 
     880        } 
     881 
     882        /// <summary> 
     883        /// See http://msdn.microsoft.com/en-us/library/windows/desktop/aa365511%28v=vs.85%29.aspx. 
     884        /// </summary> 
     885        public enum REPARSE_DATA_TAG : uint 
     886        { 
     887            IO_REPARSE_TAG_MOUNT_POINT = 0xA0000003, 
     888            IO_REPARSE_TAG_HSM = 0xC0000004, 
     889            IO_REPARSE_TAG_HSM2 = 0x80000006, 
     890            IO_REPARSE_TAG_SIS = 0x80000007, 
     891            IO_REPARSE_TAG_WIM = 0x80000008, 
     892            IO_REPARSE_TAG_CSV = 0x80000009, 
     893            IO_REPARSE_TAG_DFS = 0x8000000A, 
     894            IO_REPARSE_TAG_SYMLINK = 0xA000000C, 
     895            IO_REPARSE_TAG_DFSR = 0x80000012 
    766896        } 
    767897 
Note: See TracChangeset for help on using the changeset viewer.