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 <set> 23 #include <string> 24 #include <vector> 25 26 std::string fs_mgr_get_slot_suffix(); 27 std::string fs_mgr_get_other_slot_suffix(); 28 29 namespace android { 30 namespace fs_mgr { 31 32 struct FstabEntry { 33 std::string blk_device; 34 std::string zoned_device; 35 std::string logical_partition_name; 36 std::string mount_point; 37 std::string fs_type; 38 unsigned long flags = 0; 39 std::string fs_options; 40 std::string fs_checkpoint_opts; 41 std::string metadata_key_dir; 42 std::string metadata_encryption_options; 43 off64_t length = 0; 44 std::string label; 45 int partnum = -1; 46 int swap_prio = -1; 47 int max_comp_streams = 0; 48 off64_t zram_size = 0; 49 off64_t reserved_size = 0; 50 off64_t readahead_size_kb = -1; 51 std::string encryption_options; 52 off64_t erase_blk_size = 0; 53 off64_t logical_blk_size = 0; 54 std::string sysfs_path; 55 std::string vbmeta_partition; 56 uint64_t zram_backingdev_size = 0; 57 std::string avb_keys; 58 std::string lowerdir; 59 60 struct FsMgrFlags { 61 bool wait : 1; 62 bool check : 1; 63 bool crypt : 1; // Now only used to identify adoptable storage volumes 64 bool nonremovable : 1; 65 bool vold_managed : 1; 66 bool recovery_only : 1; 67 bool no_emulated_sd : 1; // No emulated sdcard daemon; sd card is the only external 68 // storage. 69 bool no_trim : 1; 70 bool file_encryption : 1; 71 bool formattable : 1; 72 bool slot_select : 1; 73 bool late_mount : 1; 74 bool no_fail : 1; 75 bool quota : 1; 76 bool avb : 1; 77 bool logical : 1; 78 bool checkpoint_blk : 1; 79 bool checkpoint_fs : 1; 80 bool first_stage_mount : 1; 81 bool slot_select_other : 1; 82 bool fs_verity : 1; 83 bool ext_meta_csum : 1; 84 bool fs_compress : 1; 85 bool overlayfs_remove_missing_lowerdir : 1; 86 } fs_mgr_flags = {}; 87 is_encryptableFstabEntry88 bool is_encryptable() const { return fs_mgr_flags.crypt; } 89 }; 90 91 // An Fstab is a collection of FstabEntry structs. 92 // The entries must be kept in the same order as they were seen in the fstab. 93 // Unless explicitly requested, a lookup on mount point should always return the 1st one. 94 using Fstab = std::vector<FstabEntry>; 95 96 // Exported for testability. Regular users should use ReadFstabFromFile(). 97 bool ParseFstabFromString(const std::string& fstab_str, bool proc_mounts, Fstab* fstab_out); 98 // Exported for testability. Regular users should use ReadDefaultFstab(). 99 std::string GetFstabPath(); 100 // Exported for testability. 101 bool SkipMountWithConfig(const std::string& skip_config, Fstab* fstab, bool verbose); 102 103 bool ReadFstabFromFile(const std::string& path, 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 // This method builds DSU fstab entries and transfer the fstab. 116 // 117 // fstab points to the unmodified fstab. 118 // 119 // dsu_partitions contains partition names, e.g. 120 // dsu_partitions[0] = "system_gsi" 121 // dsu_partitions[1] = "userdata_gsi" 122 // dsu_partitions[2] = ... 123 void TransformFstabForDsu(Fstab* fstab, const std::string& dsu_slot, 124 const std::vector<std::string>& dsu_partitions); 125 126 std::set<std::string> GetBootDevices(); 127 128 // Return the name of the dm-verity device for the given fstab entry. This does 129 // not check whether the device is valid or exists; it merely returns the 130 // expected name. 131 std::string GetVerityDeviceName(const FstabEntry& entry); 132 133 } // namespace fs_mgr 134 } // namespace android 135