3.4.5.2.34.2 IVdsVolumeMF::Format (Opnum 4)

The Format method formats a file system on the current volume.

 HRESULT Format(
   [in] VDS_FILE_SYSTEM_TYPE type,
   [in, string] WCHAR* pwszLabel,
   [in] DWORD dwUnitAllocationSize,
   [in] long bForce,
   [in] long bQuickFormat,
   [in] long bEnableCompression,
   [out] IVdsAsync** ppAsync
 );

type: A file system type that is enumerated by VDS_FILE_SYSTEM_TYPE. Clients that format by using file systems that are not enumerated by VDS_FILE_SYSTEM_TYPE can use the IVdsVolumeMF2::FormatEx method.

pwszLabel: A null-terminated Unicode label to assign to the new file system. The maximum label size is file system-dependent.

dwUnitAllocationSize: The size, in bytes, of the allocation unit for the file system. The value MUST be a power of 2. The allocation unit range is file system-dependent.

bForce: A Boolean that determines whether the format is forced, even if the volume is in use.

bQuickFormat: A Boolean that determines whether a file system is quick format. A quick format does not verify each sector on the volume.

bEnableCompression: A Boolean that determines whether a file system is created with compression enabled.<127>

ppAsync: A pointer to an IVdsAsync interface that, if the operation is successfully completed, receives the IVdsAsync interface to monitor and control this operation. Callers MUST release the interface when they are done with it.

Return Values: The method MUST return zero or a non-error HRESULT (as specified in [MS-ERREF]) to indicate success, or return an implementation-specific nonzero error code to indicate failure. For the HRESULT values predefined by the Virtual Disk Service Remote Protocol, see section 2.2.3.

When the server receives this message, it MUST validate the following parameter:

  • Verify that ppAsync is not NULL.

    If parameter validation fails, the server MUST fail the operation immediately, returning a vendor-specific error as its response to the client.

The server MUST perform the following:

  • Create a new async object implementing the IVdsAsync interface with an output type of VDS_ASYNCOUT_FORMAT and set the pointer referenced by ppAsync to the interface.

  • Return an HRESULT indicating failure or success. Any errors encountered up through this point in processing the FormatPartition operation are returned in this HRESULT.

The server MUST perform the following. Errors generated in this sequence of steps are returned in the pHrResult parameter to the IVdsAsync::Wait or IVdsAsyncQueryStatus methods.

  • Attempt to get exclusive access to the volume. If the server fails to get exclusive access to the volume, and the bForce parameter is not set to a non-zero value, then the server MUST return VDS_E_DEVICE_IN_USE.

  • If the operating system is unable to format the device using the file system type specified using the type parameter, then this method MUST return VDS_E_INCOMPATIBLE_FILE_SYSTEM.

  • If the target device\media is write-protected, then this method MUST return VDS_E_MEDIA_WRITE_PROTECTED.

  • If the pwszLabel parameter is incompatible with the file system type that is specified using the type parameter, then the server MUST return VDS_E_BAD_LABEL.

  • If the specified file system type has a minimum volume size requirement, and that requirement is not met, then the server MUST return VDS_E_VOLUME_TOO_SMALL.

  • If the specified file system type has a maximum volume size requirement, and that requirement is not met, then the server MUST return VDS_E_VOLUME_TOO_BIG.

  • If the specified file system type has a minimum or maximum cluster size requirement, and that requirement is not met, then the server MUST return VDS_E_CLUSTER_SIZE_TOO_SMALL or VDS_E_CLUSTER_SIZE_TOO_BIG, respectively.

  • If the specified file system type has a maximum cluster count requirement, and that requirement is not met, then the server MUST return VDS_E_CLUSTER_COUNT_BEYOND_32BITS.

The server MUST update the percentage completed value periodically during the following sequence, and send progress notifications to all clients. How often the percentage completed is updated, and at what point in the sequence, is implementation specific. To send progress notifications to the clients:

  • For each callback object registered in the list of callback objects, call the callback object's IVdsAdviseSink::OnNotify (Opnum 3) method with a VDS_NOTIFICATION structure with the following attributes:

    • objectType member is VDS_NTT_FILE_SYSTEM.

    • FileSystem member is a VDS_FILE_SYSTEM_NOTIFICATION with the following attributes:

      • ulEvent is VDS_NF_FILE_SYSTEM_FORMAT_PROGRESS.

      • volumeId is the VDS_OBJECT_ID of the volume object

      • dwPercentCompleted is the percentage completed value.

The server MUST then perform the following in sequence. Errors generated in this sequence of steps are returned in the pHrResult parameter to the IVdsAsync::Wait or IVdsAsyncQueryStatus methods.

  • Format the volume following the parameters specified to the method.

  • For each callback object registered in the list of callback objects, call the callback object's IVdsAdviseSink::OnNotify() method with a VDS_NOTIFICATION structure with the following attributes:

    • objectType member is VDS_NTT_VOLUME.

    • Volume member is a VDS_VOLUME_NOTIFICATION with the following attributes:

      • ulEvent is VDS_NF_VOLUME_MODIFY.

      • volumeId is the VDS_OBJECT_ID of this volume object.

      • plexId is NULL GUID, but it is not relevant when ulEvent is VDS_NF_VOLUME_MODIFY.

      • ulPercentCompleted range is 0-100 and is implementation-specific; however, it is not relevant when ulEvent is VDS_NF_VOLUME_MODIFY.

  • If TRUE is specified for bEnableCompression and the file system being formatted supports compression, compress the file system after formatting is complete.<128>

  • Set the return code in the async object to an HRESULT indicating failure or success.

    • If the server tried to compress the file system after formatting but failed, the return code MUST be set to VDS_S_VOLUME_COMPRESS_FAILED (HRESULT of 0x00042443).

  • If the task completed successfully, set the percentage completed value in the async object to 100.

  • Set the signal state in the async object to TRUE.