Signals that the volume is to be prepared to perform the shrink operation, the shrink operation is to be committed, or the shrink operation is to be terminated.

To perform this operation, call the DeviceIoControl function with the following parameters.

BOOL DeviceIoControl(
  (HANDLE) hDevice,             // handle to device
  FSCTL_SHRINK_VOLUME, // dwIoControlCode
  (LPVOID) lpInBuffer,               // input buffer
  nInBufferSize,     // size of input buffer    
  NULL,                          // output buffer
  O,                             // size of output buffer
  (LPDWORD) lpBytesReturned,    // number of bytes returned
  (LPOVERLAPPED) lpOverlapped   // OVERLAPPED structure



A handle to the device. To obtain a device handle, call the CreateFile function.


The control code for the operation. Use FSCTL_SHRINK_VOLUME for this operation.


A pointer to the SHRINK_VOLUME_INFORMATION input buffer, a structure.


The size of the input buffer, in bytes.


Not used with this operation.

Set to NULL.


Not used with this operation.

Set to 0 (zero).


A pointer to a variable that receives the size of the data stored in the output buffer, in bytes.

If the output buffer is too small, the call fails, GetLastError returns ERROR_INSUFFICIENT_BUFFER, and lpBytesReturned is zero.

If lpOverlapped is NULL, lpBytesReturned cannot be NULL. Even when an operation returns no output data and lpOutBuffer is NULL, DeviceIoControl makes use of lpBytesReturned. After such an operation, the value of lpBytesReturned is meaningless.

If lpOverlapped is not NULL, lpBytesReturned can be NULL. If this parameter is not NULL and the operation returns data, lpBytesReturned is meaningless until the overlapped operation has completed. To retrieve the number of bytes returned, call GetOverlappedResult. If hDevice is associated with an I/O completion port, you can retrieve the number of bytes returned by calling GetQueuedCompletionStatus.


A pointer to an OVERLAPPED structure.

If hDevice was opened without specifying FILE_FLAG_OVERLAPPED, lpOverlapped is ignored.

If hDevice was opened with the FILE_FLAG_OVERLAPPED flag, the operation is performed as an overlapped (asynchronous) operation. In this case, lpOverlapped must point to a valid OVERLAPPED structure that contains a handle to an event object. Otherwise, the function fails in unpredictable ways.

For overlapped operations, DeviceIoControl returns immediately, and the event object is signaled when the operation has been completed. Otherwise, the function does not return until the operation has been completed or an error occurs.

Return value

If the operation completes successfully, DeviceIoControl returns a nonzero value.

If the operation fails or is pending, DeviceIoControl returns zero. To get extended error information, call GetLastError.


This control code is only supported on NTFS and RAW file systems.

To complete a shrink operation, you must:

  1. Call CreateFile to open a handle to the volume.
  2. Call FSCTL_SHRINK_VOLUME. Set the ShrinkRequestType member of the SHRINK_VOLUME_INFORMATION structure to ShrinkPrepare. Set the NewNumberOfSectors member of the same structure to zero. If this call succeeds, the filesystem will not allocate clusters beyond the end of the new volume length.
  3. Call FSCTL_MOVE_FILE on all files beyond the new number of sectors and move them within the valid range. You are responsible for moving any files that are affected by the shrink operation.
  4. Call FSCTL_SHRINK_VOLUME. Set the ShrinkRequestType member of the SHRINK_VOLUME_INFORMATION structure to ShrinkCommit. Set the NewNumberOfSectors member of the same structure to zero. If all files beyond the end of the new volume size have not been moved, the call fails with STATUS_ALREADY_COMMITTED (ERROR_ACCESS_DENIED). Otherwise, the filesystem has now been shrunk.
  5. Call IOCTL_DISK_GROW_PARTITION. Set the BytesToGrow member of the DISK_GROW_PARTITION structure to the negative number that represents the number of bytes to remove.

In Windows 8 and Windows Server 2012, this code is supported by the following technologies.


Server Message Block (SMB) 3.0 protocol


SMB 3.0 Transparent Failover (TFO)


SMB 3.0 with Scale-out File Shares (SO)


Cluster Shared Volume File System (CsvFS)

See comment


Is supported only on the node that has NTFS mounted.


Minimum supported client

Windows Vista [desktop apps only]

Minimum supported server

Windows Server 2008 [desktop apps only]


WinIoCtl.h (include Windows.h)

See also

Volume Management Control Codes