summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYifan Hong2018-07-13 18:03:59 -0500
committerYifan Hong2018-07-16 17:55:23 -0500
commit91c1b2703bf422786f3d698fb60da5a33fcd83a2 (patch)
tree0629d17486d527f0966a5b95932797734ef081b0 /VintfObjectRecovery.cpp
parentdb3084356aa05f08194a69af7d46e756fbdd4656 (diff)
downloadplatform-system-libvintf-91c1b2703bf422786f3d698fb60da5a33fcd83a2.tar.gz
platform-system-libvintf-91c1b2703bf422786f3d698fb60da5a33fcd83a2.tar.xz
platform-system-libvintf-91c1b2703bf422786f3d698fb60da5a33fcd83a2.zip
VintfObjectRecovery: partitions are mounted to /mnt
Recovery now mounts system and vendor partition under /mnt. Update VintfObjectRecovery to reflect this, so that during OTA, the partitions are correctly mounted and checked. During OTA, access to /vendor will always be redirected to /mnt/vendor. Access to /system will be redirected to - /mnt/system if ro.build.system_root_image is false - /mnt/system/system otherwise. Test: manual by calling CheckCompatibility in "Run graphics test" Change-Id: I4c4448e526b2a1f14c6a77b14ac72915256b85cb Fixes: 111372832
Diffstat (limited to 'VintfObjectRecovery.cpp')
-rw-r--r--VintfObjectRecovery.cpp77
1 files changed, 52 insertions, 25 deletions
diff --git a/VintfObjectRecovery.cpp b/VintfObjectRecovery.cpp
index 9efb318..a24fc7a 100644
--- a/VintfObjectRecovery.cpp
+++ b/VintfObjectRecovery.cpp
@@ -16,8 +16,11 @@
16 16
17#include "VintfObjectRecovery.h" 17#include "VintfObjectRecovery.h"
18 18
19#include <sys/mount.h>
20#include <fs_mgr.h> 19#include <fs_mgr.h>
20#include <sys/mount.h>
21#include <sys/stat.h>
22
23#include <android-base/strings.h>
21 24
22#include "utils.h" 25#include "utils.h"
23 26
@@ -25,14 +28,20 @@ namespace android {
25namespace vintf { 28namespace vintf {
26 29
27namespace details { 30namespace details {
31using android::base::StartsWith;
28using FstabMgr = std::unique_ptr<struct fstab, decltype(&fs_mgr_free_fstab)>; 32using FstabMgr = std::unique_ptr<struct fstab, decltype(&fs_mgr_free_fstab)>;
29 33
30static status_t mountAt(const FstabMgr &fstab, const char* path, const char* mount_point) { 34static const char* const kSystemImageRootDir = "/mnt/system";
35static const char* const kVendorImageRootDir = "/mnt/vendor";
36
37static status_t mountAt(const FstabMgr& fstab, const char* path, const char* mountPoint) {
38 mkdir(mountPoint, 0755); // in case it doesn't already exist
39
31 fstab_rec* rec = fs_mgr_get_entry_for_mount_point(fstab.get(), path); 40 fstab_rec* rec = fs_mgr_get_entry_for_mount_point(fstab.get(), path);
32 if (rec == nullptr) { 41 if (rec == nullptr) {
33 return UNKNOWN_ERROR; 42 return UNKNOWN_ERROR;
34 } 43 }
35 int result = mount(rec->blk_device, mount_point, rec->fs_type, rec->flags, rec->fs_options); 44 int result = mount(rec->blk_device, mountPoint, rec->fs_type, rec->flags, rec->fs_options);
36 return result == 0 ? OK : -errno; 45 return result == 0 ? OK : -errno;
37} 46}
38 47
@@ -42,42 +51,58 @@ static FstabMgr defaultFstabMgr() {
42 51
43class RecoveryPartitionMounter : public PartitionMounter { 52class RecoveryPartitionMounter : public PartitionMounter {
44 public: 53 public:
45 RecoveryPartitionMounter(PropertyFetcher* propertyFetcher) 54 RecoveryPartitionMounter(bool systemRootImage) : mSystemRootImage(systemRootImage) {}
46 : mPropertyFetcher(propertyFetcher) {}
47 status_t mountSystem() const override { 55 status_t mountSystem() const override {
48 FstabMgr fstab = defaultFstabMgr(); 56 if (mSystemRootImage) {
49 if (fstab == NULL) { 57 return mount("/", kSystemImageRootDir);
50 return UNKNOWN_ERROR;
51 }
52 if (mPropertyFetcher->getBoolProperty("ro.build.system_root_image", false)) {
53 return mountAt(fstab, "/", "/system_root");
54 } else { 58 } else {
55 return mountAt(fstab, "/system", "/system"); 59 return mount("/system", kSystemImageRootDir);
56 } 60 }
57 } 61 }
58 62
59 status_t mountVendor() const override { 63 status_t mountVendor() const override { return mount("/vendor", kVendorImageRootDir); }
64
65 status_t umountSystem() const override { return umount(kSystemImageRootDir); }
66
67 status_t umountVendor() const override { return umount(kVendorImageRootDir); }
68
69 private:
70 const bool mSystemRootImage = false;
71
72 status_t mount(const char* path, const char* mountPoint) const {
60 FstabMgr fstab = defaultFstabMgr(); 73 FstabMgr fstab = defaultFstabMgr();
61 if (fstab == NULL) { 74 if (fstab == NULL) {
62 return UNKNOWN_ERROR; 75 return UNKNOWN_ERROR;
63 } 76 }
64 return mountAt(fstab, "/vendor", "/vendor"); 77 return mountAt(fstab, path, mountPoint);
65 } 78 }
79};
66 80
67 status_t umountSystem() const override { 81class RecoveryFileSystem : public FileSystem {
68 if (mPropertyFetcher->getBoolProperty("ro.build.system_root_image", false)) { 82 public:
69 return umount("/system_root"); 83 RecoveryFileSystem(bool systemRootImage) : mSystemRootImage(systemRootImage) {}
70 } else { 84
71 return umount("/system"); 85 status_t fetch(const std::string& path, std::string* fetched, std::string* error) const {
72 } 86 return getFileSystem(path).fetch(path, fetched, error);
73 } 87 }
74 88
75 status_t umountVendor() const override { 89 status_t listFiles(const std::string& path, std::vector<std::string>* out,
76 return umount("/vendor"); 90 std::string* error) const {
91 return getFileSystem(path).listFiles(path, out, error);
77 } 92 }
78 93
79 private: 94 private:
80 PropertyFetcher* mPropertyFetcher{nullptr}; 95 const bool mSystemRootImage = false;
96 FileSystemUnderPath mSystemFileSystem{"/mnt/system"};
97 FileSystemUnderPath mMntFileSystem{"/mnt"};
98
99 const FileSystemUnderPath& getFileSystem(const std::string& path) const {
100 // If system_root_image, /system files are under /mnt/system/system.
101 if (StartsWith(path, "/system") && mSystemRootImage) {
102 return mSystemFileSystem;
103 }
104 return mMntFileSystem;
105 }
81}; 106};
82 107
83} // namespace details 108} // namespace details
@@ -86,8 +111,10 @@ class RecoveryPartitionMounter : public PartitionMounter {
86int32_t VintfObjectRecovery::CheckCompatibility( 111int32_t VintfObjectRecovery::CheckCompatibility(
87 const std::vector<std::string> &xmls, std::string *error) { 112 const std::vector<std::string> &xmls, std::string *error) {
88 auto propertyFetcher = std::make_unique<details::PropertyFetcherImpl>(); 113 auto propertyFetcher = std::make_unique<details::PropertyFetcherImpl>();
89 auto mounter = std::make_unique<details::RecoveryPartitionMounter>(propertyFetcher.get()); 114 bool systemRootImage = propertyFetcher->getBoolProperty("ro.build.system_root_image", false);
90 auto vintfObject = std::make_unique<VintfObject>(nullptr /* fileSystem */, std::move(mounter), 115 auto mounter = std::make_unique<details::RecoveryPartitionMounter>(systemRootImage);
116 auto fileSystem = std::make_unique<details::RecoveryFileSystem>(systemRootImage);
117 auto vintfObject = std::make_unique<VintfObject>(std::move(fileSystem), std::move(mounter),
91 nullptr /* runtime info factory */, 118 nullptr /* runtime info factory */,
92 std::move(propertyFetcher)); 119 std::move(propertyFetcher));
93 return vintfObject->checkCompatibility(xmls, true /* mount */, error); 120 return vintfObject->checkCompatibility(xmls, true /* mount */, error);