• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <chrono>
20 #include <string>
21 
22 #include <android-base/logging.h>
23 #include <fs_mgr.h>
24 #include <fstab/fstab.h>
25 
26 #include "fs_mgr_priv_boot_config.h"
27 
28 /* The CHECK() in logging.h will use program invocation name as the tag.
29  * Thus, the log will have prefix "init: " when libfs_mgr is statically
30  * linked in the init process. This might be opaque when debugging.
31  * Appends "in libfs_mgr" at the end of the abort message to explicitly
32  * indicate the check happens in fs_mgr.
33  */
34 #define FS_MGR_CHECK(x) CHECK(x) << "in libfs_mgr "
35 
36 #define FS_MGR_TAG "[libfs_mgr]"
37 
38 // Logs a message to kernel
39 #define LINFO    LOG(INFO) << FS_MGR_TAG
40 #define LWARNING LOG(WARNING) << FS_MGR_TAG
41 #define LERROR   LOG(ERROR) << FS_MGR_TAG
42 #define LFATAL LOG(FATAL) << FS_MGR_TAG
43 
44 // Logs a message with strerror(errno) at the end
45 #define PINFO    PLOG(INFO) << FS_MGR_TAG
46 #define PWARNING PLOG(WARNING) << FS_MGR_TAG
47 #define PERROR   PLOG(ERROR) << FS_MGR_TAG
48 #define PFATAL PLOG(FATAL) << FS_MGR_TAG
49 
50 #define CRYPTO_TMPFS_OPTIONS "size=512m,mode=0771,uid=1000,gid=1000"
51 
52 /* fstab has the following format:
53  *
54  * Any line starting with a # is a comment and ignored
55  *
56  * Any blank line is ignored
57  *
58  * All other lines must be in this format:
59  *   <source>  <mount_point> <fs_type> <mount_flags> <fs_options> <fs_mgr_options>
60  *
61  *   <mount_flags> is a comma separated list of flags that can be passed to the
62  *                 mount command.  The list includes noatime, nosuid, nodev, nodiratime,
63  *                 ro, rw, remount, defaults.
64  *
65  *   <fs_options> is a comma separated list of options accepted by the filesystem being
66  *                mounted.  It is passed directly to mount without being parsed
67  *
68  *   <fs_mgr_options> is a comma separated list of flags that control the operation of
69  *                     the fs_mgr program.  The list includes "wait", which will wait till
70  *                     the <source> file exists, and "check", which requests that the fs_mgr
71  *                     run an fscheck program on the <source> before mounting the filesystem.
72  *                     If check is specifed on a read-only filesystem, it is ignored.
73  *                     Also, "encryptable" means that filesystem can be encrypted.
74  *                     The "encryptable" flag _MUST_ be followed by a = and a string which
75  *                     is the location of the encryption keys.  It can either be a path
76  *                     to a file or partition which contains the keys, or the word "footer"
77  *                     which means the keys are in the last 16 Kbytes of the partition
78  *                     containing the filesystem.
79  *
80  * When the fs_mgr is requested to mount all filesystems, it will first mount all the
81  * filesystems that do _NOT_ specify check (including filesystems that are read-only and
82  * specify check, because check is ignored in that case) and then it will check and mount
83  * filesystem marked with check.
84  *
85  */
86 
87 #define DM_BUF_SIZE 4096
88 
89 using namespace std::chrono_literals;
90 
91 enum class FileWaitMode { Exists, DoesNotExist };
92 
93 bool fs_mgr_wait_for_file(const std::string& filename,
94                           const std::chrono::milliseconds relative_timeout,
95                           FileWaitMode wait_mode = FileWaitMode::Exists);
96 
97 bool fs_mgr_set_blk_ro(const std::string& blockdev, bool readonly = true);
98 bool fs_mgr_update_for_slotselect(android::fs_mgr::Fstab* fstab);
99 bool fs_mgr_is_device_unlocked();
100 const std::string& get_android_dt_dir();
101 bool is_dt_compatible();
102 int load_verity_state(const android::fs_mgr::FstabEntry& entry, int* mode);
103 
104 bool fs_mgr_is_ext4(const std::string& blk_device);
105 bool fs_mgr_is_f2fs(const std::string& blk_device);
106 
107 bool fs_mgr_teardown_verity(android::fs_mgr::FstabEntry* fstab, bool wait);
108 
109 namespace android {
110 namespace fs_mgr {
111 bool UnmapDevice(const std::string& name, const std::chrono::milliseconds& timeout_ms);
112 }  // namespace fs_mgr
113 }  // namespace android
114