mirror of
https://github.com/uutils/coreutils
synced 2024-12-13 23:02:38 +00:00
Merge pull request #3614 from sylvestre/rm-ioctl
cp: Replace ioctl-sys by libc for the call to ficlone
This commit is contained in:
commit
5920de5adc
3 changed files with 14 additions and 18 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -995,12 +995,6 @@ dependencies = [
|
|||
"cfg-if 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ioctl-sys"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8bd11f3a29434026f5ff98c730b668ba74b1033637b8817940b54d040696133c"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.10.3"
|
||||
|
@ -2229,7 +2223,6 @@ dependencies = [
|
|||
"clap 3.1.18",
|
||||
"exacl",
|
||||
"filetime",
|
||||
"ioctl-sys",
|
||||
"libc",
|
||||
"quick-error",
|
||||
"selinux",
|
||||
|
|
|
@ -27,9 +27,6 @@ selinux = { version="0.2", optional=true }
|
|||
uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["entries", "fs", "perms", "mode"] }
|
||||
walkdir = "2.2"
|
||||
|
||||
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
|
||||
ioctl-sys = "0.8"
|
||||
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
winapi = { version="0.3", features=["fileapi"] }
|
||||
|
||||
|
|
|
@ -10,9 +10,6 @@
|
|||
|
||||
// spell-checker:ignore (ToDO) ficlone linkgs lstat nlink nlinks pathbuf reflink strs xattrs symlinked
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
#[macro_use]
|
||||
extern crate ioctl_sys;
|
||||
#[macro_use]
|
||||
extern crate quick_error;
|
||||
#[macro_use]
|
||||
|
@ -61,9 +58,6 @@ use uucore::error::{set_exit_code, ExitCode, UClapError, UError, UResult};
|
|||
use uucore::fs::{canonicalize, MissingHandling, ResolveMode};
|
||||
use walkdir::WalkDir;
|
||||
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
ioctl!(write ficlone with 0x94, 9; std::os::raw::c_int);
|
||||
|
||||
quick_error! {
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
|
@ -230,6 +224,16 @@ pub struct Options {
|
|||
verbose: bool,
|
||||
}
|
||||
|
||||
// From /usr/include/linux/fs.h:
|
||||
// #define FICLONE _IOW(0x94, 9, int)
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
// Use a macro as libc::ioctl expects u32 or u64 depending on the arch
|
||||
macro_rules! FICLONE {
|
||||
() => {
|
||||
0x40049409
|
||||
};
|
||||
}
|
||||
|
||||
static ABOUT: &str = "Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.";
|
||||
static LONG_HELP: &str = "";
|
||||
static EXIT_ERR: i32 = 1;
|
||||
|
@ -1567,7 +1571,8 @@ fn copy_on_write_linux(
|
|||
.context(context)?;
|
||||
match mode {
|
||||
ReflinkMode::Always => unsafe {
|
||||
let result = ficlone(dst_file.as_raw_fd(), src_file.as_raw_fd() as *const i32);
|
||||
let result = libc::ioctl(dst_file.as_raw_fd(), FICLONE!(), src_file.as_raw_fd());
|
||||
|
||||
if result != 0 {
|
||||
Err(format!(
|
||||
"failed to clone {:?} from {:?}: {}",
|
||||
|
@ -1581,7 +1586,8 @@ fn copy_on_write_linux(
|
|||
}
|
||||
},
|
||||
ReflinkMode::Auto => unsafe {
|
||||
let result = ficlone(dst_file.as_raw_fd(), src_file.as_raw_fd() as *const i32);
|
||||
let result = libc::ioctl(dst_file.as_raw_fd(), FICLONE!(), src_file.as_raw_fd());
|
||||
|
||||
if result != 0 {
|
||||
fs::copy(source, dest).context(context)?;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue