How difficult is it to move a file quickly?Richard Mawhttp://yakking.branchable.com/posts/moving-files-3-faster/yakkingikiwiki2017-08-21T10:13:12Zsplice and portabilityhttp://yakking.branchable.com/posts/moving-files-3-faster/comment_1_41bf6b8f220ba4a3325479618517be41/Gravious2017-08-17T21:09:09Z2017-02-26T18:55:58Z
<p>Pretty cool stuff!</p>
<p>Two things occur to me though, the first is that according to my man page, for splice(2) to be applicable one of the fds has to be a pipe, which probably rules it out for file copying. The second is that none of these calls seem to be standard, they're linux specific and my man pages here suggest that prototypes and semantics differ across platforms such that these calls can't be used portably. This makes me wonder whether ENOSYS is really useful here, since if we write code using these calls then we're already presumably tied to a particular platform (linux), so we can safely assume these calls are implemented?</p>
Re: splice and portabilityhttp://yakking.branchable.com/posts/moving-files-3-faster/comment_2_9640d160f32196a7530eb5d7f90f6935/Richard Maw2017-08-21T10:13:12Z2017-08-21T10:13:11Z
<p>Yeah, splice is included because at the time I had the notion of writing a generic copy routine between two file descriptors.</p>
<p>We're assuming Linux, but with some flexibility of which version.</p>
<ul>
<li>sendfile was introduced in Linux 2.2, but the output file descriptor must be a socket. Since 2.6.33 it may be any file.</li>
<li>splice was introduced in Linux 2.6.17 and might some day support any file descriptor.</li>
<li><code>copy_file_range</code> was introduced in Linux 4.5</li>
</ul>
<p>Checking versions would be inappropriate since you see frankenkernels where newer features have been back-ported, and sometimes system calls are optional, depending on kernel configuration, such as <code>name_to_handle_at</code>.</p>