FSCTL_SET_ZERO_DATA - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
// winioctl.h

// CTL_CODE(0x0009, 0x032, METHOD_BUFFERED, FILE_WRITE_ACCESS)
#define FSCTL_SET_ZERO_DATA 0x000980C8
View the official Win32 API reference
// ntifs.h

// CTL_CODE(0x0009, 0x032, METHOD_BUFFERED, FILE_WRITE_ACCESS)
#define FSCTL_SET_ZERO_DATA 0x000980C8
View the official Windows hardware development documentation

NtDoc

No description available.

Win32 API reference (ni-winioctl-fsctl_set_zero_data)

FSCTL_SET_ZERO_DATA IOCTL

Description

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 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

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

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.

In 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

See also


Windows hardware development documentation (fsctl-set-zero-data)

FSCTL_SET_ZERO_DATA control code

The 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 from a driver, call FltFsControlFile with the following parameters.

Parameters

Use FSCTL_SET_ZERO_DATA for this operation.

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.

The Flags member in FILE_ZERO_DATA_INFORMATION_EX specifies modifiers to the operation. For example, when Flags is set to FILE_ZERO_DATA_INFORMATION_FLAG_PRESERVE_CACHED_DATA, the contents of the cache corresponding to this range of the file are not purged.

Status block

FltFsControlFile returns STATUS_SUCCESS or an appropriate NTSTATUS value.

Return code Meaning
STATUS _INSUFFICIENT_RESOURCES There is not enough memory to complete the operation.
STATUS_INVALID_PARAMETER The InputBufferLength is smaller than the size of the FILE_ZERO_DATA_INFORMATION structures or the file specified is a system metadata file or a directory.
STATUS_ACCESS_DENIED The FILE_ZERO_DATA_INFORMATION_FLAG_PRESERVE_CACHED_DATA is set from user mode.
STATUS_MEDIA_WRITE_PROTECTED The volume is currently write protected.

Requirements

Requirement type Requirement
Header Ntifs.h (include Ntifs.h)

See also

FltFsControlFile

FILE_ZERO_DATA_INFORMATION

FILE_ZERO_DATA_INFORMATION_EX