xref: /aosp_15_r20/system/core/fs_mgr/fs_mgr_priv.h (revision 00c7fec1bb09f3284aad6a6f96d2f63dfc3650ad)
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 "libfstab/fstab_priv.h"
27 
28 #define FS_MGR_TAG "[libfs_mgr] "
29 
30 // Logs a message to kernel
31 #define LINFO    LOG(INFO) << FS_MGR_TAG
32 #define LWARNING LOG(WARNING) << FS_MGR_TAG
33 #define LERROR   LOG(ERROR) << FS_MGR_TAG
34 #define LFATAL LOG(FATAL) << FS_MGR_TAG
35 
36 // Logs a message with strerror(errno) at the end
37 #define PINFO    PLOG(INFO) << FS_MGR_TAG
38 #define PWARNING PLOG(WARNING) << FS_MGR_TAG
39 #define PERROR   PLOG(ERROR) << FS_MGR_TAG
40 #define PFATAL PLOG(FATAL) << FS_MGR_TAG
41 
42 #define CRYPTO_TMPFS_OPTIONS "size=512m,mode=0771,uid=1000,gid=1000"
43 
44 /* fstab has the following format:
45  *
46  * Any line starting with a # is a comment and ignored
47  *
48  * Any blank line is ignored
49  *
50  * All other lines must be in this format:
51  *   <source>  <mount_point> <fs_type> <mount_flags> <fs_options> <fs_mgr_options>
52  *
53  *   <mount_flags> is a comma separated list of flags that can be passed to the
54  *                 mount command.  The list includes noatime, nosuid, nodev, nodiratime,
55  *                 ro, rw, remount, defaults.
56  *
57  *   <fs_options> is a comma separated list of options accepted by the filesystem being
58  *                mounted.  It is passed directly to mount without being parsed
59  *
60  *   <fs_mgr_options> is a comma separated list of flags that control the operation of
61  *                     the fs_mgr program.  The list includes "wait", which will wait till
62  *                     the <source> file exists, and "check", which requests that the fs_mgr
63  *                     run an fscheck program on the <source> before mounting the filesystem.
64  *                     If check is specifed on a read-only filesystem, it is ignored.
65  *                     Also, "encryptable" means that filesystem can be encrypted.
66  *                     The "encryptable" flag _MUST_ be followed by a = and a string which
67  *                     is the location of the encryption keys.  It can either be a path
68  *                     to a file or partition which contains the keys, or the word "footer"
69  *                     which means the keys are in the last 16 Kbytes of the partition
70  *                     containing the filesystem.
71  *
72  * When the fs_mgr is requested to mount all filesystems, it will first mount all the
73  * filesystems that do _NOT_ specify check (including filesystems that are read-only and
74  * specify check, because check is ignored in that case) and then it will check and mount
75  * filesystem marked with check.
76  *
77  */
78 
79 #define DM_BUF_SIZE 4096
80 
81 using namespace std::chrono_literals;
82 
83 bool fs_mgr_is_device_unlocked();
84 
85 bool fs_mgr_is_f2fs(const std::string& blk_device);
86 
87 bool fs_mgr_filesystem_available(const std::string& filesystem);
88 std::string fs_mgr_get_context(const std::string& mount_point);
89 
90 namespace android {
91 namespace fs_mgr {
92 
93 bool UnmapDevice(const std::string& name);
94 
95 struct OverlayfsCheckResult {
96     bool supported;
97     std::string mount_flags;
98 };
99 
100 OverlayfsCheckResult CheckOverlayfs();
101 
102 }  // namespace fs_mgr
103 }  // namespace android
104