3.4.5.2.36.2 IVdsVolumeMF3::FormatEx2 (Opnum 4)

The FormatEx2 method formats a file system on a volume.

 HRESULT FormatEx2(
   [in, unique, string] LPWSTR pwszFileSystemTypeName,
   [in] USHORT usFileSystemRevision,
   [in] ULONG ulDesiredUnitAllocationSize,
   [in, unique, string] LPWSTR pwszLabel,
   [in] DWORD Options,
   [out] IVdsAsync** ppAsync
 );

pwszFileSystemTypeName: A null-terminated Unicode string that contains the name of the file systems to format the volume with.

usFileSystemRevision: A 16-bit, binary-coded decimal number that indicates the revision of the file system, if any. The first two (most significant) digits (8 bits) indicate the major revision, and the last two (least significant) digits (8 bits) indicate the minor revision. For example, 0x0250 represents revision 2.50.

ulDesiredUnitAllocationSize: The size, in bytes, of the allocation unit for the file system. The value MUST be a power of 2. If the value is 0, a default allocation unit that is determined by the file system type is used. The allocation unit range is file system-dependent.

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

Options: The combination of any values, by using a bitwise OR operator, that are defined in the VDS_FORMAT_OPTION_FLAGS enumeration.

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.

  • Create a new async object that implements the IVdsAsync interface with an output type of VDS_ASYNCOUT_FORMAT, and then set the pointer that ppAsync references to the interface.

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

The server MUST then 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 VDS_FSOF_FORCE flag in the Options parameter is not set to true, 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 specified using the type parameter, then the server MUST return VDS_E_BAD_LABEL.

  • If the specified file system type does not support quick formatting, then the server MUST return VDS_E_CANT_QUICK_FORMAT.

  • 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 perform the following in sequence:

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

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

    • The objectType member is VDS_NTT_VOLUME.

    • The 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.

  • If VDS_FSOF_COMPRESSION is specified and the file system being formatted supports compression, compress the file system after formatting is complete.<136>

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

    • If the server tried to compress the file systems 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.