• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "VintfObjectRecovery.h"
18 
19 #include <sys/mount.h>
20 #include <fs_mgr.h>
21 
22 #include "utils.h"
23 
24 namespace android {
25 namespace vintf {
26 
27 namespace details {
28 using FstabMgr = std::unique_ptr<struct fstab, decltype(&fs_mgr_free_fstab)>;
29 
mountAt(const FstabMgr & fstab,const char * path,const char * mount_point)30 static status_t mountAt(const FstabMgr &fstab, const char* path, const char* mount_point) {
31     fstab_rec* rec = fs_mgr_get_entry_for_mount_point(fstab.get(), path);
32     if (rec == nullptr) {
33         return UNKNOWN_ERROR;
34     }
35     int result = mount(rec->blk_device, mount_point, rec->fs_type, rec->flags, rec->fs_options);
36     return result == 0 ? OK : -errno;
37 }
38 
defaultFstabMgr()39 static FstabMgr defaultFstabMgr() {
40     return FstabMgr{fs_mgr_read_fstab_default(), &fs_mgr_free_fstab};
41 }
42 
43 class RecoveryPartitionMounter : public PartitionMounter {
44    public:
mountSystem() const45     status_t mountSystem() const override {
46         FstabMgr fstab = defaultFstabMgr();
47         if (fstab == NULL) {
48             return UNKNOWN_ERROR;
49         }
50         if (getPropertyFetcher().getBoolProperty("ro.build.system_root_image", false)) {
51             return mountAt(fstab, "/", "/system_root");
52         } else {
53             return mountAt(fstab, "/system", "/system");
54         }
55     }
56 
mountVendor() const57     status_t mountVendor() const override {
58         FstabMgr fstab = defaultFstabMgr();
59         if (fstab == NULL) {
60             return UNKNOWN_ERROR;
61         }
62         return mountAt(fstab, "/vendor", "/vendor");
63     }
64 
umountSystem() const65     status_t umountSystem() const override {
66         if (getPropertyFetcher().getBoolProperty("ro.build.system_root_image", false)) {
67             return umount("/system_root");
68         } else {
69             return umount("/system");
70         }
71     }
72 
umountVendor() const73     status_t umountVendor() const override {
74         return umount("/vendor");
75     }
76 };
77 
78 } // namespace details
79 
80 // static
CheckCompatibility(const std::vector<std::string> & xmls,std::string * error)81 int32_t VintfObjectRecovery::CheckCompatibility(
82         const std::vector<std::string> &xmls, std::string *error) {
83     static details::RecoveryPartitionMounter mounter;
84     return details::checkCompatibility(xmls, true /* mount */, mounter, error);
85 }
86 
87 
88 } // namespace vintf
89 } // namespace android
90