linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: unlisted-recipients:; (no To-header on input)
Cc: "Pádraig Brady" <P@draigBrady.com>,
	"Denys Vlasenko" <vda.linux@googlemail.com>,
	"Al Viro" <viro@zeniv.linux.org.uk>,
	Coreutils <coreutils@gnu.org>,
	"Christian Engelmayer" <christian.engelmayer@frequentis.com>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: rename("a", "b") would not always remove "a" on success. ?!!
Date: Fri, 28 Oct 2011 09:58:27 -0600	[thread overview]
Message-ID: <4EAAD123.6020208@redhat.com> (raw)
In-Reply-To: <4EAACD51.5060703@redhat.com>

On 10/28/2011 09:42 AM, Eric Blake wrote:
>> Perhaps it could be brought up as an issue with the standards guys?
>
> We already have. And POSIX 2008 already acted on that. While you quoted
> rename(2) (which was intentionally not changed), you forgot to also read
> the POSIX wording on mv(1):
>
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/mv.html
>
> 2. If the source_file operand and destination path name the same
> existing file, then the destination path shall not be removed, and one
> of the following shall occur:
>
> a. No change is made to source_file, no error occurs, and no diagnostic
> is issued.
> b. No change is made to source_file, a diagnostic is issued to standard
> error identifying the two names, and the exit status is affected.
> c. If the source_file operand and destination path name distinct
> directory entries, then the source_file operand is removed, no error
> occurs, and no diagnostic is issued.

Contrast this to the POSIX 2001 wording for mv:

http://pubs.opengroup.org/onlinepubs/009695399/utilities/mv.html

2. The mv utility shall perform actions equivalent to the rename() 
function defined in the System Interfaces volume of IEEE Std 1003.1-2001,...

with no escape clause for identical files.  That is, POSIX 2008 
specifically inserted a new step 2 (renumbering the step 2 from POSIX 
2001 to step 3 in POSIX 2008) at GNU Coreutils' insistence that the 
requirements were wrong.  See also 
http://www.opengroup.org/austin/aardvark/latest/xcubug2.txt, and search 
for AI-169, which was where the change in wording was made; including 
this rationale:

  Note that ERN 88 was rejected in spite of the fact that
  http://www.opengroup.org/austin/mailarchives/austin-group-l/msg05155.html
  claims the original intent was to have rename detect identical
  directory entries rather than identical files.  One of the arguments
  presented for rejecting ERN 88 was that rename(2) has the property
  of preserving link count, whereas having rename("a", "b") unlink
  "a" when the two names are hard links would not.

Unfortunately, that link no longer works, so I can't point you to the 
historical conversation at the time where it was argued that changing 
rename(2) behavior would be detrimental.  But it does give enough 
context to provide an alternate interpretation of rename() semantics 
that fit the standardized behavior:  a successful rename("a","b") 
guarantees that "b" now has the same link count as "a" had prior to the 
rename call, even if that meant a hard-linked "a" had to be left 
untouched to avoid changing the link count of hard-linked "b".

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

  reply	other threads:[~2011-10-28 15:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-28 15:25 rename("a", "b") would not always remove "a" on success. ?!! Denys Vlasenko
2011-10-28 15:32 ` Pádraig Brady
2011-10-28 15:42   ` Eric Blake
2011-10-28 15:58     ` Eric Blake [this message]
2011-10-29  1:00     ` Denys Vlasenko
2011-10-29  1:19       ` richard -rw- weinberger

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=4EAAD123.6020208@redhat.com \
    --to=eblake@redhat.com \
    --cc=P@draigBrady.com \
    --cc=christian.engelmayer@frequentis.com \
    --cc=coreutils@gnu.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vda.linux@googlemail.com \
    --cc=viro@zeniv.linux.org.uk \
    /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;
as well as URLs for NNTP newsgroup(s).