Skip to content

Commit 1b3e9fc

Browse files
committed
rust: Bind lcfs_fd_require_fsverity
This is a reasonable thing to want to do. Signed-off-by: Colin Walters <[email protected]>
1 parent 4cadb80 commit 1b3e9fc

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

rust/composefs-sys/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ name = "composefs"
1919
version = "1"
2020

2121
[features]
22-
# Depend on 1.0.4 APIs
22+
# Require functions from the C library corresponding to the provided version.
2323
v1_0_4 = []
24+
v1_0_7 = ["v1_0_4"]
2425

2526
[build-dependencies]
2627
system-deps = "6"

rust/composefs-sys/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ extern "C" {
1111
pub fn lcfs_fd_get_fsverity(digest: *mut u8, fd: std::os::raw::c_int) -> std::os::raw::c_int;
1212
#[cfg(feature = "v1_0_4")]
1313
pub fn lcfs_fd_enable_fsverity(fd: std::os::raw::c_int) -> std::os::raw::c_int;
14+
#[cfg(feature = "v1_0_7")]
15+
pub fn lcfs_fd_require_fsverity(digest: *mut u8, fd: std::os::raw::c_int) -> std::os::raw::c_int;
1416
}
1517

1618
/// Convert an integer return value into a `Result`.
@@ -41,6 +43,19 @@ mod tests {
4143
Ok(())
4244
}
4345

46+
#[test]
47+
#[cfg(feature = "v1_0_7")]
48+
fn test_fd_require_fsverity() -> Result<()> {
49+
let mut tf = tempfile::NamedTempFile::new()?;
50+
tf.write_all(b"hello")?;
51+
let tf = std::fs::File::open(tf.path())?;
52+
// This fd can't have fsverity enabled
53+
let mut buf = [0u8; LCFS_SHA256_DIGEST_LEN];
54+
let r = unsafe { lcfs_fd_require_fsverity(buf.as_mut_ptr(), tf.as_raw_fd()) };
55+
assert_ne!(r, 0);
56+
Ok(())
57+
}
58+
4459
#[test]
4560
fn test_digest() -> Result<()> {
4661
for f in [lcfs_compute_fsverity_from_fd, lcfs_fd_get_fsverity] {

0 commit comments

Comments
 (0)