Recently I've stumbled upon "If you want to use GUIDs to identify your files, then nobody's stopping you" article by Raymond Chen and wanted to implement this method. But then I found that there is another way to get file ID and this is GetFileInformationByHandleEx
with FILE_INFO_BY_HANDLE_CLASS::FileIdInfo
and using the FileId
field (128 bit).
I tried both, both methods works as expected but I have a few questions I cannot find any answers to:
- These methods return different IDs (and the id from
GetFileInformationByHandleEx
seems to use only the low 64 bit leaving the high part as zero). What each of them represent? Are they essentially the same thing or just two independent mechanisms to achieve the same goal?- Edit: Actually I've just found some information. So the ObjectID from
DeviceIoControl
is NTFS object ID but what is the other ID then? How do they relate (if at all)? Are both methods available only on NTFS or at least one of them will work on FAT16/32, exFAT, etc?
- Edit: Actually I've just found some information. So the ObjectID from
- Documentation for
FILE_INFO_BY_HANDLE_CLASS::FileIdInfo
doesn't tell us that the ID may not exist unlikeFSCTL_CREATE_OR_GET_OBJECT_ID
where I need to explicitly state that I want the ID to be created if there isn't one already. Will it have any bad consequences if I'd just blindly request creation of object IDs for any file I'll be working with? - I found a comment for this question that these IDs remain unchanged if a file is moved to another volume (logical or physical). I did test only the
DeviceIoControl
method but they indeed don't chnage across drives but if I do move the file I'm required to supplyOpenFileById
with the destination volume handle, otherwise it won't open the file. So, is there a way to makeOpenFileById
find a file without keeping the volume reference?- I'm thinking of enumerating all connected volumes to try to open the file by ID for each until it succeed but I'm not sure how reliable is this. Could it be that there could exist two equal IDs that reference different files on different volumes?
- How fast it is to ask system to get (or create) an ID? Will it hurt performance if I add the ID query to regular file enumeration procedures or I'd better to do that only on demand when I really need this?