diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
commit | c23a457e72abe608715ac76f076f47dc42af07a5 (patch) | |
tree | 2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/rustix/src/fs/ioctl.rs | |
parent | Releasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/src/fs/ioctl.rs')
-rw-r--r-- | vendor/rustix/src/fs/ioctl.rs | 52 |
1 files changed, 47 insertions, 5 deletions
diff --git a/vendor/rustix/src/fs/ioctl.rs b/vendor/rustix/src/fs/ioctl.rs index 28e0c8588..75222752f 100644 --- a/vendor/rustix/src/fs/ioctl.rs +++ b/vendor/rustix/src/fs/ioctl.rs @@ -1,11 +1,17 @@ //! Filesystem-oriented `ioctl` functions. +#![allow(unsafe_code)] + #[cfg(linux_kernel)] use { crate::fd::AsFd, - crate::{backend, io}, + crate::{backend, io, ioctl}, + backend::c, }; +#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))] +use crate::fd::{AsRawFd, BorrowedFd}; + /// `ioctl(fd, BLKSSZGET)`—Returns the logical block size of a block device. /// /// This is mentioned in the [Linux `openat` manual page]. @@ -15,7 +21,11 @@ use { #[inline] #[doc(alias = "BLKSSZGET")] pub fn ioctl_blksszget<Fd: AsFd>(fd: Fd) -> io::Result<u32> { - backend::fs::syscalls::ioctl_blksszget(fd.as_fd()) + // SAFETY: BLZSSZGET is a getter opcode that gets a u32. + unsafe { + let ctl = ioctl::Getter::<ioctl::BadOpcode<{ c::BLKSSZGET }>, c::c_uint>::new(); + ioctl::ioctl(fd, ctl) + } } /// `ioctl(fd, BLKPBSZGET)`—Returns the physical block size of a block device. @@ -23,7 +33,11 @@ pub fn ioctl_blksszget<Fd: AsFd>(fd: Fd) -> io::Result<u32> { #[inline] #[doc(alias = "BLKPBSZGET")] pub fn ioctl_blkpbszget<Fd: AsFd>(fd: Fd) -> io::Result<u32> { - backend::fs::syscalls::ioctl_blkpbszget(fd.as_fd()) + // SAFETY: BLKPBSZGET is a getter opcode that gets a u32. + unsafe { + let ctl = ioctl::Getter::<ioctl::BadOpcode<{ c::BLKPBSZGET }>, c::c_uint>::new(); + ioctl::ioctl(fd, ctl) + } } /// `ioctl(fd, FICLONE, src_fd)`—Share data between open files. @@ -38,7 +52,7 @@ pub fn ioctl_blkpbszget<Fd: AsFd>(fd: Fd) -> io::Result<u32> { #[inline] #[doc(alias = "FICLONE")] pub fn ioctl_ficlone<Fd: AsFd, SrcFd: AsFd>(fd: Fd, src_fd: SrcFd) -> io::Result<()> { - backend::fs::syscalls::ioctl_ficlone(fd.as_fd(), src_fd.as_fd()) + unsafe { ioctl::ioctl(fd, Ficlone(src_fd.as_fd())) } } /// `ioctl(fd, EXT4_IOC_RESIZE_FS, blocks)`—Resize ext4 filesystem on fd. @@ -46,5 +60,33 @@ pub fn ioctl_ficlone<Fd: AsFd, SrcFd: AsFd>(fd: Fd, src_fd: SrcFd) -> io::Result #[inline] #[doc(alias = "EXT4_IOC_RESIZE_FS")] pub fn ext4_ioc_resize_fs<Fd: AsFd>(fd: Fd, blocks: u64) -> io::Result<()> { - backend::fs::syscalls::ext4_ioc_resize_fs(fd.as_fd(), blocks) + // SAFETY: EXT4_IOC_RESIZE_FS is a pointer setter opcode. + unsafe { + let ctl = ioctl::Setter::<ioctl::BadOpcode<{ backend::fs::EXT4_IOC_RESIZE_FS }>, u64>::new( + blocks, + ); + ioctl::ioctl(fd, ctl) + } +} + +#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))] +struct Ficlone<'a>(BorrowedFd<'a>); + +#[cfg(all(linux_kernel, not(any(target_arch = "sparc", target_arch = "sparc64"))))] +unsafe impl ioctl::Ioctl for Ficlone<'_> { + type Output = (); + + const IS_MUTATING: bool = false; + const OPCODE: ioctl::Opcode = ioctl::Opcode::old(c::FICLONE as ioctl::RawOpcode); + + fn as_ptr(&mut self) -> *mut c::c_void { + self.0.as_raw_fd() as *mut c::c_void + } + + unsafe fn output_from_ptr( + _: ioctl::IoctlOutput, + _: *mut c::c_void, + ) -> io::Result<Self::Output> { + Ok(()) + } } |