Rendy
驱动牛犊
驱动牛犊
  • 注册日期2003-07-10
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分71分
  • 威望8点
  • 贡献值0点
  • 好评度6点
  • 原创分0分
  • 专家分0分
阅读:3088回复:12

如何强行Umount一个Filedisk加载的虚拟磁盘

楼主#
更多 发布于:2005-02-01 13:17
我将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是就提示拒绝访问了。
bellkwong
驱动牛犊
驱动牛犊
  • 注册日期2003-04-21
  • 最后登录2009-07-30
  • 粉丝0
  • 关注0
  • 积分150分
  • 威望15点
  • 贡献值0点
  • 好评度15点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2007-10-20 04:16
引用第3楼Rendy于2005-02-01 14:33发表的  :
是啊,所以我把那两个函数注释了(见帖1),可以强行Umount了(Winamp正在放里面的Mp3呢),但是这时你再新建一个虚拟磁盘(不是刚才的那个了,新建了一个文件)后,如果格式化时选择进行了格式化,那么还是可以使用的,并且一切正常,但是如果放弃格式化,就会提示拒绝访问。


Cancel the format operation will cause the the filesystem under NOT-MOUNTED state. Without a doubt, system will throw an access-denied message.
Keep the dream in mind.
sc_wolf
驱动小牛
驱动小牛
  • 注册日期2006-09-03
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分35分
  • 威望278点
  • 贡献值1点
  • 好评度150点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2007-10-18 11:04
你可以发送强制卸下卷就行了///FSCTL_DISMOUNT_VOLUME,不要删除中间的代码..加上这个就行..

wowocock 老兄,已经告诉你了....
linfeng1216
驱动小牛
驱动小牛
  • 注册日期2004-03-10
  • 最后登录2008-12-31
  • 粉丝0
  • 关注0
  • 积分818分
  • 威望89点
  • 贡献值0点
  • 好评度74点
  • 原创分0分
  • 专家分0分
地板#
发布于:2007-09-21 13:22
错误码是5,表示“拒绝访问”。但是我没有打开盘里的任何文件呀。
这件事很难
linfeng1216
驱动小牛
驱动小牛
  • 注册日期2004-03-10
  • 最后登录2008-12-31
  • 粉丝0
  • 关注0
  • 积分818分
  • 威望89点
  • 贡献值0点
  • 好评度74点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2007-09-21 13:21
不知为何,我调用 FSCTL_LOCK_VOLUME 总是失败?
这件事很难
Rendy
驱动牛犊
驱动牛犊
  • 注册日期2003-07-10
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分71分
  • 威望8点
  • 贡献值0点
  • 好评度6点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2005-02-02 09:19
因为要实现硬件的绑定,拔下key的时候需要强行关闭
wowocock
VIP专家组
VIP专家组
  • 注册日期2002-04-08
  • 最后登录2016-01-09
  • 粉丝16
  • 关注2
  • 积分601分
  • 威望1651点
  • 贡献值1点
  • 好评度1227点
  • 原创分1分
  • 专家分0分
6楼#
发布于:2005-02-02 09:16
为什么要去掉exe中的FSCTL_LOCK_VOLUME和FSCTL_UNLOCK_VOLUME??????
花开了,然后又会凋零,星星是璀璨的,可那光芒也会消失。在这样 一瞬间,人降生了,笑者,哭着,战斗,伤害,喜悦,悲伤憎恶,爱。一切都只是刹那间的邂逅,而最后都要归入死亡的永眠
Rendy
驱动牛犊
驱动牛犊
  • 注册日期2003-07-10
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分71分
  • 威望8点
  • 贡献值0点
  • 好评度6点
  • 原创分0分
  • 专家分0分
7楼#
发布于:2005-02-02 08:26
谢谢大家回复,但是我就是想如何才能强行Umount一个磁盘,简单的去掉exe中的FSCTL_LOCK_VOLUME和FSCTL_UNLOCK_VOLUME好像有问题(第一次可以Umount,但是如果新建一个磁盘,这个新建的就无法Umount了),有没有办法强行卸载一个卷,就像format的/x参数(/x参数可以使这个卷上的所有句柄都无效),这样就可以正常关闭了。
wowocock
VIP专家组
VIP专家组
  • 注册日期2002-04-08
  • 最后登录2016-01-09
  • 粉丝16
  • 关注2
  • 积分601分
  • 威望1651点
  • 贡献值1点
  • 好评度1227点
  • 原创分1分
  • 专家分0分
8楼#
发布于: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.

花开了,然后又会凋零,星星是璀璨的,可那光芒也会消失。在这样 一瞬间,人降生了,笑者,哭着,战斗,伤害,喜悦,悲伤憎恶,爱。一切都只是刹那间的邂逅,而最后都要归入死亡的永眠
Rendy
驱动牛犊
驱动牛犊
  • 注册日期2003-07-10
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分71分
  • 威望8点
  • 贡献值0点
  • 好评度6点
  • 原创分0分
  • 专家分0分
9楼#
发布于:2005-02-01 14:53
发现跟格式化没关,就是强行Umount后,新建一个虚拟磁盘,就不能Umount了,除非把它格式化了,要不就提示拒绝访问
Rendy
驱动牛犊
驱动牛犊
  • 注册日期2003-07-10
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分71分
  • 威望8点
  • 贡献值0点
  • 好评度6点
  • 原创分0分
  • 专家分0分
10楼#
发布于:2005-02-01 14:33
是啊,所以我把那两个函数注释了(见帖1),可以强行Umount了(Winamp正在放里面的Mp3呢),但是这时你再新建一个虚拟磁盘(不是刚才的那个了,新建了一个文件)后,如果格式化时选择进行了格式化,那么还是可以使用的,并且一切正常,但是如果放弃格式化,就会提示拒绝访问。
zhangshengyu
驱动老牛
驱动老牛
  • 注册日期2003-10-03
  • 最后登录2016-07-26
  • 粉丝0
  • 关注0
  • 积分792分
  • 威望696点
  • 贡献值41点
  • 好评度499点
  • 原创分0分
  • 专家分0分
  • 社区居民
11楼#
发布于:2005-02-01 13:40
是filedisk.exe的问题,如果磁盘不可用,filedisk.exe根本就走不到UMOUNT就退出了。
---内核开发合作或提供基础技术服务QQ:22863668 ---
Rendy
驱动牛犊
驱动牛犊
  • 注册日期2003-07-10
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分71分
  • 威望8点
  • 贡献值0点
  • 好评度6点
  • 原创分0分
  • 专家分0分
12楼#
发布于:2005-02-01 13:21
如果格式化时选择进行了格式化,那么还是可以使用的,并且一切正常,但是如果放弃格式化,就会提示拒绝访问,是不是有什么没有释放啊?
游客

返回顶部