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 #ifndef __CORE_FS_MGR_PRIV_H
18 #define __CORE_FS_MGR_PRIV_H
19 
20 #include <android-base/logging.h>
21 #include <fs_mgr.h>
22 #include "fs_mgr_priv_boot_config.h"
23 
24 /* The CHECK() in logging.h will use program invocation name as the tag.
25  * Thus, the log will have prefix "init: " when libfs_mgr is statically
26  * linked in the init process. This might be opaque when debugging.
27  * Appends "in libfs_mgr" at the end of the abort message to explicitly
28  * indicate the check happens in fs_mgr.
29  */
30 #define FS_MGR_CHECK(x) CHECK(x) << "in libfs_mgr "
31 
32 #define FS_MGR_TAG "[libfs_mgr]"
33 
34 // Logs a message to kernel
35 #define LINFO    LOG(INFO) << FS_MGR_TAG
36 #define LWARNING LOG(WARNING) << FS_MGR_TAG
37 #define LERROR   LOG(ERROR) << FS_MGR_TAG
38 
39 // Logs a message with strerror(errno) at the end
40 #define PINFO    PLOG(INFO) << FS_MGR_TAG
41 #define PWARNING PLOG(WARNING) << FS_MGR_TAG
42 #define PERROR   PLOG(ERROR) << FS_MGR_TAG
43 
44 #define CRYPTO_TMPFS_OPTIONS "size=256m,mode=0771,uid=1000,gid=1000"
45 
46 #define WAIT_TIMEOUT 20
47 
48 /* fstab has the following format:
49  *
50  * Any line starting with a # is a comment and ignored
51  *
52  * Any blank line is ignored
53  *
54  * All other lines must be in this format:
55  *   <source>  <mount_point> <fs_type> <mount_flags> <fs_options> <fs_mgr_options>
56  *
57  *   <mount_flags> is a comma separated list of flags that can be passed to the
58  *                 mount command.  The list includes noatime, nosuid, nodev, nodiratime,
59  *                 ro, rw, remount, defaults.
60  *
61  *   <fs_options> is a comma separated list of options accepted by the filesystem being
62  *                mounted.  It is passed directly to mount without being parsed
63  *
64  *   <fs_mgr_options> is a comma separated list of flags that control the operation of
65  *                     the fs_mgr program.  The list includes "wait", which will wait till
66  *                     the <source> file exists, and "check", which requests that the fs_mgr
67  *                     run an fscheck program on the <source> before mounting the filesystem.
68  *                     If check is specifed on a read-only filesystem, it is ignored.
69  *                     Also, "encryptable" means that filesystem can be encrypted.
70  *                     The "encryptable" flag _MUST_ be followed by a = and a string which
71  *                     is the location of the encryption keys.  It can either be a path
72  *                     to a file or partition which contains the keys, or the word "footer"
73  *                     which means the keys are in the last 16 Kbytes of the partition
74  *                     containing the filesystem.
75  *
76  * When the fs_mgr is requested to mount all filesystems, it will first mount all the
77  * filesystems that do _NOT_ specify check (including filesystems that are read-only and
78  * specify check, because check is ignored in that case) and then it will check and mount
79  * filesystem marked with check.
80  *
81  */
82 
83 #define MF_WAIT                  0x1
84 #define MF_CHECK                 0x2
85 #define MF_CRYPT                 0x4
86 #define MF_NONREMOVABLE          0x8
87 #define MF_VOLDMANAGED          0x10
88 #define MF_LENGTH               0x20
89 #define MF_RECOVERYONLY         0x40
90 #define MF_SWAPPRIO             0x80
91 #define MF_ZRAMSIZE            0x100
92 #define MF_VERIFY              0x200
93 #define MF_FORCECRYPT          0x400
94 #define MF_NOEMULATEDSD        0x800 /* no emulated sdcard daemon, sd card is the only
95                                         external storage */
96 #define MF_NOTRIM             0x1000
97 #define MF_FILEENCRYPTION     0x2000
98 #define MF_FORMATTABLE        0x4000
99 #define MF_SLOTSELECT         0x8000
100 #define MF_FORCEFDEORFBE     0x10000
101 #define MF_LATEMOUNT         0x20000
102 #define MF_NOFAIL            0x40000
103 #define MF_VERIFYATBOOT      0x80000
104 #define MF_MAX_COMP_STREAMS 0x100000
105 #define MF_RESERVEDSIZE     0x200000
106 #define MF_QUOTA            0x400000
107 #define MF_ERASEBLKSIZE     0x800000
108 #define MF_LOGICALBLKSIZE  0X1000000
109 #define MF_AVB             0X2000000
110 
111 #define DM_BUF_SIZE 4096
112 
113 int fs_mgr_set_blk_ro(const char *blockdev);
114 int fs_mgr_test_access(const char *device);
115 bool fs_mgr_update_for_slotselect(struct fstab *fstab);
116 bool is_dt_compatible();
117 bool is_device_secure();
118 int load_verity_state(struct fstab_rec* fstab, int* mode);
119 
120 #endif /* __CORE_FS_MGR_PRIV_H */
121