Ken Sumrall | 7574c03 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 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 | |
Jinguang Dong | 9d34496 | 2017-06-13 10:20:34 +0800 | [diff] [blame] | 20 | #include <chrono> |
| 21 | #include <string> |
| 22 | |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame] | 23 | #include <android-base/logging.h> |
Bowgo Tsai | c1bc281 | 2018-11-26 17:49:23 +0800 | [diff] [blame] | 24 | #include <fs_mgr.h> |
Tom Cherry | d0be7a5 | 2018-11-29 13:04:52 -0800 | [diff] [blame] | 25 | #include <fstab/fstab.h> |
Jinguang Dong | 9d34496 | 2017-06-13 10:20:34 +0800 | [diff] [blame] | 26 | |
Sandeep Patil | 9de748f | 2017-02-16 19:15:29 -0800 | [diff] [blame] | 27 | #include "fs_mgr_priv_boot_config.h" |
Ken Sumrall | 7574c03 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 28 | |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 29 | /* The CHECK() in logging.h will use program invocation name as the tag. |
| 30 | * Thus, the log will have prefix "init: " when libfs_mgr is statically |
| 31 | * linked in the init process. This might be opaque when debugging. |
| 32 | * Appends "in libfs_mgr" at the end of the abort message to explicitly |
| 33 | * indicate the check happens in fs_mgr. |
| 34 | */ |
| 35 | #define FS_MGR_CHECK(x) CHECK(x) << "in libfs_mgr " |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame] | 36 | |
| 37 | #define FS_MGR_TAG "[libfs_mgr]" |
| 38 | |
| 39 | // Logs a message to kernel |
| 40 | #define LINFO LOG(INFO) << FS_MGR_TAG |
| 41 | #define LWARNING LOG(WARNING) << FS_MGR_TAG |
| 42 | #define LERROR LOG(ERROR) << FS_MGR_TAG |
David Anderson | 0bfa1c8 | 2018-10-30 15:06:46 -0700 | [diff] [blame] | 43 | #define LFATAL LOG(FATAL) << FS_MGR_TAG |
bowgotsai | 47878de | 2017-01-23 14:04:34 +0800 | [diff] [blame] | 44 | |
| 45 | // Logs a message with strerror(errno) at the end |
| 46 | #define PINFO PLOG(INFO) << FS_MGR_TAG |
| 47 | #define PWARNING PLOG(WARNING) << FS_MGR_TAG |
| 48 | #define PERROR PLOG(ERROR) << FS_MGR_TAG |
David Anderson | 0bfa1c8 | 2018-10-30 15:06:46 -0700 | [diff] [blame] | 49 | #define PFATAL PLOG(FATAL) << FS_MGR_TAG |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 50 | |
Paul Lawrence | 7fdcbdf | 2018-04-13 12:28:42 -0700 | [diff] [blame] | 51 | #define CRYPTO_TMPFS_OPTIONS "size=512m,mode=0771,uid=1000,gid=1000" |
Ken Sumrall | 7574c03 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 52 | |
Ken Sumrall | 7574c03 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 53 | /* fstab has the following format: |
| 54 | * |
| 55 | * Any line starting with a # is a comment and ignored |
| 56 | * |
| 57 | * Any blank line is ignored |
| 58 | * |
| 59 | * All other lines must be in this format: |
| 60 | * <source> <mount_point> <fs_type> <mount_flags> <fs_options> <fs_mgr_options> |
| 61 | * |
| 62 | * <mount_flags> is a comma separated list of flags that can be passed to the |
| 63 | * mount command. The list includes noatime, nosuid, nodev, nodiratime, |
| 64 | * ro, rw, remount, defaults. |
| 65 | * |
| 66 | * <fs_options> is a comma separated list of options accepted by the filesystem being |
| 67 | * mounted. It is passed directly to mount without being parsed |
| 68 | * |
| 69 | * <fs_mgr_options> is a comma separated list of flags that control the operation of |
| 70 | * the fs_mgr program. The list includes "wait", which will wait till |
Wei Wang | 254f443 | 2016-08-23 11:58:09 -0700 | [diff] [blame] | 71 | * the <source> file exists, and "check", which requests that the fs_mgr |
Ken Sumrall | 7574c03 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 72 | * run an fscheck program on the <source> before mounting the filesystem. |
| 73 | * If check is specifed on a read-only filesystem, it is ignored. |
| 74 | * Also, "encryptable" means that filesystem can be encrypted. |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 75 | * The "encryptable" flag _MUST_ be followed by a = and a string which |
| 76 | * is the location of the encryption keys. It can either be a path |
Ken Sumrall | 7574c03 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 77 | * to a file or partition which contains the keys, or the word "footer" |
| 78 | * which means the keys are in the last 16 Kbytes of the partition |
| 79 | * containing the filesystem. |
| 80 | * |
| 81 | * When the fs_mgr is requested to mount all filesystems, it will first mount all the |
| 82 | * filesystems that do _NOT_ specify check (including filesystems that are read-only and |
| 83 | * specify check, because check is ignored in that case) and then it will check and mount |
| 84 | * filesystem marked with check. |
| 85 | * |
| 86 | */ |
| 87 | |
David Anderson | 62e5b20 | 2018-05-01 17:09:17 -0700 | [diff] [blame] | 88 | // clang-format off |
Jeff Sharkey | 6d89610 | 2016-12-14 12:00:51 -0700 | [diff] [blame] | 89 | #define MF_WAIT 0x1 |
| 90 | #define MF_CHECK 0x2 |
| 91 | #define MF_CRYPT 0x4 |
| 92 | #define MF_NONREMOVABLE 0x8 |
| 93 | #define MF_VOLDMANAGED 0x10 |
| 94 | #define MF_LENGTH 0x20 |
| 95 | #define MF_RECOVERYONLY 0x40 |
| 96 | #define MF_SWAPPRIO 0x80 |
| 97 | #define MF_ZRAMSIZE 0x100 |
| 98 | #define MF_VERIFY 0x200 |
| 99 | #define MF_FORCECRYPT 0x400 |
| 100 | #define MF_NOEMULATEDSD 0x800 /* no emulated sdcard daemon, sd card is the only |
| 101 | external storage */ |
| 102 | #define MF_NOTRIM 0x1000 |
| 103 | #define MF_FILEENCRYPTION 0x2000 |
| 104 | #define MF_FORMATTABLE 0x4000 |
| 105 | #define MF_SLOTSELECT 0x8000 |
| 106 | #define MF_FORCEFDEORFBE 0x10000 |
| 107 | #define MF_LATEMOUNT 0x20000 |
| 108 | #define MF_NOFAIL 0x40000 |
| 109 | #define MF_VERIFYATBOOT 0x80000 |
Jin Qian | 0067e03 | 2016-11-18 16:37:53 -0800 | [diff] [blame] | 110 | #define MF_MAX_COMP_STREAMS 0x100000 |
Jeff Sharkey | 6d89610 | 2016-12-14 12:00:51 -0700 | [diff] [blame] | 111 | #define MF_RESERVEDSIZE 0x200000 |
| 112 | #define MF_QUOTA 0x400000 |
Connor O'Brien | 46fec48 | 2017-01-24 17:50:39 -0800 | [diff] [blame] | 113 | #define MF_ERASEBLKSIZE 0x800000 |
| 114 | #define MF_LOGICALBLKSIZE 0X1000000 |
bowgotsai | b51722b | 2017-01-11 22:21:38 +0800 | [diff] [blame] | 115 | #define MF_AVB 0X2000000 |
Jaegeuk Kim | efd3b9c | 2018-02-22 18:10:05 -0800 | [diff] [blame] | 116 | #define MF_KEYDIRECTORY 0X4000000 |
| 117 | #define MF_SYSFS 0X8000000 |
David Anderson | 62e5b20 | 2018-05-01 17:09:17 -0700 | [diff] [blame] | 118 | #define MF_LOGICAL 0x10000000 |
Daniel Rosenberg | 4c93b25 | 2018-08-28 01:41:18 -0700 | [diff] [blame] | 119 | #define MF_CHECKPOINT_BLK 0x20000000 |
| 120 | #define MF_CHECKPOINT_FS 0x40000000 |
Tom Cherry | e68bf85 | 2018-10-25 16:10:23 -0700 | [diff] [blame] | 121 | #define MF_FIRST_STAGE_MOUNT \ |
| 122 | 0x80000000 |
David Anderson | 62e5b20 | 2018-05-01 17:09:17 -0700 | [diff] [blame] | 123 | // clang-format on |
Geremy Condra | 3ad3d1c | 2013-02-22 18:11:41 -0800 | [diff] [blame] | 124 | |
| 125 | #define DM_BUF_SIZE 4096 |
Ken Sumrall | 7574c03 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 126 | |
Jinguang Dong | 9d34496 | 2017-06-13 10:20:34 +0800 | [diff] [blame] | 127 | using namespace std::chrono_literals; |
| 128 | |
David Anderson | c8ac4e7 | 2018-09-06 17:25:03 -0700 | [diff] [blame] | 129 | enum class FileWaitMode { Exists, DoesNotExist }; |
| 130 | |
Jinguang Dong | 9d34496 | 2017-06-13 10:20:34 +0800 | [diff] [blame] | 131 | bool fs_mgr_wait_for_file(const std::string& filename, |
David Anderson | c8ac4e7 | 2018-09-06 17:25:03 -0700 | [diff] [blame] | 132 | const std::chrono::milliseconds relative_timeout, |
| 133 | FileWaitMode wait_mode = FileWaitMode::Exists); |
| 134 | |
Tom Cherry | 0d2621f | 2018-12-04 13:15:09 -0800 | [diff] [blame] | 135 | bool fs_mgr_set_blk_ro(const std::string& blockdev); |
Tom Cherry | d0be7a5 | 2018-11-29 13:04:52 -0800 | [diff] [blame] | 136 | bool fs_mgr_update_for_slotselect(Fstab* fstab); |
Bowgo Tsai | d1fe3bd | 2017-07-05 15:37:15 +0800 | [diff] [blame] | 137 | bool fs_mgr_is_device_unlocked(); |
Yu Ning | c01022a | 2017-07-26 17:54:08 +0800 | [diff] [blame] | 138 | const std::string& get_android_dt_dir(); |
Sandeep Patil | e396c60 | 2017-02-24 11:04:49 -0800 | [diff] [blame] | 139 | bool is_dt_compatible(); |
Mark Salyzyn | b5ca728 | 2018-08-29 10:44:33 -0700 | [diff] [blame] | 140 | int load_verity_state(fstab_rec* fstab, int* mode); |
Sami Tolvanen | 214f33b | 2014-12-18 16:15:30 +0000 | [diff] [blame] | 141 | |
Ken Sumrall | 7574c03 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 142 | #endif /* __CORE_FS_MGR_PRIV_H */ |