Hi,
we are experiencing some strange behavior when trying to get the cluster
bitmap of a locked NTFS volume in W2K/XP (did not test NT4). In order to
retrieve a consistent bitmap, we lock the volume prior to sending the
FSCTL_GET_VOLUME_BITMAP control code like so (error handling removed):
hVolume = CreateFile(
szVolumeName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL
);
DeviceIoControl(
hVolume,
FSCTL_LOCK_VOLUME,
NULL, 0,
NULL, 0,
&dwBytesReturned,
NULL
);
This all succeeds and I can then successfully send
FSCTL_GET_VOLUME_BITMAP for FAT volumes. However, it fails for NTFS
volumes with GetLastError() == ERROR_NOT_READY. The docs suggest that “a
return value from GetLastError of ERROR_NOT_READY indicates that the
volume is an NTFS volume, and it is not mounted”. But the volume is
obviously still happily mounted because I never issued a
FSCTL_DISMOUNT_VOLUME and can successfully read from the handle via
ReadFile().
Eventually it turns out that when I set dwShareMode in CreateFile() to
zero (no sharing), then FSCTL_GET_VOLUME_BITMAP succeeds for the locked
NTFS volume (and also still does for FAT).
Can anybody explain why it is like that?
Also, I’m quite confused by the following statements at the end of the
Remarks section for FSCTL_GET_VOLUME_BITMAP in the PSDK:
This operation aligns the bitmap it returns on a page boundary.
Windows XP: This operation aligns the bitmap it returns on a byte
boundary.
What does that mean? To be compatible with NT4/W2K/XP, do I need to make
sure that the output buffer I’m supplying to DeviceIoControl() is
aligned at a page boundary?
Thanks!