From: Jamie Lokier <jamie@shareable.org>
To: Artem Bityutskiy <dedekind@infradead.org>
Cc: linux-mtd@lists.infradead.org, Bruce_Leonard@selinc.com
Subject: Re: UBIFS sync question
Date: Thu, 2 Oct 2008 13:55:32 +0100 [thread overview]
Message-ID: <20081002125529.GA29028@shareable.org> (raw)
In-Reply-To: <1222839603.8051.16.camel@sauron>
Artem Bityutskiy wrote:
> However, if you open a file, and just add few lines to it, then it
> should not become empty after reboot. You should just loose whole or
> part of new data.
>
> I think you actually truncate the file, then re-write it, instead of
> appending. This often happens in case of shell scripts - shell commands
> like truncating files.
Generally when updating a file, then I write a new file under a
temporary name in the same directory, then fsync() the new file, then
rename() it over the original file, then fsync() the containing
directory.
That should be safe for any change to the file contents. After boot
during this process, you should see the old contents or the new
contents, nothing else. After the second fsync(), you should be
confident that any subsequent boot will always see the new contents.
O_APPEND should be ok too and is essential for log files, but there's
always a danger than after a boot in the middle of the update, you'll
see half the write.
-- Jamie
prev parent reply other threads:[~2008-10-02 12:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-30 22:28 UBIFS sync question Bruce_Leonard
2008-09-30 22:53 ` Bruce_Leonard
2008-10-01 5:40 ` Artem Bityutskiy
2008-10-01 17:06 ` Bruce_Leonard
2008-10-01 17:32 ` Josh Boyer
2008-10-01 17:40 ` Bruce_Leonard
2008-10-02 5:21 ` Artem Bityutskiy
2008-10-02 12:55 ` Jamie Lokier [this message]
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=20081002125529.GA29028@shareable.org \
--to=jamie@shareable.org \
--cc=Bruce_Leonard@selinc.com \
--cc=dedekind@infradead.org \
--cc=linux-mtd@lists.infradead.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