阅读:3086回复:12
如何强行Umount一个Filedisk加载的虚拟磁盘
我将filedisk.exe中Umount函数中的
// if (!DeviceIoControl( // Device, // FSCTL_LOCK_VOLUME, // NULL, // 0, // NULL, // 0, // &BytesReturned, // NULL // )) // { // PrintLastError(&VolumeName[4]); // return -1; // } 和 // if (!DeviceIoControl( // Device, // FSCTL_UNLOCK_VOLUME, // NULL, // 0, // NULL, // 0, // &BytesReturned, // NULL // )) // { // PrintLastError(&VolumeName[4]); // return -1; // } 去掉,可以强行Umount,但是再新建一个disk.img文件,格式化是选取消,在Umount是就提示拒绝访问了。 |
|
沙发#
发布于:2005-02-01 13:21
如果格式化时选择进行了格式化,那么还是可以使用的,并且一切正常,但是如果放弃格式化,就会提示拒绝访问,是不是有什么没有释放啊?
|
|
驱动老牛
![]() |
板凳#
发布于:2005-02-01 13:40
是filedisk.exe的问题,如果磁盘不可用,filedisk.exe根本就走不到UMOUNT就退出了。
|
|
地板#
发布于:2005-02-01 14:33
是啊,所以我把那两个函数注释了(见帖1),可以强行Umount了(Winamp正在放里面的Mp3呢),但是这时你再新建一个虚拟磁盘(不是刚才的那个了,新建了一个文件)后,如果格式化时选择进行了格式化,那么还是可以使用的,并且一切正常,但是如果放弃格式化,就会提示拒绝访问。
|
|
地下室#
发布于:2005-02-01 14:53
发现跟格式化没关,就是强行Umount后,新建一个虚拟磁盘,就不能Umount了,除非把它格式化了,要不就提示拒绝访问
|
|
5楼#
发布于:2005-02-01 22:05
FSCTL_DISMOUNT_VOLUME
The FSCTL_DISMOUNT_VOLUME control code dismounts a volume. To perform this operation, call the DeviceIoControl function with the following parameters. BOOL DeviceIoControl( (HANDLE) hDevice, // handle to volume FSCTL_DISMOUNT_VOLUME, // dwIoControlCode NULL, // lpInBuffer 0, // nInBufferSize NULL, // lpOutBuffer 0, // nOutBufferSize (LPDWORD) lpBytesReturned, // number of bytes returned (LPOVERLAPPED) lpOverlapped // OVERLAPPED structure ); Parameters hDevice [in] Handle to the volume to be dismounted. To retrieve a handle, call the CreateFile function. dwIoControlCode [in] Control code for the operation. Use FSCTL_DISMOUNT_VOLUME for this operation. lpInBuffer Not used with this operation; set to NULL. nInBufferSize Not used with this operation; set to zero. lpOutBuffer Not used with this operation; set to NULL. nOutBufferSize Not used with this operation; set to zero. lpBytesReturned [out] Pointer to a variable that receives the size of the data stored in the output buffer, in bytes. If lpOverlapped is NULL, lpBytesReturned cannot be NULL. Even when an operation returns no output data and lpOutBuffer is NULL, DeviceIoControl makes use of lpBytesReturned. After such an operation, the value of lpBytesReturned is meaningless. If lpOverlapped is not NULL, lpBytesReturned can be NULL. If this parameter is not NULL and the operation returns data, lpBytesReturned is meaningless until the overlapped operation has completed. To retrieve the number of bytes returned, call GetOverlappedResult. If hDevice is associated with an I/O completion port, you can retrieve the number of bytes returned by calling GetQueuedCompletionStatus. lpOverlapped [in] Pointer to an OVERLAPPED structure. If hDevice was opened without specifying FILE_FLAG_OVERLAPPED, lpOverlapped is ignored. If hDevice was opened with the FILE_FLAG_OVERLAPPED flag, the operation is performed as an overlapped (asynchronous) operation. In this case, lpOverlapped must point to a valid OVERLAPPED structure that contains a handle to an event object. Otherwise, the function fails in unpredicatable ways. For overlapped operations, DeviceIoControl returns immediately, and the event object is signaled when the operation has been completed. Otherwise, the function does not return until the operation has been completed or an error occurs. Return Values If the operation succeeds, DeviceIoControl returns a nonzero value. If the operation fails, DeviceIoControl returns zero. To get extended error information, call GetLastError. Remarks The hDevice handle passed to DeviceIoControl must be a handle to a volume, opened for direct access. To retrieve a volume handle, call CreateFile with the lpFileName parameter set to a string of the following form: \\.\X: where X is a hard-drive partition letter, floppy disk drive, or CD-ROM drive. The application must also specify the FILE_SHARE_READ and FILE_SHARE_WRITE flags in the dwShareMode parameter of CreateFile. If the specified volume is locked by another process, the operation fails. To prevent another process from locking the volume, lock it as soon as you open it. A dismounted volume has the following properties: There are no open files. The operating system does not "know" about the volume. The operating system tries to mount an unmounted volume as soon as any attempt is made to access it. For example, a call to GetLogicalDrives triggers the operating system to mount any unmounted volumes. Dismounting a volume is useful whenever a volume needs to disappear for a while. For example, an application that changes a volume's file system from FAT to NTFS might follow these steps: Open the volume Lock the volume Format the volume Dismount the volume Unlock the volume Close the volume handle A dismounting operation removes the volume from the FAT file system's "awareness." When the operating system mounts the volume, it appears as an NTFS volume. |
|
|
6楼#
发布于:2005-02-02 08:26
谢谢大家回复,但是我就是想如何才能强行Umount一个磁盘,简单的去掉exe中的FSCTL_LOCK_VOLUME和FSCTL_UNLOCK_VOLUME好像有问题(第一次可以Umount,但是如果新建一个磁盘,这个新建的就无法Umount了),有没有办法强行卸载一个卷,就像format的/x参数(/x参数可以使这个卷上的所有句柄都无效),这样就可以正常关闭了。
|
|
7楼#
发布于:2005-02-02 09:16
为什么要去掉exe中的FSCTL_LOCK_VOLUME和FSCTL_UNLOCK_VOLUME??????
|
|
|
8楼#
发布于:2005-02-02 09:19
因为要实现硬件的绑定,拔下key的时候需要强行关闭
|
|
9楼#
发布于:2007-09-21 13:21
不知为何,我调用 FSCTL_LOCK_VOLUME 总是失败?
|
|
|
10楼#
发布于:2007-09-21 13:22
错误码是5,表示“拒绝访问”。但是我没有打开盘里的任何文件呀。
|
|
|
11楼#
发布于:2007-10-18 11:04
你可以发送强制卸下卷就行了///FSCTL_DISMOUNT_VOLUME,不要删除中间的代码..加上这个就行..
wowocock 老兄,已经告诉你了.... |
|
12楼#
发布于:2007-10-20 04:16
引用第3楼Rendy于2005-02-01 14:33发表的 : Cancel the format operation will cause the the filesystem under NOT-MOUNTED state. Without a doubt, system will throw an access-denied message. |
|
|