FSCTL_SET_ZERO_DATA control code
Fills a specified range of a file with zeros (0). If the file is sparse or compressed, the NTFS file system may deallocate disk space in the file. This sets the range of bytes to zeros (0) without extending the file size.
To perform this operation, call the DeviceIoControl function with the following parameters.
BOOL WINAPI DeviceIoControl( (HANDLE) hDevice, // handle to a file FSCTL_SET_ZERO_DATA, // dwIoControlCode (LPVOID) lpInBuffer, // input buffer (DWORD) nInBufferSize, // size of input buffer NULL, // lpOutBuffer 0, // nOutBufferSize (LPDWORD) lpBytesReturned, // number of bytes returned (LPOVERLAPPED) lpOverlapped ); // OVERLAPPED structure
Parameters
- hDevice
-
A handle to the file or alternate stream on which zero (0) data is to be written.
To retrieve a file handle, use the CreateFile function. The file does not need to be a sparse file.
- dwIoControlCode
-
The control code for the operation.
Use FSCTL_SET_ZERO_DATA for this operation.
- lpInBuffer
-
A pointer to a FILE_ZERO_DATA_INFORMATION structure that specifies the range of the file to set to zeros.
The FileOffset member is the byte offset of the first byte to set to zeros (0), and the BeyondFinalZero member is the byte offset of the first byte beyond the last zero (0) byte.
- nInBufferSize
-
The size of the input buffer, in bytes.
- lpOutBuffer
-
Not used with this operation.
Set to NULL.
- nOutBufferSize
-
Not used with this operation.
Set to zero (0).
- lpBytesReturned
-
A pointer to a variable that receives the size of the data that is stored in the output buffer, in bytes.
If lpOverlapped is NULL, lpBytesReturned cannot be NULL. Even when an operation does not return output data and lpOutBuffer is NULL, DeviceIoControl uses 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 is complete. 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.
- lpOverlapped
-
A pointer to an OVERLAPPED structure.
If hDevice is opened without specifying FILE_FLAG_OVERLAPPED, lpOverlapped is ignored.
If hDevice is 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 is complete. Otherwise, the function does not return until the operation is complete 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 (0). For extended error information, call GetLastError.
Remarks
For the implications of overlapped I/O on this operation, see the Remarks section of the DeviceIoControl topic.
If you use the WriteFile function to write zeros (0) to a sparse file, the file system allocates disk space for the data that you are writing. If you use the FSCTL_SET_ZERO_DATA control code to write zeros (0) to a sparse file and the zero (0) region is large enough, the file system may not allocate disk space.
If you use the FSCTL_SET_ZERO_DATA control code to write zeros (0) to a non-sparse file, zeros (0) are written to the file. The system allocates disk storage for all of the zero (0) range, which is equivalent to using the WriteFile function to write zeros (0) to a file.
The time stamps may not be updated correctly for a remote file. To ensure consistent results, use unbuffered I/O.
IIn Windows 8 and Windows Server 2012, this code is supported by the following technologies.
| Technology | Supported |
|---|---|
|
Server Message Block (SMB) 3.0 protocol |
Yes |
|
SMB 3.0 Transparent Failover (TFO) |
Yes |
|
SMB 3.0 with Scale-out File Shares (SO) |
Yes |
|
Cluster Shared Volume File System (CsvFS) |
Yes |
|
Resilient File System (ReFS) |
Yes |
Requirements
|
Minimum supported client |
Windows XP [desktop apps only] |
|---|---|
|
Minimum supported server |
Windows Server 2003 [desktop apps only] |
|
Header |
|
See also
- DeviceIoControl
- File Management Control Codes
- FILE_ZERO_DATA_INFORMATION
- FSCTL_QUERY_ALLOCATED_RANGES
- FSCTL_SET_SPARSE
- Sparse Files