Re: Using rename() across file systems



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

.



Relevant Pages

  • Using rename() across file systems
    ... Programming" by Marc Rochkind that rename will not work if the source ... and destination reside on different file systems. ... If this limitation actually does exist, my intention is to have my own ...
    (comp.unix.programmer)
  • Re: Using rename() across file systems
    ... potentially slow link and, ... Programming" by Marc Rochkind that rename will not work if the source ... and destination reside on different file systems. ...
    (comp.unix.programmer)
  • Re: Using rename() across file systems
    ... this purpose to its final destination. ... Programming" by Marc Rochkind that rename will not work if the source ... and destination reside on different file systems. ...
    (comp.unix.programmer)
  • Re: Robocopy repeatedly updates files on remote server
    ... everytime it syncs the source and destination even though the files ... the destination serves as a backup repository. ... This happens when the granularity of the date/time stamp of the ... two file systems is not the same. ...
    (microsoft.public.windowsxp.general)