// winioctl.h
// CTL_CODE(0x0009, 0x008, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define FSCTL_DISMOUNT_VOLUME 0x00090020
View the official Win32 API reference// ntifs.h
// CTL_CODE(0x0009, 0x008, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define FSCTL_DISMOUNT_VOLUME 0x00090020
View the official Windows hardware development documentationNo description available.
Dismounts a volume regardless of whether or not the volume is currently in use. For more information, see the Remarks section.
To perform this operation, call the DeviceIoControl function with the following parameters.
| C++ |
|---|
BOOL DeviceIoControl( (HANDLE) hDevice, // handle to a volume (DWORD) FSCTL_DISMOUNT_VOLUME, // dwIoControlCodeNULL, // lpInBuffer0, // nInBufferSizeNULL, // lpOutBuffer0, // nOutBufferSize(LPDWORD) lpBytesReturned, // number of bytes returned (LPOVERLAPPED) lpOverlapped // OVERLAPPED structure ); |
Irp->IoStatus.Status is set to STATUS_SUCCESS if the request is successful.
Otherwise, Status to the appropriate error condition as a NTSTATUS code.
For more information, see NTSTATUS Values.
The FSCTL_DISMOUNT_VOLUME control code will attempt to dismount a volume regardless of whether or not any other processes are using the volume, which can have unpredictable results for those processes if they do not hold a lock on the volume. For information about locking a volume, see FSCTL_LOCK_VOLUME.
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 a system volume or contains a page file, the operation fails.
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:
The operating system tries to mount an unmounted volume as soon as an attempt is made to access it. For example, a call to GetLogicalDrives triggers the operating system to mount unmounted volumes.
Dismounting a volume is useful when a volume needs to disappear for a while. For example, an application that changes a volume file system from the FAT file system to the NTFS file system might use the following procedure.
To change a volume file system
A dismounting operation removes the volume from the FAT file system awareness. When the operating system mounts the volume, it appears as an NTFS file system volume.
In Windows 8 and Windows Server 2012, this code is supported by the following technologies.
| Technology | Supported |
|---|---|
| Server Message Block (SMB) 3.0 protocol | No |
| SMB 3.0 Transparent Failover (TFO) | No |
| SMB 3.0 with Scale-out File Shares (SO) | No |
| Cluster Shared Volume File System (CsvFS) | See comment |
On CsvFs the node where dismount is issued will see a normal dismount sequence. On all other nodes FS will invalidate all the opened files.
Volume Management Control Codes
The FSCTL_DISMOUNT_VOLUME control code attempts to dismount a volume regardless of whether the volume is in use.
To perform this operation, call FltFsControlFile or ZwFsControlFile with the following parameters.
Instance [in]: FltFsControlFile only. Opaque instance pointer for the caller. This parameter is required and cannot be NULL.
FileObject: [in]: FltFsControlFile only. The file pointer object specifying the volume to be dismounted. This parameter is required and cannot be NULL.
FileHandle [in]: ZwFsControlFile only. The file handle of the volume to be dismounted. This parameter is required and cannot be NULL.
FsControlCode [in]: Control code for the operation. Use FSCTL_DISMOUNT_VOLUME for this operation.
InputBuffer [in]: None. Set to NULL.
InputBufferLength [in]: Set to 0.
OutputBuffer [out]: None. Set to NULL.
OutputBufferLength [out]: Set to 0.
FltFsControlFile or ZwFsControlFile returns STATUS_SUCCESS or an appropriate NTSTATUS value.
The FSCTL_DISMOUNT_VOLUME control code will attempt to dismount a volume regardless of whether any other processes are using the volume, which can have unpredictable results for those processes if they do not hold a lock on the volume. For information about locking a volume, see FSCTL_LOCK_VOLUME.
The operating system does not detect unmounted volumes. If an attempt is made to access an unmounted volume, the operating system then tries to mount the volume. For example, a call to GetLogicalDrives triggers the operating system to mount unmounted volumes.
The FileHandle handle passed to ZwFsControlFile must be a handle to a volume, opened for direct access. To retrieve a volume handle, call ZwCreateFile with the ObjectAttributes parameter set to an ObjectName of the following form: \\.\X: where X is a drive letter of the volume, floppy disk drive, or CD-ROM drive. The application must also specify the FILE_SHARE_READ and FILE_SHARE_WRITE flags in the ShareAccess parameter of ZwCreateFile.
If the specified volume is a system volume or contains a page file, the operation fails.
If the specified volume is locked by another process, the operation fails.
| Requirement type | Requirement |
|---|---|
| Header | Ntifs.h (include Ntifs.h or Fltkernel.h) |