DefragVolume (Compact 2013)

3/26/2014

This function defragments files on a volume and removes any free space. The function also calls ScanVolumeEx prior to defragmentation to verify that the volume does not contain errors.

Syntax

BOOL DefragVolume(
  HANDLE hVolume,
  PDISK_INFO pdi,
  PDEFRAG_OPTIONS pdo,
  PFN_PROGRESS pfnProgress,
  PFN_MESSAGE pfnMessage
);

Parameters

  • hVolume
    [in] Handle to a disk or partition. Call CreateFile to obtain a handle to the volume.
  • pdo
    [in] Pointer to a DEFRAG_OPTIONS structure. The following fields can be specified.

    Member

    Description

    dwFatToUse

    Indicates which FAT to use for scanning, one-based indexing.

    fVerifyFix

    Set to TRUE to prompt the user to perform a fix.

  • pfnProgress
    [in] Callback function indicating progress.
  • pfnMessage
    [in] Callback function used to display a message to the user.

Return Value

TRUE indicates success. FALSE indicates failure. Typical reasons for failing would be running out of memory or an error writing to disk. This function does not fail if errors are detected on the disk.

Remarks

For best results, use the correct type of handle. For example, if the store to be scanned is partitioned, use a handle to the partition. If the store is not partitioned, use a disk handle.

Requirements

Header

defragdisk.h

Library

Fatutil.dll

See Also

Reference

FAT Utility Library Functions
CreateFile
DEFRAG_OPTIONS

Other Resources

DISK_INFO
DeviceIoControl