How to finalize a drive

This topic describes how to finalize a drive.

Finalising a drive moves it to a consistent state, which enables the safe removal of media or safe shut down of the device. There are two types of finalisation defined by TfinalizeDrvMode:

  • EFinal_RO - Hard finalisation. This flushes all caches and puts the volume into a consistent state. After finalisation, the volume becomes read-only until remounted. All read operations are accepted but all write operations fail. This mode is used:

    • in an eject media application - this application is launched by the user in order to safely remove the media

    • when the device is shut down.

  • EFinal_RW - soft finalisation. This flushes all caches and puts the volume into a consistent state, after which all read and write operations are accepted but the first write access after finalisation renders the volume no longer finalized.

    This mode of finalisation can be used by an application to put the media into a consistent state after a period of device inactivity. This minimizes the risk of media corruption on its removal or sudden power loss.

finalize a drive by calling RFs::finalizeDrive() with the drive number and the type of finalisation mode required, EFinal_RW or EFinal_RO. The error code returned by finalizeDrive() should be checked before proceeding as it is not possible to finalize the volume if it is corrupt or has filesystem objects open on it (files, directories, formats etc.).

During drive finalisation, data is written to the media that indicates the drive is in a consistent state, after which no write operations are supposed to take place on the specified volume.

From v9.4. the API RFs::finalizeDrives() has been changed so that it sends finalize drive requests to all the existing drives in the system, not just the local and internal drives.

The user of RFs APIs must have the DiskAdmin security capability.