共用方式為


Programmatically Dismount Volumes (Standard 7 SP1)

7/8/2014

To create an unprotected volume in a Hibernate Once/Resume Many (HORM) environment, you must lock and dismount the volume before you create the hibernation file.

To lock and dismount a volume, you must create an application that calls the DeviceIoControl function. This function sends control codes directly to the file system. By passing the parameters FSCTL_LOCK_VOLUME and FSCTL_DISMOUNT_VOLUME to the function, you can lock and dismount the volume before the hibernation file is created.

Use the following program flow to lock and dismount a volume, and then let the system hibernate. The application must also support unlocking the volume when the system starts from the hibernation file.

To programmatically dismount volumes

  1. Create an application to lock and dismount a volume you do not want protected by Enhanced Write Filter (EWF). Use the DeviceIoControl function by using the dwIoControlCode parameter FS_LOCK_VOLUME. This locks the volume. If there is an open file handle to the volume when this function is called, the volume does not lock. By locking the volume before you dismount it, you can make sure that the volume is dismounted cleanly. For example, call the DeviceIoControl function by using the following values:

    DeviceIoControl(
         hDevice,
         FSCTL_LOCK_VOLUME,
         NULL,
         0,
         NULL,
         0,
         &cbReturned,
         NULL
         )
    

    For more information about DeviceIoControl, see this Microsoft Web site.

    For more information about FSCTL_LOCK_VOLUME, see this Microsoft Web site.

  2. After the volume is locked, the volume can be dismounted. In your application, call the DeviceIoControl function by using the dwIoControlCode parameter FSCTL_DISMOUNT_VOLUME to dismount the volume. This parameter dismounts the volume from the file system. If you do not lock the volume before you dismount it, any open file handles are invalidated and the volume forcibly dismounts.

    After the volume is dismounted, any information in the write cache about the volume is flushed, and you can safely write the hibernation file.

    For example, call the DeviceIoControl function by using the following values:

    DeviceIoControl(
         hDevice,
         FSCTL_DISMOUNT_VOLUME,
         NULL,
         0,
         NULL,
         0,
         &cbReturned,
         NULL
         )
    
  3. After the volume is dismounted, create the hibernation file and shut down the system by using the SetSuspendState function.

    SetSuspendState ( 
         Hibernate,
         ForceCritical,
         DisableWakeEvent ) 
    

    For more information about the SetSuspendState function, see this Microsoft Web site.

  4. After the system hibernates, start the system. The system resumes from the hibernation file.

  5. To enable the system to rediscover the volume, the volume first must be unlocked immediately after the system starts. Use the DeviceIoControl function by using the dwIoControlCode parameter FS_UNLOCK_VOLUME. This unlocks the volume.

    DeviceIoControl(
         hDevice,
         FSCTL_UNLOCK_VOLUME,
         NULL,
         0,
         NULL,
         0,
         &cbReturned,
         NULL
         )
    

    For more information about FSCTL_UNLOCK_VOLUME, see this Microsoft Web site.

    After the volume is unlocked, the system automatically rediscovers the volume and makes it available. Because the hibernation file does not include any information about the volume, you must unlock the volume on every restart.

See Also

Concepts

Protect Multiple Volumes in a Hibernate Once/Resume Many Configuration

Other Resources

Use an Unprotected Volume in a Hibernate Once/Resume Many Environment