Re: Using rename() across file systems
- From: Jon <jon@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 26 Oct 2007 08:13:50 -0700
On Oct 26, 7:01 am, Rainer Weikusat <rweiku...@xxxxxxxxxxx> wrote:
JH Trauntvein <j.trauntv...@xxxxxxxxxxx> writes:
I am working on an application that can transfer a file over a
potentially slow link and, when the transfer has successfully
completed, copies the file from a temporary file that was created for
this purpose to its final destination. I am using the rename()
function to do this final step. I have read in "Advanced Unix
Programming" by Marc Rochkind that rename will not work if the source
and destination reside on different file systems. The man page for
rename(), however, is silent on the matter of different file systems
and Mr. Rochkind's remarks seem almost parenthetical. I would like to
confirm that the limitation actually exists.
This is implemenation defined, as of UNIX(*), cf
[EXDEV]
[CX] [Option Start] The links named by new and old are on
different file systems and the implementation does not support
links between file systems. [Option End]
(SUS, 'rename')
If this limitation actually does exist, my intention is to have my own
function detect this by calling statvfs() for the source name and the
name of the parent in the destination and comparing the f_fsid member
of the resulting structures. If this value is different, i assume
that the file systems are different and I will have to do a copy
operation instead. Is this assumption correct?
This would again depend on the implementation, namely, on what exactly
constitutes a 'file system id'. I suggest a simpler method: Try to
rename and if this fails with EXDEV, copy.
I have some code that punts with system("mv ...") in the case that
EXDEV is
returned. Seems reliable for our application which archives to an NFS-
mounted
filesystem. Mixed environment of AIX, Solaris, various flavors of
Linux, an
HP running Windows Server running an NFS server.
Regards,
Jon
.
- References:
- Using rename() across file systems
- From: JH Trauntvein
- Re: Using rename() across file systems
- From: Rainer Weikusat
- Using rename() across file systems
- Prev by Date: web server design
- Next by Date: FreeBSD locales
- Previous by thread: Re: Using rename() across file systems
- Next by thread: Using rename() across file systems
- Index(es):
Relevant Pages
|