From: Andrew Morton <akpm@osdl.org>
To: Alberto Bertogli <albertogli@telpin.com.ar>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Syncing a file's metadata in a portable way
Date: Fri, 9 Jul 2004 02:39:48 -0700 [thread overview]
Message-ID: <20040709023948.59497dca.akpm@osdl.org> (raw)
In-Reply-To: <20040709030637.GB5858@telpin.com.ar>
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.
next prev parent reply other threads:[~2004-07-09 9:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-09 3:06 Syncing a file's metadata in a portable way Alberto Bertogli
2004-07-09 9:39 ` Andrew Morton [this message]
2004-07-10 11:54 ` bert hubert
2004-07-10 20:14 ` Andrew Morton
2004-07-11 10:27 ` bert hubert
2004-07-11 10:35 ` Andrew Morton
2004-07-11 14:19 ` Alberto Bertogli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040709023948.59497dca.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=albertogli@telpin.com.ar \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox