Merge pull request #3614 from sylvestre/rm-ioctl

cp: Replace ioctl-sys by libc for the call to ficlone
This commit is contained in:
Sylvestre Ledru 2022-06-15 09:07:44 +02:00 committed by GitHub
commit 5920de5adc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 18 deletions

7
Cargo.lock generated
View file

@ -995,12 +995,6 @@ dependencies = [
"cfg-if 1.0.0", "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]] [[package]]
name = "itertools" name = "itertools"
version = "0.10.3" version = "0.10.3"
@ -2229,7 +2223,6 @@ dependencies = [
"clap 3.1.18", "clap 3.1.18",
"exacl", "exacl",
"filetime", "filetime",
"ioctl-sys",
"libc", "libc",
"quick-error", "quick-error",
"selinux", "selinux",

View file

@ -27,9 +27,6 @@ selinux = { version="0.2", optional=true }
uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["entries", "fs", "perms", "mode"] } uucore = { version=">=0.0.11", package="uucore", path="../../uucore", features=["entries", "fs", "perms", "mode"] }
walkdir = "2.2" walkdir = "2.2"
[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies]
ioctl-sys = "0.8"
[target.'cfg(target_os = "windows")'.dependencies] [target.'cfg(target_os = "windows")'.dependencies]
winapi = { version="0.3", features=["fileapi"] } winapi = { version="0.3", features=["fileapi"] }

View file

@ -10,9 +10,6 @@
// spell-checker:ignore (ToDO) ficlone linkgs lstat nlink nlinks pathbuf reflink strs xattrs symlinked // 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] #[macro_use]
extern crate quick_error; extern crate quick_error;
#[macro_use] #[macro_use]
@ -61,9 +58,6 @@ use uucore::error::{set_exit_code, ExitCode, UClapError, UError, UResult};
use uucore::fs::{canonicalize, MissingHandling, ResolveMode}; use uucore::fs::{canonicalize, MissingHandling, ResolveMode};
use walkdir::WalkDir; use walkdir::WalkDir;
#[cfg(any(target_os = "linux", target_os = "android"))]
ioctl!(write ficlone with 0x94, 9; std::os::raw::c_int);
quick_error! { quick_error! {
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
@ -230,6 +224,16 @@ pub struct Options {
verbose: bool, 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 ABOUT: &str = "Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.";
static LONG_HELP: &str = ""; static LONG_HELP: &str = "";
static EXIT_ERR: i32 = 1; static EXIT_ERR: i32 = 1;
@ -1567,7 +1571,8 @@ fn copy_on_write_linux(
.context(context)?; .context(context)?;
match mode { match mode {
ReflinkMode::Always => unsafe { 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 { if result != 0 {
Err(format!( Err(format!(
"failed to clone {:?} from {:?}: {}", "failed to clone {:?} from {:?}: {}",
@ -1581,7 +1586,8 @@ fn copy_on_write_linux(
} }
}, },
ReflinkMode::Auto => unsafe { 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 { if result != 0 {
fs::copy(source, dest).context(context)?; fs::copy(source, dest).context(context)?;
} }