| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#; |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/::AsRawFdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/AsRawFd#; |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#; |
| 5 | |
| 6 | /// Clone a file using the FICLONE syscall |
| 7 | /// |
| 8 | /// This is mainly tested on the `btrfs` filesystem. |
| 9 | /// |
| 10 | /// For the details on the limitations of this method, see [`man 2 ioctl_ficlonerange`]. |
| 11 | /// |
| 12 | /// [`man 2 ioctl_ficlonerange`]: https://man7.org/linux/man-pages/man2/ioctl_ficlonerange.2.html |
| 13 | pub fn clone_filerust-analyzer cargo clone-file 0.1.0 linux/clone_file().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>, Q: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(src: P, dest: Q) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 14 | let src_file = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]open().(src)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 15 | let dest_file = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::optionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]options().() |
| 16 | .writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]write().(true) |
| 17 | .createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]create().(true) |
| 18 | .truncaterust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]truncate().(true) |
| 19 | .openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]open().(dest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 20 | |
| 21 | match unsafe { ioctlrust-analyzer cargo clone-file 0.1.0 linux/ioctl/::ficlonerust-analyzer cargo clone-file 0.1.0 linux/ioctl/ficlone().(dest_file.as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/impl#[`fs::File`][AsRawFd]as_raw_fd().(), src_file.as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/impl#[`fs::File`][AsRawFd]as_raw_fd().() as u64) } { |
| 22 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()), |
| 23 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::last_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]last_os_error().()), |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | /// Clone a range from a file using the FICLONERANGE syscall |
| 28 | /// |
| 29 | /// This is mainly tested on the `btrfs` filesystem. |
| 30 | /// |
| 31 | /// For the details on the limitations of this method, see [`man 2 ioctl_ficlonerange`]. |
| 32 | /// |
| 33 | /// One of the more common limitations is that `src_offset`, `src_length` and `dest_offset` |
| 34 | /// must be multiples of the filesystem block size. Expect this function to fail if that is not the case. |
| 35 | /// |
| 36 | /// [`man 2 ioctl_ficlonerange`]: https://man7.org/linux/man-pages/man2/ioctl_ficlonerange.2.html |
| 37 | pub fn clone_file_rangerust-analyzer cargo clone-file 0.1.0 linux/clone_file_range().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>, Q: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>( |
| 38 | src: P, |
| 39 | src_offset: u64, |
| 40 | src_length: u64, |
| 41 | dest: Q, |
| 42 | dest_offset: u64, |
| 43 | ) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 44 | let src_file = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]open().(src)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 45 | let dest_file = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::optionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]options().().writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]write().(true).createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]create().(true).openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[OpenOptions]open().(dest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 46 | |
| 47 | let args = ioctlrust-analyzer cargo clone-file 0.1.0 linux/ioctl/::FileCloneRangerust-analyzer cargo clone-file 0.1.0 linux/ioctl/FileCloneRange# { |
| 48 | src_fdrust-analyzer cargo clone-file 0.1.0 linux/ioctl/FileCloneRange#src_fd.: src_file.as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/impl#[`fs::File`][AsRawFd]as_raw_fd().() as i64, |
| 49 | src_offsetrust-analyzer cargo clone-file 0.1.0 linux/ioctl/FileCloneRange#src_offset., |
| 50 | src_lengthrust-analyzer cargo clone-file 0.1.0 linux/ioctl/FileCloneRange#src_length., |
| 51 | dest_offsetrust-analyzer cargo clone-file 0.1.0 linux/ioctl/FileCloneRange#dest_offset., |
| 52 | }; |
| 53 | |
| 54 | match unsafe { ioctlrust-analyzer cargo clone-file 0.1.0 linux/ioctl/::ficlonerangerust-analyzer cargo clone-file 0.1.0 linux/ioctl/ficlonerange().(dest_file.as_raw_fdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/fd/raw/impl#[`fs::File`][AsRawFd]as_raw_fd().(), &args) } { |
| 55 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()), |
| 56 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::last_os_errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]last_os_error().()), |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | mod ioctlrust-analyzer cargo clone-file 0.1.0 linux/ioctl/ { |
| 61 | pub struct FileCloneRangerust-analyzer cargo clone-file 0.1.0 linux/ioctl/FileCloneRange# { |
| 62 | pub src_fdrust-analyzer cargo clone-file 0.1.0 linux/ioctl/FileCloneRange#src_fd.: i64, |
| 63 | pub src_offsetrust-analyzer cargo clone-file 0.1.0 linux/ioctl/FileCloneRange#src_offset.: u64, |
| 64 | pub src_lengthrust-analyzer cargo clone-file 0.1.0 linux/ioctl/FileCloneRange#src_length.: u64, |
| 65 | pub dest_offsetrust-analyzer cargo clone-file 0.1.0 linux/ioctl/FileCloneRange#dest_offset.: u64, |
| 66 | } |
| 67 | |
| 68 | nixrust-analyzer cargo nix 0.31.3 crate/::ioctl_write_intrust-analyzer cargo nix 0.31.3 sys/ioctl/ioctl_write_int!!(ficlonerust-analyzer cargo clone-file 0.1.0 linux/ioctl/ficlone()., 0x94, 9); |
| 69 | nixrust-analyzer cargo nix 0.31.3 crate/::ioctl_write_ptrrust-analyzer cargo nix 0.31.3 sys/ioctl/ioctl_write_ptr!!(ficlonerangerust-analyzer cargo clone-file 0.1.0 linux/ioctl/ficlonerange()., 0x94, 13, FileCloneRangerust-analyzer cargo clone-file 0.1.0 linux/ioctl/FileCloneRange#); |
| 70 | } |