// ntifs.h
// CTL_CODE(0x0009, 0x033, METHOD_NEITHER, FILE_READ_ACCESS)
#define FSCTL_QUERY_ALLOCATED_RANGES 0x000940CF
View the official Windows Driver Kit DDI reference// winioctl.h
// CTL_CODE(0x0009, 0x033, METHOD_NEITHER, FILE_READ_ACCESS)
#define FSCTL_QUERY_ALLOCATED_RANGES 0x000940CF
View the official Win32 API referenceNo description available.
FSCTL_QUERY_ALLOCATED_RANGES requests a scan of a file or alternate stream looking for byte ranges that can contain nonzero data, and then return of information on those ranges. Only sparse files can have zeroed ranges known to the operating system. For other files, the output buffer will contain only a single range that contains the starting point and the length requested.
FSCTL_QUERY_ALLOCATED_RANGES
Pointer to a FILE_ALLOCATED_RANGE_BUFFER structure that indicates the range to query for allocation.
Size of the FILE_ALLOCATED_RANGE_BUFFER structure that InputBuffer points to, in bytes.
Pointer to an array of zero or more FILE_ALLOCATED_RANGE_BUFFER data elements in which the results of the query are returned. See below for more information.
Size of the buffer that OutputBuffer points to, in bytes.
n/a
n/a
Reserved for system use.
To perform this operation, call FltFsControlFile or ZwFsControlFile with the following parameters.
| Parameter | Description |
|---|---|
| Instance | [in] For FltFsControlFile only. An opaque instance pointer for the caller. This parameter is required and cannot be NULL. |
| FileObject | [in] For FltFsControlFile only. A file object pointer for the file or directory that is the target of this request. This parameter is required and cannot be NULL. |
| FileHandle | [in] For ZwFsControlFile only. File handle of the file or directory that is the target of this request. This parameter is required and cannot be NULL. |
| IoStatusBlock | [out] For ZwFsControlFile only. Pointer to an IO_STATUS_BLOCK structure that contains the final status of the request. |
| FsControlCode | [in] Set to FSCTL_QUERY_ALLOCATED_RANGES. |
| InputBuffer | [in] Pointer to a FILE_ALLOCATED_RANGE_BUFFER structure that indicates the range to query for allocation. |
| InputBufferLength | [in] Size of the buffer that InputBuffer points to, in bytes. |
| OutputBuffer | [out] Pointer to an array of zero or more FILE_ALLOCATED_RANGE_BUFFER data elements in which the results of the query are returned. See below for more information. |
| OutputBufferLength | [out] Size of the buffer that OutputBuffer points to, in bytes. |
| LengthReturned | [out] Pointer to a caller-allocated variable that receives the size in bytes of the information returned in the buffer at OutputBuffer. |
FSCTL_QUERY_ALLOCATED_RANGES returns an array of zero or more FILE_ALLOCATED_RANGE_BUFFER data elements in the buffer that OutputBuffer points to. The number of FILE_ALLOCATED_RANGE_BUFFER elements returned is computed by dividing the value returned in LengthReturned by sizeof(FILE_ALLOCATED_RANGE_BUFFER). The returned ranges must intersect the range specified in InputBuffer. Zero FILE_ALLOCATED_RANGE_BUFFER data elements are returned when the file has no allocated ranges.
FSCTL_QUERY_ALLOCATED_RANGES returns STATUS_SUCCESS upon successful completion; otherwise it returns an error code. Common error codes follow.
| Error code | Meaning |
|---|---|
| STATUS_INVALID_PARAMETER | A parameter is invalid. For example: the handle is not to a file; the size of InputBuffer is less than the size of a FILE_ALLOCATED_RANGE_BUFFER structure; FileOffset is less than zero; Length is less than zero; or FileOffset plus Length is larger than 0x7FFFFFFFFFFFFFFF. |
| STATUS_INVALID_USER_BUFFER | The input buffer or output buffer is not aligned to a 4-byte boundary. |
| STATUS_BUFFER_TOO_SMALL | The output buffer is too small to contain a FILE_ALLOCATED_RANGE_BUFFER structure. |
| STATUS_BUFFER_OVERFLOW | The output buffer is too small to contain the required number of FILE_ALLOCATED_RANGE_BUFFER structures. |
Scans a file or alternate stream looking for ranges that may contain nonzero data. Only compressed or sparse files can have zeroed ranges known to the operating system. For other files, the output buffer will contain only a single entry that contains the starting point and the length requested. To perform this operation, call the DeviceIoControl function with the following parameters.
BOOL DeviceIoControl(
(HANDLE) hDevice, // handle to file
FSCTL_QUERY_ALLOCATED_RANGES, // dwIoControlCode
(LPVOID) lpInBuffer, // input buffer
(DWORD) nInBufferSize, // size of input buffer
(LPVOID) lpOutBuffer, // output buffer
(DWORD) nOutBufferSize, // size of output buffer
(LPDWORD) lpBytesReturned, // number of bytes returned
(LPOVERLAPPED) lpOverlapped // OVERLAPPED structure
);
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.
For the implications of overlapped I/O on this operation, see the Remarks section of DeviceIoControl.
The NTFS file system rounds the input file offset down to a convenient boundary and the length up to a convenient boundary and then begins to walk through the file.
The operating system does not track every piece of zero (0) or nonzero data. Because zero (0) is often a perfectly legal datum, it would be misleading. Instead, the system tracks ranges where disk space is allocated. Where no disk space is allocated, all data are assumed to be zero (0). Allocated storage can contain zero (0) or nonzero data. So all this operation does is return information about parts of the file where nonzero data may be located. It is up to the application to scan these parts of the file in accordance with the application's data conventions.
Each entry in the output array contains an offset and a length that indicates a range in the file that may contain nonzero data. The actual nonzero data, if any, is somewhere within this range, and the calling program must scan further within the range to locate it and determine if it really is valid data. Multiple instances of valid data may exist within the range.
Allocated ranges are subject to the rule that a memory mapped remote (network) file and an open handle to the file are not necessarily coherent. If you memory mapped a sparse network file and wrote nonzero data to previously unallocated regions of the file, disk space would be allocated for the new data. However, a call to FSCTL_QUERY_ALLOCATED_RANGES thereafter would not necessarily return a correct list of allocated regions. To ensure coherency between the view memory and the file handle, flush the data to the file with the FlushViewOfFile function.
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) | No |