Skip to content

sg_httpupld_save_as(): Error "Invalid cross-device link" #27

@silvioprog

Description

@silvioprog

Hello.

Supposing a directory /tmp/ at sda1 was set to the "uploads dir" and the function sg_httpupld_save_as() tries to save a uploaded file in any directory at sda2, it raises "Invalid cross-device link", because it uses rename() internally, that returns an EXDEV if the oldpath and newpath are not on the same mounted file system (see rename(3) at man pages).

It is very common to see ARM-based OSes mounted in SD cards but saving files to external hard disks, thus, we should consider a low-level file-copy in Sagui, avoiding possible slow file-copy functions provided by the application.

cheers

Edit 1: (Linux only)

On Linux, kernel-level functions like copy_file_range() and sendfile() must be considered. Those system calls performs an in-kernel copy between two file descriptors. Because this copying is done within the kernel, is more efficient than the combination of read() and write(), which would require transferring data to and from user space.

Two quotes:

copy_file_range():

The copy_file_range() system call first appeared in Linux 4.5, but glibc 2.27 provides a user-space emulation when it is not available.

sendfile():

The original Linux sendfile() system call was not designed to handle large file offsets. Consequently, Linux 2.4 added sendfile64(), with a wider type for the offset argument. The glibc sendfile() wrapper function transparently deals with the kernel differences.

Applications may wish to fall back to read()/write() in the case where sendfile() fails with EINVAL or ENOSYS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions