rename is idiotic (was Re: VFAT rename)

Albert D. Cahalan (acahalan@cs.uml.edu)
Mon, 17 May 1999 00:05:17 -0400 (EDT)


Alexander Viro writes:
> On Fri, 14 May 1999, A. Wik wrote:

>> It's impossible to rename a file on a VFAT filesystem if
>> the only difference between the old and new names is case
>> (eg. longfilename and LongFilename). The operation is
>> cancelled in fs/namei.c because the lookups return the
>> same dentry for both names. What would be the most
>> reasonable way to fix this?
>
> Get a time machine and go into '89. Then bring a clue to POSIX authors.
> In other words: it's POSIX-mandated behaviour. Bogus, but required.
> It's a feature. That is, an idiotic bug in standard. Nothing to do here.

First of all, vfat isn't even close to being POSIX. Why worry about one
more little glitch? Normal POSIX filesystems allow "touch me ; mv me mE".

Second of all, you are right about this being an idiotic bug.
Following what seems to be a UNIX tradition (dup2, wait3, wait4),
I propose the fix below. There might also be a "ren" shell builtin
that calls it.

RENAME2(2) Linux Programmer's Manual RENAME2(2)

NAME
rename2 - change the name or location of a file

SYNOPSIS
#include <unistd.h>
int rename2(const char *src, const char *dst, unsigned flags);

DESCRIPTION
The rename2 function renames a file, moving it between directories
if required. Symbolic links are followed for every path component
except the last. If the destination already exists, rename2 will fail.
Directories used as src need not be writable for ".." updates.

The flags argument modifies rename2 behavior according to these bits:

R2_CLOBBER
If dst already exists, unlink it atomically during rename2.

R2_MKDIR
Create any directories needed by the dst argument. This includes
directories which are specified by symbolic links in dst.

R2_NOSRCLINK
Do not follow symbolic links for src.

R2_NODSTLINK
Do not follow symbolic links for dst.

R2_SRCLINK
Follow symbolic links for the last path component of src.

R2_DSTLINK
Follow symbolic links for the last path component of dst.

R2_WINWILD
Interpret wildcards. This is most useful when files reside on network
servers that use the SMB protocol, including Samba and Windows shares.

RETURN VALUE
On success, zero is returned. On error, an error code is returned.

ERRORS
Blah, blah, blah...

CONFORMING TO
Linux

SEE ALSO
rename(2), link(2), unlink(2), symlink(2), mv(1), link(8)

Linux 2.3.4 27 May 1999 2

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/