Home > Archive > Unix Programming > October 2007 > Using rename() across file systems
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Using rename() across file systems
|
|
| JH Trauntvein 2007-10-26, 8:07 am |
| 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.
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?
Regards,
Jon Trauntvein
| |
| Keith Willis 2007-10-26, 8:07 am |
| On Fri, 26 Oct 2007 10:24:24 -0000, JH Trauntvein
<j.trauntvein@comcast.net> wrote:
>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.
Well on Solaris 10 (aka SunOS 5.10) the man page says in the ERRORS
section:
EXDEV The links named by 'old' and 'new' are on different file
systems.
HTH
--
PGP key ID 0xEB7180EC
| |
| Rainer Weikusat 2007-10-26, 8:07 am |
| JH Trauntvein <j.trauntvein@comcast.net> 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.
| |
|
| On Oct 26, 7:01 am, Rainer Weikusat <rweiku...@mssgmbh.com> wrote:
> JH Trauntvein <j.trauntv...@comcast.net> writes:
>
> 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')
>
>
> 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
|
|
|
|
|