You are not logged in.

#1 2010-05-14 20:48:19

B-Con
Member
From: USA
Registered: 2007-12-17
Posts: 554
Website

File buffers

When fflush() flushes a file stream, what does the other end of the stream connect to? I assume it's connected to the file system buffer, meaning that calling fflush() forces all dirty pages to be flushed to the FS buffer. What then is the intermediary buffer between the application and the FS buffer called, and why is it necessary if the FS buffer already exists?

How I see it:

Application data space -> File buffer -> File system buffer -> Disk

I don't know the official name of what I call "file buffer".

Conversely, the sync() utility forces all file system buffers to disk, which is unrelated to what fflush() does, right?

Offline

#2 2010-05-14 21:52:17

Peasantoid
Member
Registered: 2009-04-26
Posts: 928
Website

Re: File buffers

[No, wait, I don't have anything particularly helpful. Never mind. I am as yet unable to fully comprehend *nix IO.]

Last edited by Peasantoid (2010-05-14 21:57:02)

Offline

#3 2010-05-14 22:10:07

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: File buffers

fflush's man page gives a fairly reasonable explanation of what it does, and actually mentions the variation between fflush and sync. To wit...

DESCRIPTION
       For output streams, fflush() forces a write of all user-space buffered data for the given output or update stream via the stream's underly‐
       ing write function.


NOTES
       Note that fflush() only flushes the user space buffers provided by the C library.  To ensure that the data is physically stored on disk the
       kernel buffers must be flushed too, for example, with sync(2) or fsync(2).

Offline

#4 2010-05-17 00:20:19

B-Con
Member
From: USA
Registered: 2007-12-17
Posts: 554
Website

Re: File buffers

Thanks, I should've thought to look at the man page.

Offline

Board footer

Powered by FluxBB