From: "J.A. Magallón" <jamagallon@ono.com>
To: Ketil Froyn <ketil@froyn.name>
Cc: linux-kernel@vger.kernel.org
Subject: Re: unexpected rename() behaviour
Date: Sat, 29 Mar 2008 01:16:56 +0100 [thread overview]
Message-ID: <20080329011656.7c38265a@werewolf> (raw)
In-Reply-To: <47ED8858.9000401@froyn.name>
On Sat, 29 Mar 2008 01:07:52 +0100, Ketil Froyn <ketil@froyn.name> wrote:
> Hi,
>
> The following behaviour was unexpected (tested on Debian/ext3):
>
> $ echo 1 > 1
> $ ln 1 2
> $ cat 2
> 1
> $ ./rename 2 1
> $ echo $?
> 0
> $ cat 2
> 1
>
> The code for ./rename is simple:
>
> ---
> /* compile: gcc -o rename rename.c */
> #include <stdio.h>
> int main(int argc, char *argv[]) { return rename(argv[1], argv[2]); }
> ---
>
> I thought this must be wrong behaviour, but I have been unable to
> confirm what the correct result should be in this special case. rename()
> returns success, but the source file is intact, which seems odd. The
> "mv" command specifically checks for cases like this and calls
> unlink("2") instead of rename("2", "1"). Are all applications meant to
> do this? What standards describe what rename() should do in cases like this?
>
man 2 rename:
If oldpath and newpath are existing hard links referring to the same
file, then rename() does nothing, and returns a success status.
That's why mv checks the special case.
--
J.A. Magallon <jamagallon()ono!com> \ Software is like sex:
\ It's better when it's free
Mandriva Linux release 2008.1 (Cooker) for i586
Linux 2.6.23-jam05 (gcc 4.2.2 20071128 (4.2.2-2mdv2008.1)) SMP PREEMPT
next prev parent reply other threads:[~2008-03-29 0:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-29 0:07 unexpected rename() behaviour Ketil Froyn
2008-03-29 0:16 ` J.A. Magallón [this message]
2008-03-29 10:56 ` Ketil Froyn
2008-03-29 12:36 ` Andreas Schwab
2008-03-29 12:57 ` David Newall
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=20080329011656.7c38265a@werewolf \
--to=jamagallon@ono.com \
--cc=ketil@froyn.name \
--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 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.