FSCTL_SHRINK_VOLUME IOCTL

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.

C++
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
);

Major Code

IRP_MJ_DEVICE_CONTROL

Input Buffer

Input Buffer Length

Output Buffer

Output Buffer Length

Input / Output Buffer

Input / Output Buffer Length

Status Block

Irp->IoStatus.Status is set to STATUS_SUCCESS if the request is successful.

Otherwise, Status to the appropriate error condition as a NTSTATUS code.

For more information, see NTSTATUS Values.

Remarks

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.

Technology Supported
Server Message Block (SMB) 3.0 protocol No
SMB 3.0 Transparent Failover (TFO) No
SMB 3.0 with Scale-out File Shares (SO) No
Cluster Shared Volume File System (CsvFS) See comment
 

Is supported only on the node that has NTFS mounted.

Requirements

   
Minimum supported client Windows Vista [desktop apps only]
Minimum supported server Windows Server 2008 [desktop apps only]
Header winioctl.h (include Windows.h)

See Also

CreateFile

DeviceIoControl

FSCTL_EXTEND_VOLUME

IOCTL_DISK_GROW_PARTITION

SHRINK_VOLUME_INFORMATION

Volume Management Control Codes