Re: fsync.2 does not mention error handling

From: Michael Kerrisk
Date: Thu Dec 04 2008 - 14:12:41 EST


On Tue, Dec 2, 2008 at 7:06 AM, Pavel Machek <pavel@xxxxxxx> wrote:
> fsync() transfers ("flushes") all modified in-core data of (i.e.,
> modified buffer cache pages for) the file referred to by the file
> descriptor fd to the disk device (or other permanent storage device)
> where that file resides. The call blocks until the device reports
> that the transfer has completed. It also flushes metadata information
> associated with the file (see stat(2)).
> Calling fsync() does not necessarily ensure that the entry in the
> directory containing the file has also reached disk. For that an
> explicit fsync() on a file descriptor for the directory is also
> needed.
> ...
> On success, these system calls return zero. On error, -1 is
> returned, and errno is set appropriately.
> --------------
> I guess it should mention that any errors during fsync are only
> mentioned to the first process calling it... which means that if you
> write file
> fsync file
> fsync .
> ... and someone else does "fsync ." in the meantime, you may get
> success when in fact directory entry of file is not written to the
> disk.

Could you provide some pointers to supporting information / mail
threads, relating to this?

Also, I'm still not 100% clear what you are saying above. Do you mean
that in this scenario, an error may occur but the first caller above
won't know of it? (It would help if you could write a few sentences
that you think should be in the man page.)



Michael Kerrisk
Linux man-pages maintainer;
man-pages online:
Found a bug?
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at