You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using GetFileInformationByHandleEx to query the FILE_ID_INFO of a file, the returned FILE_ID_INFO reports the incorrect File ID if you use the Identifier getter of the FILE_ID_128 member.
This is a code sample from a command line exe that will report the File ID of a given file.
if(args.Length!=1){Console.WriteLine("No file path provided");return;}stringfileName=args[0];varfHandle=CreateFile(fileName,FileAccess.FILE_GENERIC_READ,FileShare.None,null,FileMode.Open,0,IntPtr.Zero);varfileIdInfo=GetFileInformationByHandleEx<FILE_ID_INFO>(fHandle,FILE_INFO_BY_HANDLE_CLASS.FileIdInfo);Console.WriteLine("File ID: {0}",string.Join(", ",fileIdInfo.FileId.Identifier));Console.WriteLine("Volume Serial Number: {0}",fileIdInfo.VolumeSerialNumber);
In a debugger the private members id0 and id1, which represent the low and high bits of the 128 bit identifier, are set as expected. These values are correct for the File ID of the file in question.
But Identifier is showing that the high bits (id1) have values other than 0.
/// <summary>/// <para>Defines a 128-bit file identifier.</para>/// </summary>// https://docs.microsoft.com/en-us/windows/desktop/api/winnt/ns-winnt-_file_id_128 typedef struct _FILE_ID_128 { BYTE// Identifier[16]; } FILE_ID_128, *PFILE_ID_128;[PInvokeData("winnt.h",MSDNShortId="254ea6a9-e1dd-4b97-91f7-2693065c4bb8")][StructLayout(LayoutKind.Sequential)]publicstructFILE_ID_128{privatereadonlyulongid0;privatereadonlyulongid1;/// <summary>/// <para>A byte array containing the 128 bit identifier.</para>/// </summary>publicbyte[]Identifier{get{usingPinnedObjectpin=new(id0);return((IntPtr)pin).ToArray<byte>(16);}set{usingPinnedObjectpin=new(id0);Marshal.Copy(value,0,pin,16);}}}
Expected behavior
The value returned by FILE_ID_128.Identifier should be an array of 16 bytes, where the first 8 are the byte representation of id0 and the later 8 bytes are the byte representation of id1.
The text was updated successfully, but these errors were encountered:
Describe the bug and how to reproduce
When using
GetFileInformationByHandleEx
to query theFILE_ID_INFO
of a file, the returnedFILE_ID_INFO
reports the incorrect File ID if you use theIdentifier
getter of theFILE_ID_128
member.This is a code sample from a command line exe that will report the File ID of a given file.
In a debugger the private members
![image](https://private-user-images.githubusercontent.com/100410746/268053859-76d4847e-6352-4b52-ab05-8260af82804a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MDA2MzgsIm5iZiI6MTczOTYwMDMzOCwicGF0aCI6Ii8xMDA0MTA3NDYvMjY4MDUzODU5LTc2ZDQ4NDdlLTYzNTItNGI1Mi1hYjA1LTgyNjBhZjgyODA0YS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjE1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxNVQwNjE4NThaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0zMzc4YmU3YWQxODgxYjY1NjViYWUzOWNhNjQ1MWQ0ODk3ODdjNDc2N2ZmNDI0NmQwMmQ0OTRlNjBhMzY1ZTQ3JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.VL2Mhu8KBTOi9hsnBGHOCrst8AjvBTiMkpDOFweO_pE)
id0
andid1
, which represent the low and high bits of the 128 bit identifier, are set as expected. These values are correct for the File ID of the file in question.But
Identifier
is showing that the high bits (id1
) have values other than 0.What code is involved
Vanara.PInvoke.Kernel32.FILE_ID_128.Identifier
getter.Expected behavior
The value returned by
FILE_ID_128.Identifier
should be an array of 16 bytes, where the first 8 are the byte representation ofid0
and the later 8 bytes are the byte representation ofid1
.The text was updated successfully, but these errors were encountered: