Home

syncfs

Syncfs is a Linux system call that synchronizes all in-memory data and metadata for the filesystem that contains the file referred to by the provided file descriptor. It ensures that pending writes and metadata changes are flushed to the underlying storage. The call is identified as int syncfs(int fd) and is available on Linux in userspace programs via the C library as a wrapper around the kernel system call.

This call differs from fsync, which operates on a single open file object and ensures its inodes

Usage: A process calls syncfs with a file descriptor referencing any file on the target filesystem. On

Notes: syncfs is Linux-specific and not specified by POSIX; the exact behavior can vary across filesystem implementations.

and
data
are
written
to
disk;
syncfs,
by
contrast,
targets
the
entire
filesystem
that
the
fd
belongs
to,
flushing
all
dirty
inodes
and
metadata
associated
with
that
filesystem.
It
is
also
distinct
from
the
generic
sync()
call,
which
flushes
buffered
data
to
disk
for
all
filesystems
and
can
be
less
predictable
in
timing.
success,
0
is
returned;
on
error,
-1
is
returned
and
errno
is
set.
Common
error
codes
include
EBADF
for
an
invalid
fd,
and
EROFS
if
the
filesystem
is
read-only
or
otherwise
cannot
be
synchronized.
It
can
be
useful
after
a
crash,
before
unmounting,
or
when
ensuring
that
metadata
and
data
are
persisted
for
a
whole
filesystem.