1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 03:57:44 +00:00

Merge pull request #7439 from dezgeg/ficlone

cp: Use FICLONE ioctl constant from linux-raw-sys
This commit is contained in:
Sylvestre Ledru 2025-03-14 09:59:36 +01:00 committed by GitHub
commit d570512bdc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 12 additions and 10 deletions

1
Cargo.lock generated
View file

@ -2616,6 +2616,7 @@ dependencies = [
"filetime",
"indicatif",
"libc",
"linux-raw-sys 0.9.2",
"quick-error",
"selinux",
"uucore",

View file

@ -303,6 +303,7 @@ iana-time-zone = "0.1.57"
indicatif = "0.17.8"
itertools = "0.14.0"
libc = "0.2.153"
linux-raw-sys = "0.9"
lscolors = { version = "0.20.0", default-features = false, features = [
"gnu_legacy",
] }

View file

@ -24,6 +24,7 @@ path = "src/cp.rs"
clap = { workspace = true }
filetime = { workspace = true }
libc = { workspace = true }
linux-raw-sys = { workspace = true }
quick-error = { workspace = true }
selinux = { workspace = true, optional = true }
uucore = { workspace = true, features = [

View file

@ -20,15 +20,6 @@ use uucore::mode::get_umask;
use crate::{CopyDebug, CopyResult, OffloadReflinkDebug, ReflinkMode, SparseDebug, SparseMode};
// From /usr/include/linux/fs.h:
// #define FICLONE _IOW(0x94, 9, int)
// Use a macro as libc::ioctl expects u32 or u64 depending on the arch
macro_rules! FICLONE {
() => {
0x40049409
};
}
/// The fallback behavior for [`clone`] on failed system call.
#[derive(Clone, Copy)]
enum CloneFallback {
@ -70,7 +61,15 @@ where
let dst_file = File::create(&dest)?;
let src_fd = src_file.as_raw_fd();
let dst_fd = dst_file.as_raw_fd();
let result = unsafe { libc::ioctl(dst_fd, FICLONE!(), src_fd) };
// Using .try_into().unwrap() is required as glibc, musl & android all have different type for ioctl()
#[allow(clippy::unnecessary_fallible_conversions)]
let result = unsafe {
libc::ioctl(
dst_fd,
linux_raw_sys::ioctl::FICLONE.try_into().unwrap(),
src_fd,
)
};
if result == 0 {
return Ok(());
}