switch from `data_model::DataInit` to `zerocopy`
No behavior change intended.
The `DataInit` trait has been deleted in favor of the `zerocopy` crate,
which doesn't require any unsafe code to use.
Bug: 269356487
Test: m
Change-Id: Ie1ee815ca1beb06b336cb060a651b75c3b02e1c0
diff --git a/libs/devicemapper/src/sys.rs b/libs/devicemapper/src/sys.rs
index 3cecde3..bd1e165 100644
--- a/libs/devicemapper/src/sys.rs
+++ b/libs/devicemapper/src/sys.rs
@@ -15,7 +15,8 @@
*/
use bitflags::bitflags;
-use data_model::DataInit;
+use zerocopy::AsBytes;
+use zerocopy::FromZeroes;
// UAPI for device mapper can be found at include/uapi/linux/dm-ioctl.h
@@ -44,7 +45,7 @@
}
#[repr(C)]
-#[derive(Copy, Clone)]
+#[derive(Copy, Clone, AsBytes, FromZeroes)]
pub struct DmIoctl {
pub version: [u32; 3],
pub data_size: u32,
@@ -60,9 +61,6 @@
pub data: [u8; 7],
}
-// SAFETY: C struct is safe to be initialized from raw data
-unsafe impl DataInit for DmIoctl {}
-
pub const DM_VERSION_MAJOR: u32 = 4;
pub const DM_VERSION_MINOR: u32 = 0;
pub const DM_VERSION_PATCHLEVEL: u32 = 0;
@@ -71,10 +69,12 @@
pub const DM_UUID_LEN: usize = 129;
pub const DM_MAX_TYPE_NAME: usize = 16;
+#[repr(transparent)]
+#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, AsBytes, FromZeroes)]
+pub struct Flag(u32);
+
bitflags! {
- #[repr(transparent)]
- #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
- pub struct Flag: u32 {
+ impl Flag: u32 {
const DM_READONLY_FLAG = 1 << 0;
const DM_SUSPEND_FLAG = 1 << 1;
const DM_PERSISTENT_DEV_FLAG = 1 << 3;