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 logical_partition_name;
35     std::string mount_point;
36     std::string fs_type;
37     unsigned long flags = 0;
38     std::string fs_options;
39     std::string key_loc;
40     std::string metadata_key_dir;
41     std::string metadata_encryption;
42     off64_t length = 0;
43     std::string label;
44     int partnum = -1;
45     int swap_prio = -1;
46     int max_comp_streams = 0;
47     off64_t zram_size = 0;
48     off64_t reserved_size = 0;
49     std::string encryption_options;
50     off64_t erase_blk_size = 0;
51     off64_t logical_blk_size = 0;
52     std::string sysfs_path;
53     std::string vbmeta_partition;
54     std::string zram_loopback_path;
55     uint64_t zram_loopback_size = 512 * 1024 * 1024;  // 512MB by default;
56     std::string zram_backing_dev_path;
57     std::string avb_keys;
58 
59     struct FsMgrFlags {
60         bool wait : 1;
61         bool check : 1;
62         bool crypt : 1;
63         bool nonremovable : 1;
64         bool vold_managed : 1;
65         bool recovery_only : 1;
66         bool verify : 1;
67         bool force_crypt : 1;
68         bool no_emulated_sd : 1;  // No emulated sdcard daemon; sd card is the only external
69                                   // storage.
70         bool no_trim : 1;
71         bool file_encryption : 1;
72         bool formattable : 1;
73         bool slot_select : 1;
74         bool force_fde_or_fbe : 1;
75         bool late_mount : 1;
76         bool no_fail : 1;
77         bool verify_at_boot : 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     } fs_mgr_flags = {};
89 
is_encryptableFstabEntry90     bool is_encryptable() const {
91         return fs_mgr_flags.crypt || fs_mgr_flags.force_crypt || fs_mgr_flags.force_fde_or_fbe;
92     }
93 };
94 
95 // An Fstab is a collection of FstabEntry structs.
96 // The entries must be kept in the same order as they were seen in the fstab.
97 // Unless explicitly requested, a lookup on mount point should always return the 1st one.
98 using Fstab = std::vector<FstabEntry>;
99 
100 bool ReadFstabFromFile(const std::string& path, Fstab* fstab);
101 bool ReadFstabFromDt(Fstab* fstab, bool log = true);
102 bool ReadDefaultFstab(Fstab* fstab);
103 bool SkipMountingPartitions(Fstab* fstab);
104 
105 FstabEntry* GetEntryForMountPoint(Fstab* fstab, const std::string& path);
106 // The Fstab can contain multiple entries for the same mount point with different configurations.
107 std::vector<FstabEntry*> GetEntriesForMountPoint(Fstab* fstab, const std::string& path);
108 
109 // This method builds DSU fstab entries and transfer the fstab.
110 //
111 // fstab points to the unmodified fstab.
112 //
113 // dsu_partitions contains partition names, e.g.
114 //     dsu_partitions[0] = "system_gsi"
115 //     dsu_partitions[1] = "userdata_gsi"
116 //     dsu_partitions[2] = ...
117 void TransformFstabForDsu(Fstab* fstab, const std::vector<std::string>& dsu_partitions);
118 
119 std::set<std::string> GetBootDevices();
120 
121 // Return the name of the dm-verity device for the given fstab entry. This does
122 // not check whether the device is valid or exists; it merely returns the
123 // expected name.
124 std::string GetVerityDeviceName(const FstabEntry& entry);
125 
126 }  // namespace fs_mgr
127 }  // namespace android
128