FsRtlGetFileSize function (ntifs.h)

The FsRtlGetFileSize routine is used to get the size of a file.

Syntax

NTSTATUS FsRtlGetFileSize(
  [in]  PFILE_OBJECT   FileObject,
  [out] PLARGE_INTEGER FileSize
);

Parameters

[in] FileObject

A pointer to the file object to query.

[out] FileSize

A pointer to a large integer that receives the file size on output.

Return value

FsRtlGetFileSize returns STATUS_SUCCESS or an appropriate error status representing the final completion status of the operation. Possible error status codes include the following:

Return code Description
STATUS_INSUFFICIENT_RESOURCES
The memory required for use by this function could not be allocated.
STATUS_FILE_IS_A_DIRECTORY
The specified FileObject refers to a directory.

Remarks

The FsRtlGetFileSize routine is used to retrieve the file size for a file. Unlike ZwQueryInformationFile, FsRtlGetFileSize does not acquire the file object lock on synchronous file objects. If you already own file system resources, you should call FsRtlGetFileSize instead of ZwQueryInformationFile, because attempting to acquire the file object lock would violate locking order and lead to deadlocks. The ZwQueryInformationFile function should be only if you do not already own file system resources.

FsRtlGetFileSize will use fast I/O if it is supported or regular IRP-based query to extract the file size.

Requirements

Requirement Value
Target Platform Universal
Header ntifs.h (include Ntifs.h)
Library NtosKrnl.lib
DLL NtosKrnl.exe
IRQL PASSIVE_LEVEL
DDI compliance rules HwStorPortProhibitedDDIs(storport), PowerIrpDDis(wdm)

See also

FltQueryInformationFile

ZwQueryInformationFile