Before doing a USN journal / NTFS MFT files-enumeration with
while (DeviceIoControl(hDrive, FSCTL_ENUM_USN_DATA, &med, sizeof(med), pData, sizeof(pData), &cb, NULL))
{
// do stuff here
med.StartFileReferenceNumber = *((DWORDLONG*) pData); // pData contains FRN for next FSCTL_ENUM_USN_DATA
}
I'd like to know the number of files/directories (to "reserve" a std::vector: v.reserve(...)
and also other reasons).
I thought about using FSCTL_QUERY_USN_JOURNAL
before, that gives a USN_JOURNAL_DATA_V0
containing informations about the volume.
Unfortnuately FirstUsn
, NextUsn
, MaxUsn
don't give this information. Even if I have 100k files on the volume, NextUsn
can be 10 millions for example, so it doesn't give the right order of magnitude.
How to get the number of files / directories before doing a FSCTL_ENUM_USN_DATA?
opendir/readdir/closedir
what you are looking for? – ImpeachmentFSCTL_GET_NTFS_FILE_RECORD
in binary search adjustFileReferenceNumber
- this give the highest validFileReferenceNumber
after several iterations. the same value is returned inFSCTL_ENUM_USN_DATA
when we reach end of enum. but this value bit more than actual number of files. for example in my test on some volume i getf800
as this number. and count of files byFSCTL_ENUM_USN_DATA
i gotd81b
, while by enumerating viaFSCTL_GET_NTFS_FILE_RECORD
-d830
– Polyandrystd::vector<wstring>
or even avector<pair<wstring, DWORDLONG>>
to store filename + parentID. That's why I need to reserve in order to reallocate this vector as least as possible. What do you call a moderately buffer (of what?) in this context? Thanks! – IolentapData
in your code. The size of that buffer determines how many entries you can receive in a single call to DeviceIoControl. Before copying the data frompData
into your vector, count the number of entries in the buffer, that way you only need to resize the vector once per call. – Pallbeareropendir/readdir/closedir
is not an answer to any Windows development question. – Fung