FSCTL_SHRINK_VOLUME IOCTL (winioctl.h)
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
);
Remarks
This control code is only supported on NTFS and RAW file systems.
To complete a shrink operation, you must:
- Call CreateFile to open a handle to the volume.
- 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.
- 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.
- 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.
- 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
Requirement | Value |
---|---|
Minimum supported client | Windows Vista [desktop apps only] |
Minimum supported server | Windows Server 2008 [desktop apps only] |
Header | winioctl.h (include Windows.h) |