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

Implement copy_file_range() system call for Linux #941

Closed
ArniDagur opened this issue Sep 15, 2018 · 3 comments
Closed

Implement copy_file_range() system call for Linux #941

ArniDagur opened this issue Sep 15, 2018 · 3 comments

Comments

@ArniDagur
Copy link
Contributor

copy_file_range() has yet to be implemented.

@asomers
Copy link
Member

asomers commented Sep 15, 2018

If you're interested, feel free to submit a patch. Nix works 99% on user contributions.

@ArniDagur
Copy link
Contributor Author

ArniDagur commented Sep 16, 2018

How I should handle the flags argument of copy_file_range? The man page says that "the flags argument is provided to allow for future extensions and currently must be to 0".

Here's what I've got at the moment (haven't tested it yet but it compiles):

#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn copy_file_range(fd_in: RawFd, off_in: Option<&mut libc::loff_t>,
          fd_out: RawFd, off_out: Option<&mut libc::loff_t>,
          len: usize) -> Result<usize> {
    let off_in = off_in.map(|offset| offset as *mut _).unwrap_or(ptr::null_mut());
    let off_out = off_out.map(|offset| offset as *mut _).unwrap_or(ptr::null_mut());

    let ret = unsafe {
        libc::syscall(libc::SYS_copy_file_range, fd_in, off_in, fd_out, off_out, len, 0 )
    };
    Errno::result(ret).map(|r| r as usize)
}

I just leave out the flags argument, but this is not good for forwards compatibility.

@asomers
Copy link
Member

asomers commented Sep 16, 2018

There are two choices:

  1. Leave out the flags argument as you did.
  2. Create a CopyFileRangeFlags enum with a single None variant.

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

Successfully merging a pull request may close this issue.

3 participants