Platform SDK: Hardware |
Using the FSCTL_MOVE_FILE control code relocates one or more virtual clusters of a file from one logical cluster to another within the same volume.
To perform this operation, call the DeviceIoControl function with the following parameters.
BOOL DeviceIoControl( (HANDLE) hDevice, // handle to volume FSCTL_MOVE_FILE, // dwIoControlCode operation (LPVOID) lpInBuffer, // input buffer (DWORD) nInBufferSize, // size of input buffer NULL, // lpOutBuffer; must be NULL 0, // nOutBufferSize; must be zero (LPDWORD) lpBytesReturned, // number of bytes returned (LPOVERLAPPED) lpOverlapped // OVERLAPPED structure );
Encrypted files must be opened with FILE_READ_DATA, FILE_WRITE_DATA, FILE_APPEND_DATA, or FILE_EXECUTE access. Other files need only be opened with FILE_READ_ATTRIBUTES access. For more information, see File and Directory Security.
If lpOverlapped is NULL (nonoverlapped I/O), lpBytesReturned is used internally and cannot be NULL.
If lpOverlapped is not NULL (overlapped I/O), lpBytesReturned can be NULL.
If hDevice was opened with the FILE_FLAG_OVERLAPPED flag, lpOverlapped must point to a valid OVERLAPPED structure. In this case, DeviceIoControl is performed as an overlapped (asynchronous) operation. If the device was opened with the FILE_FLAG_OVERLAPPED flag and lpOverlapped is NULL, the function fails in unpredictable ways.
If hDevice was opened without specifying the FILE_FLAG_OVERLAPPED flag, lpOverlapped is ignored and DeviceIoControl does not return until the operation has been completed or an error occurs.
If the operation succeeds, DeviceIoControl returns a nonzero value.
If the operation fails, DeviceIoControl returns zero. To get extended error information, call GetLastError. The possible return values for GetLastError include the following values.
Last Error | Interpretation |
---|---|
ERROR_INVALID_PARAMETER | One or more of the following:
One or more of the logical clusters to which the file's virtual clusters are to be moved is an allocated cluster. |
ERROR_INVALID_FUNCTION | This is an NTFS volume with a cluster size greater than 4KB. |
ERROR_INSUFFICIENT_BUFFER | This is an NTFS volume and the input buffer was smaller than sizeof(MOVE_FILE_DATA). |
ERROR_NOT_READY | The volume is NTFS and is unmounted. |
ERROR_GEN_FAILURE | Typically, this means that on NTFS, another compress or FSCTL_MOVE_FILE operation is happening at the same time on the file specified by the FileHandle member. |
Note that when a move operation returns with a failure, some of the clusters may have been moved. To determine if this is the case, you have to acquire a new bitmap or retrieve new pointers.
The FSCTL_MOVE_FILE operation relocates one or more virtual clusters of a file from one logical cluster to another within the same volume. If the file to be moved is a sparse or compressed file, the granularity of the move is 16 clusters; otherwise, the granularity is one cluster.
Note that the bitmap returned by the DeviceIoControl FSCTL_GET_VOLUME_BITMAP operation represents a point in time, and can be incorrect as soon as it has been read if the volume has write activity. Thus, it is possible to attempt to move a cluster onto an allocated cluster in spite of a recent bitmap indicating that the cluster is unallocated. Programs using FSCTL_MOVE_FILE must be prepared for this possibility.
For the implications of overlapped I/O on this operation, see the Remarks section of the DeviceIoControl topic.
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Unsupported.
Header: Declared in Winioctl.h.
Device Input and Output Overview, Device Input and Output Control Codes, Defragmentation, DeviceIoControl, CreateFile, GetLastError, GetOverlappedResult, GetQueuedCompletionStatus, MOVE_FILE_DATA, FSCTL_GET_VOLUME_BITMAP, OVERLAPPED