Skip to content

fdio: fix fd offset handling with `FICLONE`

Jonathan Lebon requested to merge jlebon/libglnx:pr/ficlone-fixes into master

When using FICLONE, the kernel does a full file clone and disregards the fd offsets. Users of this API however assume that it is offset-sensitive. So we need to verify that the fd offsets are at the start of the files before we call FICLONE. This was done in systemd also in:

https://github.com/systemd/systemd/commit/c622fbdb8d37

The commit message does not explain this but ioctl_ficlone(2) says:

The `FICLONE` ioctl clones entire files.

(Compare with FICLONERANGE, which takes a struct with offsets and the length).

Similarly, we need to seek to the end of the file descriptors on success so that we're consistent with the behaviour of the other backends available (copy_file_range, sendfile and manual copying). This also matches what systemd does nowadays:

https://github.com/systemd/systemd/blob/80f967311ac5/src/shared/copy.c#L199

Merge request reports