Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
silvioprog opened this issue Apr 26, 2019 · 1 comment
Open

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

silvioprog opened this issue Apr 26, 2019 · 1 comment
Labels

Comments

@silvioprog
Copy link
Member

silvioprog commented Apr 26, 2019

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.

@DomenicoMammola
Copy link

DomenicoMammola commented Jun 26, 2024

Got the same problem with a micro-server app (made with brookframework) running on ubuntu 24.04 (destination folder is on a secondary disk)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants