From 0d469de9a03f2f587ba2c6323b9706b689e6f599 Mon Sep 17 00:00:00 2001 From: Sandeep Patil Date: Mon, 23 Jul 2018 14:50:26 -0700 Subject: [PATCH 1/2] dmctl: Do not skip argument if not matched with '-ro'. 'dmctl create' command would fail if '-ro' flag is not used. This happend because the argument in place of '-ro' is skipped unconditionally. Bug: 72722987 Test: $ losetup /dev/block/loop0 fs.img $ dmctl create FOO linear 0 25600 /dev/block/loop0 0 Change-Id: I3f6264336b9c9a1b5de76f3a1d29e6045453f9cb Signed-off-by: Sandeep Patil --- fs_mgr/tools/dmctl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs_mgr/tools/dmctl.cpp b/fs_mgr/tools/dmctl.cpp index 5e11c8423..32cbb32ee 100644 --- a/fs_mgr/tools/dmctl.cpp +++ b/fs_mgr/tools/dmctl.cpp @@ -132,11 +132,11 @@ static int DmCreateCmdHandler(int argc, char** argv) { while (arg_index < argc && argv[arg_index][0] == '-') { if (strcmp(argv[arg_index], "-ro") == 0) { table.set_readonly(true); + arg_index++; } else { std::cerr << "Unrecognized option: " << argv[arg_index] << std::endl; return -EINVAL; } - arg_index++; } // Parse everything else as target information. From efc54790859ee672b317692690461b7e0f0e47b3 Mon Sep 17 00:00:00 2001 From: Sandeep Patil Date: Mon, 23 Jul 2018 15:24:55 -0700 Subject: [PATCH 2/2] fs_mgr: libdm: add support android-verity target. The support for android-verity makes it possible for us to test raw verified filesystem images to be attached to android-verity target and have it verified by the kernel. This makes the testing of android-verity device mapper target much easier as it doesn't _have_ to be used for root mount. Bug: 72722987 Test: $ losetup /dev/block/loop0 /data/local/tmp/verity_fs.img $ dmctl create verity-fs android-verity 0 4200 \ Android:7e4333f9bba00adfe0ede979e28ed1920492b40f 7:0 Change-Id: Ica6bf5c6e1fd758fdb4005fc8a09755f369a8a0f Signed-off-by: Sandeep Patil --- fs_mgr/libdm/dm_target.cpp | 4 ++++ fs_mgr/libdm/include/libdm/dm_target.h | 14 ++++++++++++++ fs_mgr/tools/dmctl.cpp | 11 +++++++++++ 3 files changed, 29 insertions(+) diff --git a/fs_mgr/libdm/dm_target.cpp b/fs_mgr/libdm/dm_target.cpp index 20b26df37..7c1826766 100644 --- a/fs_mgr/libdm/dm_target.cpp +++ b/fs_mgr/libdm/dm_target.cpp @@ -111,5 +111,9 @@ std::string DmTargetVerity::GetParameterString() const { return base + " " + std::to_string(optional_args_.size()) + " " + optional; } +std::string DmTargetAndroidVerity::GetParameterString() const { + return keyid_ + " " + block_device_; +} + } // namespace dm } // namespace android diff --git a/fs_mgr/libdm/include/libdm/dm_target.h b/fs_mgr/libdm/include/libdm/dm_target.h index d5974f4f1..31863c8fa 100644 --- a/fs_mgr/libdm/include/libdm/dm_target.h +++ b/fs_mgr/libdm/include/libdm/dm_target.h @@ -128,6 +128,20 @@ class DmTargetVerity final : public DmTarget { bool valid_; }; +class DmTargetAndroidVerity final : public DmTarget { + public: + DmTargetAndroidVerity(uint64_t start, uint64_t length, const std::string& block_device, + const std::string& keyid) + : DmTarget(start, length), keyid_(keyid), block_device_(block_device) {} + + std::string name() const override { return "android-verity"; } + std::string GetParameterString() const override; + + private: + std::string keyid_; + std::string block_device_; +}; + // This is the same as DmTargetVerity, but the table may be specified as a raw // string. This code exists only for fs_mgr_verity and should be avoided. Use // DmTargetVerity for new code instead. diff --git a/fs_mgr/tools/dmctl.cpp b/fs_mgr/tools/dmctl.cpp index 32cbb32ee..45a81af2d 100644 --- a/fs_mgr/tools/dmctl.cpp +++ b/fs_mgr/tools/dmctl.cpp @@ -40,6 +40,7 @@ using DmTable = ::android::dm::DmTable; using DmTarget = ::android::dm::DmTarget; using DmTargetLinear = ::android::dm::DmTargetLinear; using DmTargetZero = ::android::dm::DmTargetZero; +using DmTargetAndroidVerity = ::android::dm::DmTargetAndroidVerity; using DmTargetTypeInfo = ::android::dm::DmTargetTypeInfo; using DmBlockDevice = ::android::dm::DeviceMapper::DmBlockDevice; @@ -96,6 +97,16 @@ class TargetParser final { } return std::make_unique(start_sector, num_sectors, block_device, physical_sector); + } else if (target_type == "android-verity") { + if (!HasArgs(2)) { + std::cerr << "Expected \"android-verity\" " + << std::endl; + return nullptr; + } + std::string keyid = NextArg(); + std::string block_device = NextArg(); + return std::make_unique(start_sector, num_sectors, keyid, + block_device); } else { std::cerr << "Unrecognized target type: " << target_type << std::endl; return nullptr;