apkdmverity: use data_model crate for better handling of C structs
The data_model:DataInit trait provides methods for converting between
a C struct and an array of the same size, allowing us to drop the hand
crafted as_u8_slice methods.
Bug: N/A
Test: cargo test
Test: atest apkdmverity.test
Change-Id: Iaff910f0a638e91a428777b94dc6fb0b5fe53831
diff --git a/apkverity/src/loopdevice/sys.rs b/apkverity/src/loopdevice/sys.rs
index 3f10f22..5de0c92 100644
--- a/apkverity/src/loopdevice/sys.rs
+++ b/apkverity/src/loopdevice/sys.rs
@@ -15,6 +15,7 @@
*/
use bitflags::bitflags;
+use data_model::DataInit;
// This UAPI is copied and converted from include/uapi/linux/loop.h Note that this module doesn't
// implement all the features introduced in loop(4). Only the features that are required to support
@@ -28,6 +29,7 @@
pub const LOOP_CLR_FD: libc::c_ulong = 0x4C01;
#[repr(C)]
+#[derive(Copy, Clone)]
pub struct loop_config {
pub fd: u32,
pub block_size: u32,
@@ -35,7 +37,11 @@
pub reserved: [u64; 8],
}
+// SAFETY: C struct is safe to be initialized from raw data
+unsafe impl DataInit for loop_config {}
+
#[repr(C)]
+#[derive(Copy, Clone)]
pub struct loop_info64 {
pub lo_device: u64,
pub lo_inode: u64,