Add support for autoclear flag for loopdevice
Returning a struct with the File reference instead of just a device path
to make sure autoclear loop device is not automatically cleared once the
attach function returns.
Also add host supported attribute for libdm since the library should
work on the host.
Bug: 375432644
Test: atest libdm_rust.test; atest apkdmverity.test
Change-Id: I223fe2eff056fb6ca86df64e871825f9b04881d7
diff --git a/guest/apkdmverity/src/main.rs b/guest/apkdmverity/src/main.rs
index d2f88ae..2fc964b 100644
--- a/guest/apkdmverity/src/main.rs
+++ b/guest/apkdmverity/src/main.rs
@@ -27,6 +27,7 @@
use apkverify::{HashAlgorithm, V4Signature};
use clap::{arg, Arg, ArgAction, Command};
use dm::loopdevice;
+use dm::loopdevice::LoopConfigOptions;
use dm::util;
use dm::verity::{DmVerityHashAlgorithm, DmVerityTargetBuilder};
use itertools::Itertools;
@@ -109,9 +110,13 @@
}
(
loopdevice::attach(
- &apk, 0, apk_size, /* direct_io */ true, /* writable */ false,
+ &apk,
+ 0,
+ apk_size,
+ &LoopConfigOptions { direct_io: true, ..Default::default() },
)
- .context("Failed to attach APK to a loop device")?,
+ .context("Failed to attach APK to a loop device")?
+ .path,
apk_size,
)
};
@@ -125,10 +130,9 @@
// Due to unknown reason(b/191344832), we can't enable "direct IO" for the IDSIG file (backing
// the hash). For now we don't use "direct IO" but it seems OK since the IDSIG file is very
// small and the benefit of direct-IO would be negliable.
- let hash_device = loopdevice::attach(
- &idsig, offset, size, /* direct_io */ false, /* writable */ false,
- )
- .context("Failed to attach idsig to a loop device")?;
+ let hash_device = loopdevice::attach(&idsig, offset, size, &LoopConfigOptions::default())
+ .context("Failed to attach idsig to a loop device")?
+ .path;
// Build a dm-verity target spec from the information from the idsig file. The apk and the
// idsig files are used as the data device and the hash device, respectively.
@@ -347,18 +351,17 @@
// of the data device is done in the scopeguard for the return value of `enable_verity`
// below. Only the idsig_loop_device needs detatching.
let apk_loop_device = loopdevice::attach(
- &apk_path, 0, apk_size, /* direct_io */ true, /* writable */ false,
+ &apk_path,
+ 0,
+ apk_size,
+ &LoopConfigOptions { direct_io: true, ..Default::default() },
)
- .unwrap();
+ .unwrap()
+ .path;
let idsig_loop_device = scopeguard::guard(
- loopdevice::attach(
- &idsig_path,
- 0,
- idsig_size,
- /* direct_io */ false,
- /* writable */ false,
- )
- .unwrap(),
+ loopdevice::attach(&idsig_path, 0, idsig_size, &LoopConfigOptions::default())
+ .unwrap()
+ .path,
|dev| loopdevice::detach(dev).unwrap(),
);