Using rename() across file systems - Unix

This is a discussion on Using rename() across file systems - Unix ; 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. ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Using rename() across file systems

  1. Using rename() across file systems

    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


  2. Re: Using rename() across file systems

    On Fri, 26 Oct 2007 10:24:24 -0000, JH Trauntvein
    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

  3. Re: Using rename() across file systems

    JH Trauntvein 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.

  4. Re: Using rename() across file systems

    On Oct 26, 7:01 am, Rainer Weikusat wrote:
    > JH Trauntvein 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


  5. Using rename() across file systems

    JHT> I am working on an application that can transfer a file
    JHT> over a potentially slow link and, when the transfer has
    JHT> successfully completed, copies the file from a
    JHT> temporary file that was created for this purpose to its
    JHT> final destination. I am using the rename() function to
    JHT> do this final step.

    That's a move, not a copy.

    JHT> I have read in "Advanced Unix Programming" by Marc
    JHT> Rochkind that rename will not work if the source and
    JHT> destination reside on different file systems. [...]
    JHT> [...] my intention is to have my own function detect
    JHT> this by calling statvfs() for the source name and the
    JHT> name of the parent in the destination and comparing
    JHT> the f_fsid member of the resulting structures. [...]

    Why make life so hard for yourself? Put the temporary file in the
    same directory as the final location, and stop worrying about
    different filesystems. If renaming a file from one name to another
    within a single directory would cross filesystems, then you are
    probably using something very unusual (such as stacked filesystems)
    and as such probably have other, more serious, design issues to
    contend with first. (-:


+ Reply to Thread