I'm writing a program that performs a directory sorting function, but I'm having problems locking a volume for reading/writing under winNT/2K. I can make it work under win95/98 by manipulating \\.\vwin32.vxd and it seems that the 3 level of locks all work with or without open files on the volume being locked. However in winNT/2K if there are open files, locking fails. I wonder how some programs like the disk Defragmenter does with direct disk access with open files. Is there a way to tweak the arguments to DeviceIOControl function a little bit to make it work? (It
seems winNT/2K provides only one level of locking?) Or is there another way to do direct disk access without using lock?? Here is the main part of my program:// open volume, OK
m_hDeviceIO = CreateFile (szVolumeName, dwAccessFlags,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0,
NULL);
// lock volume, fails
DeviceIoControl (m_hDeviceIO, FSCTL_LOCK_VOLUME, NULL, 0, NULL,
0, &dwBytesReturned, NULL); Any answers/comments are welcome. Thanx!
seems winNT/2K provides only one level of locking?) Or is there another way to do direct disk access without using lock?? Here is the main part of my program:// open volume, OK
m_hDeviceIO = CreateFile (szVolumeName, dwAccessFlags,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0,
NULL);
// lock volume, fails
DeviceIoControl (m_hDeviceIO, FSCTL_LOCK_VOLUME, NULL, 0, NULL,
0, &dwBytesReturned, NULL); Any answers/comments are welcome. Thanx!
NT里不能用\\.\vwin32.vxd 来打开硬盘。
NT里用 CreateFile("\\\\.\\C:",.....)打开的硬盘应该是无条件可读写的。
DeviceIoControl (m_hDeviceIO, FSCTL_LOCK_VOLUME, NULL, 0, NULL,
0, &dwBytesReturned, NULL);
来锁当前硬盘时,该操作会失败,而在WIN98下的\\.\vwin32.vxd 方式就不会,因为它有三个级别可以选