Messages in this thread | ![/](/images/icornerl.gif) | | Date | Fri, 9 Jul 2004 02:39:48 -0700 | From | Andrew Morton <> | Subject | Re: Syncing a file's metadata in a portable way |
| |
Alberto Bertogli <albertogli@telpin.com.ar> wrote: > > > 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".
It depends on the Linux filesystem. On ext3, for example, fsync() will sync all of the filesytem's metadata (and data in journalled and ordered data mode).
But on ext2 you'll need to fsync the directory. However, that only needs to be done once, after the create.
> However, the O_DIRECTORY flag is Linux only, making this mechanism not > portable. > > Is there a way of doing this in a portable way?
Doing a create, followed by a system-wide sync(), followed by write/fsync/write/fsync/... will do what you want on all Linux filesystems. That might be a bit of a performance problem if you're creating a lot of files, although probably not.
This method should portable to other OS'es if they implement sync() sanely.
But note that they may not: according to the spec, sync() doesn't _have_ to wait for all the queued I/O to complete prior to returning. It does on Linux. Some additional sync()s may be needed on other OS'es.
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| ![\](/images/icornerr.gif) |