Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit focus mode

FlushFileBuffers function (fileapi.h)

  • 2021-10-13
Feedback

In this article

Flushes the buffers of a specified file and causes all buffered data to be written to a file.

Syntax

BOOL FlushFileBuffers(  [in] HANDLE hFile);

Parameters

[in] hFile

A handle to the open file.

The file handle must have theGENERIC_WRITE access right. For more information, seeFile Security and Access Rights.

IfhFile is a handle to a communications device, the function only flushes the transmit buffer.

IfhFile is a handle to the server end of a named pipe, the function does not return until the client has read all buffered data from the pipe.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, callGetLastError.

The function fails ifhFile is a handle to the console output. That is because the console output is not buffered. The function returnsFALSE, andGetLastError returnsERROR_INVALID_HANDLE.

Remarks

Typically theWriteFile andWriteFileEx functions write data to an internal buffer that the operating system writes to a disk or communication pipe on a regular basis. TheFlushFileBuffers function writes all the buffered information for a specified file to the device or pipe.

Due to disk caching interactions within the system, theFlushFileBuffers function can be inefficient when used after every write to a disk drive device when many writes are being performed separately. If an application is performing multiple writes to disk and also needs to ensure critical data iswritten to persistent media, the application should use unbuffered I/O instead of frequently callingFlushFileBuffers. To open a file for unbuffered I/O, call theCreateFile function with theFILE_FLAG_NO_BUFFERING andFILE_FLAG_WRITE_THROUGH flags. This prevents the file contents from being cached and flushes the metadata to disk with each write. For more information, seeCreateFile.

To flush all open files on a volume, callFlushFileBuffers with a handle to the volume. The caller must have administrative privileges. For more information, seeRunning with Special Privileges.

When opening a volume withCreateFile, thelpFileName string should be the following form: \\.\x: or \\?\Volume{GUID}. Do not use a trailing backslash in the volume name, because that indicates the root directory of a drive.

In Windows 8 and Windows Server 2012, this function is supported by the following technologies.

TechnologySupported
Server Message Block (SMB) 3.0 protocolYes
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
 

Examples

For an example, seeMultithreaded Pipe Server.

Requirements

RequirementValue
Minimum supported clientWindows XP [desktop apps | UWP apps]
Minimum supported serverWindows Server 2003 [desktop apps | UWP apps]
Target PlatformWindows
Headerfileapi.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll

See also

CreateFile

File Management Functions

WriteFile

WriteFileEx


Feedback

Was this page helpful?

YesNo

In this article

Was this page helpful?

YesNo