Skip to content

Commit 821eeae

Browse files
fsverity: use correct type for opcode const
This is u32 on amd64 but on other systems (ppe64le, s390x) it has a different type. The correct definition is in rustix::ioctl::Opcode, so use that instead. Also make better use of `use` in the src/fsverity/ioctl.rs. Signed-off-by: Allison Karlitskaya <[email protected]>
1 parent be2cd13 commit 821eeae

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/fsverity/ioctl.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
use core::mem::size_of;
2+
13
use std::{io::Error, os::fd::AsFd};
24

3-
use rustix::io::Errno;
4-
use rustix::ioctl;
5+
use rustix::{
6+
io::Errno,
7+
ioctl::{ioctl, opcode, Opcode, Setter, Updater},
8+
};
59

610
pub use super::{EnableVerityError, FsVerityHashValue, MeasureVerityError};
711

@@ -21,7 +25,7 @@ struct FsVerityEnableArg {
2125
}
2226

2327
// #define FS_IOC_ENABLE_VERITY _IOW('f', 133, struct fsverity_enable_arg)
24-
const FS_IOC_ENABLE_VERITY: u32 = ioctl::opcode::write::<FsVerityEnableArg>(b'f', 133);
28+
const FS_IOC_ENABLE_VERITY: Opcode = opcode::write::<FsVerityEnableArg>(b'f', 133);
2529

2630
/// Enable fsverity on the target file. This is a thin safe wrapper for the underlying base `ioctl`
2731
/// and hence all constraints apply such as requiring the file descriptor to already be `O_RDONLY`
@@ -30,9 +34,9 @@ pub(super) fn fs_ioc_enable_verity<H: FsVerityHashValue>(
3034
fd: impl AsFd,
3135
) -> Result<(), EnableVerityError> {
3236
unsafe {
33-
match ioctl::ioctl(
37+
match ioctl(
3438
fd,
35-
ioctl::Setter::<{ FS_IOC_ENABLE_VERITY }, FsVerityEnableArg>::new(FsVerityEnableArg {
39+
Setter::<{ FS_IOC_ENABLE_VERITY }, FsVerityEnableArg>::new(FsVerityEnableArg {
3640
version: 1,
3741
hash_algorithm: H::ALGORITHM as u32,
3842
block_size: 4096,
@@ -64,13 +68,13 @@ struct FsVerityDigest<F> {
6468
}
6569

6670
// #define FS_IOC_MEASURE_VERITY _IORW('f', 134, struct fsverity_digest)
67-
const FS_IOC_MEASURE_VERITY: u32 = ioctl::opcode::read_write::<FsVerityDigest<()>>(b'f', 134);
71+
const FS_IOC_MEASURE_VERITY: Opcode = opcode::read_write::<FsVerityDigest<()>>(b'f', 134);
6872

6973
/// Measure the fsverity digest of the provided file descriptor.
7074
pub(super) fn fs_ioc_measure_verity<H: FsVerityHashValue>(
7175
fd: impl AsFd,
7276
) -> Result<H, MeasureVerityError> {
73-
let digest_size = std::mem::size_of::<H>() as u16;
77+
let digest_size = size_of::<H>() as u16;
7478
let digest_algorithm = H::ALGORITHM as u16;
7579

7680
let mut digest = FsVerityDigest::<H> {
@@ -80,9 +84,9 @@ pub(super) fn fs_ioc_measure_verity<H: FsVerityHashValue>(
8084
};
8185

8286
let r = unsafe {
83-
ioctl::ioctl(
87+
ioctl(
8488
fd,
85-
ioctl::Updater::<{ FS_IOC_MEASURE_VERITY }, FsVerityDigest<H>>::new(&mut digest),
89+
Updater::<{ FS_IOC_MEASURE_VERITY }, FsVerityDigest<H>>::new(&mut digest),
8690
)
8791
};
8892
match r {

0 commit comments

Comments
 (0)