NtFlushBuffersFileEx function (ntifs.h)

The NtFlushBuffersFileEx routine sends a flush request for a given file to the file system. An optional flush operation flag can be set to control how file data is written to storage.

Syntax

__kernel_entry NTSYSCALLAPI NTSTATUS NtFlushBuffersFileEx(
  [in]  HANDLE           FileHandle,
  [in]  ULONG            Flags,
  [in]  PVOID            Parameters,
  [in]  ULONG            ParametersSize,
  [out] PIO_STATUS_BLOCK IoStatusBlock
);

Parameters

[in] FileHandle

Handle returned by NtCreateFile or NtOpenFile for the file whose buffers will be flushed. This parameter is required and cannot be NULL.

[in] Flags

Flush operation flags. Flags can be one of the following values:

Value Meaning
0 (normal) File data and metadata in the file cache will be written, and the underlying storage is synchronized to flush its cache. Windows file systems supported: NTFS, ReFS, FAT, exFAT.
FLUSH_FLAGS_FILE_DATA_ONLY File data in the file cache will be written. No metadata is written and the underlying storage is not synchronized to flush its cache. This flag is not valid with volume handles. Windows file systems supported: NTFS, FAT, exFAT.
FLUSH_FLAGS_NO_SYNC File data and metadata in the file cache will be written. The underlying storage is not synchronized to flush its cache. This flag is not valid with volume handles. Windows file systems supported: NTFS, FAT, exFAT.
FLUSH_FLAGS_FILE_DATA_SYNC_ONLY Data from the given file will be written from the Windows in-memory cache. Only metadata that is necessary for data retrieval will be flushed (timestamp updating will be skipped as much as possible). The underlying storage is synchronized to flush its cache. This flag is not valid with volume or directory handles. Windows file systems supported: NTFS.

[in] Parameters

Pointer to a block with additional parameters. This parameter must currently be set to NULL.

[in] ParametersSize

The size, in bytes, of the block that Parameters point to. This parameter must currently be set to 0.

[out] IoStatusBlock

Address of the caller's I/O status block. This parameter is required and cannot be NULL.

Return value

NtFlushBuffersFileEx returns STATUS_SUCCESS or an appropriate NTSTATUS value, such as one of the following:

Return code Description
STATUS_MEDIA_WRITE_PROTECTED The file resides on a write-protected volume; this is an error code.
STATUS_VOLUME_DISMOUNTED The file resides on a volume that is not currently mounted; this is an error code.
STATUS_ACCESS_DENIED The file does has neither write or append access.

Remarks

Minifilter drivers should call FltFlushBuffers2 instead of calling NtFlushBuffersFileEx.

A legacy file system filter driver can call NtFlushBuffersFileEx to issue an IRP_MJ_FLUSH_BUFFERS request to the file system for a given file. The flush operation is synchronous.

Callers of NtFlushBuffersFileEx must be running at IRQL = PASSIVE_LEVEL and with special kernel APCs enabled.

For calls from kernel-mode drivers, the NtXxx and ZwXxx versions of a Windows Native System Services routine can behave differently in the way that they handle and interpret input parameters. For more information about the relationship between the NtXxx and ZwXxx versions of a routine, see Using Nt and Zw Versions of the Native System Services Routines.

Requirements

Requirement Value
Minimum supported client Windows 8
Target Platform Universal
Header ntifs.h (include Ntifs.h)
Library NtosKrnl.lib
DLL NtosKrnl.exe
IRQL PASSIVE_LEVEL (See Remarks section.)

See also

FltFlushBuffers2

IRP_MJ_FLUSH_BUFFERS

Using Nt and Zw Versions of the Native System Services Routines

NtCreateFile

NtOpenFile