compsvc: mininize the footprint of raw fd
Bug: 243500154
Test: TH
Change-Id: I1279ec1f7efbc363a16aeb4f3c2e55bf26075585
diff --git a/compos/src/artifact_signer.rs b/compos/src/artifact_signer.rs
index a15df28..e51b8dd 100644
--- a/compos/src/artifact_signer.rs
+++ b/compos/src/artifact_signer.rs
@@ -24,7 +24,7 @@
use protobuf::Message;
use std::fs::File;
use std::io::Write;
-use std::os::unix::io::AsRawFd;
+use std::os::unix::io::AsFd;
use std::path::Path;
const TARGET_DIRECTORY: &str = "/data/misc/apexdata/com.android.art/dalvik-cache";
@@ -52,7 +52,7 @@
let target_path = target_path.to_str().ok_or_else(|| anyhow!("Invalid path"))?;
let file = File::open(path).with_context(|| format!("Opening {}", path.display()))?;
- let digest = fsverity::measure(file.as_raw_fd())?;
+ let digest = fsverity::measure(file.as_fd())?;
let digest = to_hex_string(&digest);
self.file_digests.push((target_path.to_owned(), digest));
diff --git a/compos/src/fsverity.rs b/compos/src/fsverity.rs
index f5df5f7..4f0ed34 100644
--- a/compos/src/fsverity.rs
+++ b/compos/src/fsverity.rs
@@ -18,7 +18,7 @@
use libc::getxattr;
use std::ffi::CString;
use std::io;
-use std::os::unix::io::RawFd;
+use std::os::unix::io::{AsRawFd, BorrowedFd};
const SHA256_HASH_SIZE: usize = 32;
@@ -26,10 +26,10 @@
pub type Sha256Digest = [u8; SHA256_HASH_SIZE];
/// Returns the fs-verity measurement/digest. Currently only SHA256 is supported.
-pub fn measure(fd: RawFd) -> Result<Sha256Digest> {
+pub fn measure(fd: BorrowedFd) -> Result<Sha256Digest> {
// TODO(b/196635431): Unfortunately, the FUSE API doesn't allow authfs to implement the standard
// fs-verity ioctls. Until the kernel allows, use the alternative xattr that authfs provides.
- let path = CString::new(format!("/proc/self/fd/{}", fd).as_str()).unwrap();
+ let path = CString::new(format!("/proc/self/fd/{}", fd.as_raw_fd()).as_str()).unwrap();
let name = CString::new("authfs.fsverity.digest").unwrap();
let mut buf = [0u8; SHA256_HASH_SIZE];
// SAFETY: getxattr should not write beyond the given buffer size.