mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Merge pull request #7439 from dezgeg/ficlone
cp: Use FICLONE ioctl constant from linux-raw-sys
This commit is contained in:
commit
d570512bdc
4 changed files with 12 additions and 10 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2616,6 +2616,7 @@ dependencies = [
|
||||||
"filetime",
|
"filetime",
|
||||||
"indicatif",
|
"indicatif",
|
||||||
"libc",
|
"libc",
|
||||||
|
"linux-raw-sys 0.9.2",
|
||||||
"quick-error",
|
"quick-error",
|
||||||
"selinux",
|
"selinux",
|
||||||
"uucore",
|
"uucore",
|
||||||
|
|
|
@ -303,6 +303,7 @@ iana-time-zone = "0.1.57"
|
||||||
indicatif = "0.17.8"
|
indicatif = "0.17.8"
|
||||||
itertools = "0.14.0"
|
itertools = "0.14.0"
|
||||||
libc = "0.2.153"
|
libc = "0.2.153"
|
||||||
|
linux-raw-sys = "0.9"
|
||||||
lscolors = { version = "0.20.0", default-features = false, features = [
|
lscolors = { version = "0.20.0", default-features = false, features = [
|
||||||
"gnu_legacy",
|
"gnu_legacy",
|
||||||
] }
|
] }
|
||||||
|
|
|
@ -24,6 +24,7 @@ path = "src/cp.rs"
|
||||||
clap = { workspace = true }
|
clap = { workspace = true }
|
||||||
filetime = { workspace = true }
|
filetime = { workspace = true }
|
||||||
libc = { workspace = true }
|
libc = { workspace = true }
|
||||||
|
linux-raw-sys = { workspace = true }
|
||||||
quick-error = { workspace = true }
|
quick-error = { workspace = true }
|
||||||
selinux = { workspace = true, optional = true }
|
selinux = { workspace = true, optional = true }
|
||||||
uucore = { workspace = true, features = [
|
uucore = { workspace = true, features = [
|
||||||
|
|
|
@ -20,15 +20,6 @@ use uucore::mode::get_umask;
|
||||||
|
|
||||||
use crate::{CopyDebug, CopyResult, OffloadReflinkDebug, ReflinkMode, SparseDebug, SparseMode};
|
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.
|
/// The fallback behavior for [`clone`] on failed system call.
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
enum CloneFallback {
|
enum CloneFallback {
|
||||||
|
@ -70,7 +61,15 @@ where
|
||||||
let dst_file = File::create(&dest)?;
|
let dst_file = File::create(&dest)?;
|
||||||
let src_fd = src_file.as_raw_fd();
|
let src_fd = src_file.as_raw_fd();
|
||||||
let dst_fd = dst_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 {
|
if result == 0 {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue