Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose optimized fsverity interface to Rust #357

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions rust/composefs-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern "C" {
digest: *mut u8,
fd: std::os::raw::c_int,
) -> std::os::raw::c_int;
pub fn lcfs_fd_get_fsverity(digest: *mut u8, fd: std::os::raw::c_int) -> std::os::raw::c_int;
#[cfg(feature = "v1_0_4")]
pub fn lcfs_fd_enable_fsverity(fd: std::os::raw::c_int) -> std::os::raw::c_int;
}
Expand Down Expand Up @@ -42,21 +43,20 @@ mod tests {

#[test]
fn test_digest() -> Result<()> {
unsafe {
for f in [lcfs_compute_fsverity_from_fd, lcfs_fd_get_fsverity] {
let mut tf = tempfile::tempfile()?;
tf.write_all(b"hello world")?;
let mut buf = [0u8; LCFS_SHA256_DIGEST_LEN];
tf.seek(std::io::SeekFrom::Start(0))?;
let r = lcfs_compute_fsverity_from_fd(buf.as_mut_ptr(), tf.as_raw_fd());
assert_eq!(r, 0);
unsafe { f(buf.as_mut_ptr(), tf.as_raw_fd()) };
assert_eq!(
buf,
[
30, 46, 170, 66, 2, 215, 80, 164, 17, 116, 238, 69, 73, 112, 185, 44, 27, 194,
249, 37, 177, 227, 80, 118, 216, 199, 213, 245, 99, 98, 186, 100
]
);
Ok(())
}
Ok(())
}
}
3 changes: 2 additions & 1 deletion rust/composefs/src/fsverity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ impl Digest {
}

/// Compute the composefs fsverity digest from the provided file descriptor.
/// If fsverity is already enabled, this will return the digest computed by the kernel.
#[allow(unsafe_code)]
pub fn fsverity_digest_from_fd(fd: BorrowedFd, digest: &mut Digest) -> std::io::Result<()> {
unsafe {
map_result(composefs_sys::lcfs_compute_fsverity_from_fd(
map_result(composefs_sys::lcfs_fd_get_fsverity(
digest.0.as_mut_ptr(),
fd.as_raw_fd(),
))
Expand Down
Loading