1 /* 2 * Copyright (C) 2012 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 #pragma once 18 19 #include <stdint.h> 20 #include <sys/types.h> 21 22 #include <functional> 23 #include <set> 24 #include <string> 25 #include <vector> 26 27 std::string fs_mgr_get_slot_suffix(); 28 std::string fs_mgr_get_other_slot_suffix(); 29 30 namespace android { 31 namespace fs_mgr { 32 33 struct FstabEntry { 34 std::string blk_device; 35 std::vector<std::string> user_devices; 36 std::vector<int> device_aliased; 37 std::string logical_partition_name; 38 std::string mount_point; 39 std::string fs_type; 40 unsigned long flags = 0; 41 std::string fs_options; 42 std::string fs_checkpoint_opts; 43 std::string metadata_key_dir; 44 std::string metadata_encryption_options; 45 off64_t length = 0; 46 std::string label; 47 int partnum = -1; 48 int swap_prio = -1; 49 int max_comp_streams = 0; 50 off64_t zram_size = 0; 51 off64_t reserved_size = 0; 52 off64_t readahead_size_kb = -1; 53 std::string encryption_options; 54 off64_t erase_blk_size = 0; 55 off64_t logical_blk_size = 0; 56 std::string sysfs_path; 57 std::string vbmeta_partition; 58 uint64_t zram_backingdev_size = 0; 59 std::string avb_keys; 60 std::string lowerdir; 61 std::string avb_hashtree_digest; 62 63 struct FsMgrFlags { 64 bool wait : 1; 65 bool check : 1; 66 bool crypt : 1; // Now only used to identify adoptable storage volumes 67 bool nonremovable : 1; 68 bool vold_managed : 1; 69 bool recovery_only : 1; 70 bool no_emulated_sd : 1; // No emulated sdcard daemon; sd card is the only external 71 // storage. 72 bool no_trim : 1; 73 bool file_encryption : 1; 74 bool formattable : 1; 75 bool slot_select : 1; 76 bool late_mount : 1; 77 bool no_fail : 1; 78 bool quota : 1; 79 bool avb : 1; 80 bool logical : 1; 81 bool checkpoint_blk : 1; 82 bool checkpoint_fs : 1; 83 bool first_stage_mount : 1; 84 bool slot_select_other : 1; 85 bool fs_verity : 1; 86 bool ext_meta_csum : 1; 87 bool fs_compress : 1; 88 bool overlayfs_remove_missing_lowerdir : 1; 89 bool is_zoned : 1; 90 bool overlay_on : 1; 91 bool overlay_off : 1; 92 } fs_mgr_flags = {}; 93 is_encryptableFstabEntry94 bool is_encryptable() const { return fs_mgr_flags.crypt; } 95 }; 96 97 // An Fstab is a collection of FstabEntry structs. 98 // The entries must be kept in the same order as they were seen in the fstab. 99 // Unless explicitly requested, a lookup on mount point should always return the 1st one. 100 using Fstab = std::vector<FstabEntry>; 101 102 bool ReadFstabFromFile(const std::string& path, Fstab* fstab); 103 bool ReadFstabFromProcMounts(Fstab* fstab); 104 bool ReadFstabFromDt(Fstab* fstab, bool verbose = true); 105 bool ReadDefaultFstab(Fstab* fstab); 106 bool SkipMountingPartitions(Fstab* fstab, bool verbose = false); 107 108 // The Fstab can contain multiple entries for the same mount point with different configurations. 109 std::vector<FstabEntry*> GetEntriesForMountPoint(Fstab* fstab, const std::string& path); 110 111 // Like GetEntriesForMountPoint() but return only the first entry or nullptr if no entry is found. 112 FstabEntry* GetEntryForMountPoint(Fstab* fstab, const std::string& path); 113 const FstabEntry* GetEntryForMountPoint(const Fstab* fstab, const std::string& path); 114 115 FstabEntry* GetEntryForMountPoint(Fstab* fstab, const std::string_view path, 116 const std::string_view fstype); 117 118 // This method builds DSU fstab entries and transfer the fstab. 119 // 120 // fstab points to the unmodified fstab. 121 // 122 // dsu_partitions contains partition names, e.g. 123 // dsu_partitions[0] = "system_gsi" 124 // dsu_partitions[1] = "userdata_gsi" 125 // dsu_partitions[2] = ... 126 void TransformFstabForDsu(Fstab* fstab, const std::string& dsu_slot, 127 const std::vector<std::string>& dsu_partitions); 128 129 std::set<std::string> GetBootDevices(); 130 131 // Get the Partition UUID the kernel loaded from if the bootloader passed it. 132 // 133 // If the kernel's Partition UUID is provided then we can use this to help 134 // identify which block device contains the filesystems we care about. 135 // 136 // NOTE: Nothing secures a UUID other than the convention that two disks 137 // aren't supposed to both have the same UUID. We still need other mechanisms 138 // to ensure we've got the right disk. 139 std::string GetBootPartUuid(); 140 141 // Return the name of the dm-verity device for the given fstab entry. This does 142 // not check whether the device is valid or exists; it merely returns the 143 // expected name. 144 std::string GetVerityDeviceName(const FstabEntry& entry); 145 146 // Returns the Android Device Tree directory as specified in the kernel bootconfig or cmdline. 147 // If the platform does not configure a custom DT path, returns the standard one (based in procfs). 148 const std::string& GetAndroidDtDir(); 149 150 // Import the kernel bootconfig by calling the callback |fn| with each key-value pair. 151 void ImportBootconfig(const std::function<void(std::string, std::string)>& fn); 152 153 // Get the kernel bootconfig value for |key|. 154 // Returns true if |key| is found in bootconfig. 155 // Otherwise returns false and |*out| is not modified. 156 bool GetBootconfig(const std::string& key, std::string* out); 157 158 // Import the kernel cmdline by calling the callback |fn| with each key-value pair. 159 void ImportKernelCmdline(const std::function<void(std::string, std::string)>& fn); 160 161 // Get the kernel cmdline value for |key|. 162 // Returns true if |key| is found in the kernel cmdline. 163 // Otherwise returns false and |*out| is not modified. 164 bool GetKernelCmdline(const std::string& key, std::string* out); 165 166 // Return the "other" slot for the given slot suffix. 167 std::string OtherSlotSuffix(const std::string& suffix); 168 169 bool GetBootconfigFromString(const std::string& bootconfig, const std::string& key, 170 std::string* out); 171 172 } // namespace fs_mgr 173 } // namespace android 174