Syncing a file's metadata in a portable way
From: Alberto Bertogli
Date: Thu Jul 08 2004 - 22:06:43 EST
Hi!
I wanted to know if there was a common, portable way of syncing a given
file's metadata.
In particular, I just want to create a file with open() and be sure that
after some operation the file has been properly created and even if there
is a crash, it can be accessed (modulo internal disk caches and all that
stuff).
I know that fsync() provides only data guarantees, and even the manpage
says clearly that in order to sync metadata an "explicit fsync on the file
descriptor of the directory is also needed".
However, the O_DIRECTORY flag is Linux only, making this mechanism not
portable.
Is there a way of doing this in a portable way?
I know that under some filesystems with some mount options this can be
assured just by open() returning, or fsync() on the file, but I was
looking for a more general way to do it.
Also, according to SUSv3, "If _POSIX_SYNCHRONIZED_IO is defined, the
fsync() function shall force all currently queued I/O operations
associated with the file". This seems to imply that metadata gets synced
too, or at least I think "I/O operations associated with the file" can be
interpreted to include metadata.
However, based on a quick grep at the glibc code, it seems that the flag
doesn't make a difference in this case.
Is this really used or enforced?
Thanks a lot,
Alberto
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/