All of lore.kernel.org
 help / color / mirror / Atom feed
From: Artem Bityutskiy <dedekind1@gmail.com>
To: Jon Povey <Jon.Povey@racelogic.co.uk>
Cc: linux-mtd <linux-mtd@lists.infradead.org>
Subject: Re: UBIFS question, atomic file create/rename semantics
Date: Mon, 04 Apr 2011 11:59:24 +0300	[thread overview]
Message-ID: <1301907564.2760.44.camel@localhost> (raw)
In-Reply-To: <70E876B0EA86DD4BAF101844BC814DFE093FAFC247@Cloud.RL.local>

Hi,

On Mon, 2011-04-04 at 09:54 +0100, Jon Povey wrote:
> I have a file I want to create on first-time boot on my system,
> on UBIFS. It's done in a shell script, and the logic is something like
> 
> if [ ! -e $FILE ]
> then
>         # create the file
> fi
> 
> Once or twice this file has turned out to be zero length (or possibly
> contain nulls, I am working on slightly vauge reports).
> 
> Looking into the issues of sync and semantics, I think this is related
> to not doing sync and rename.
> The script was pretty much just saying "prog > $FILE" and no sync.
> 
> I came up with the following and would appreciate any comments about
> how reliable this should be:
> 
> if [ ! -e $FILE ]
> then
>         prog > $FILE.tmp
>         sync
>         mv $FILE.tmp $FILE
>         sync
> fi
> 
> My understanding is that as the .tmp file is on the same filesystem
> and I ran sync, the mv means the final file atomically either exists
> with full correct contents, or will not exist at all (after surprise
> power cycle during the process).
> 
> A quick "yes, fine" or "won't work" would be appreciated.

It does not mean you should trust me and not test that, but I think
"yes", your sequence should make it.

-- 
Best Regards,
Artem Bityutskiy (Артём Битюцкий)

  reply	other threads:[~2011-04-04  9:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-04  8:54 UBIFS question, atomic file create/rename semantics Jon Povey
2011-04-04  8:59 ` Artem Bityutskiy [this message]
2011-04-04  9:10   ` Jon Povey

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=1301907564.2760.44.camel@localhost \
    --to=dedekind1@gmail.com \
    --cc=Jon.Povey@racelogic.co.uk \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.