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 bool fs_mgr_set_blk_ro(const std::string& blockdev, bool readonly = true); 92 bool fs_mgr_update_for_slotselect(android::fs_mgr::Fstab* fstab); 93 bool fs_mgr_is_device_unlocked(); 94 const std::string& get_android_dt_dir(); 95 bool is_dt_compatible(); 96 97 bool fs_mgr_is_ext4(const std::string& blk_device); 98 bool fs_mgr_is_f2fs(const std::string& blk_device); 99 100 bool fs_mgr_teardown_verity(android::fs_mgr::FstabEntry* fstab); 101 102 namespace android { 103 namespace fs_mgr { 104 bool UnmapDevice(const std::string& name); 105 } // namespace fs_mgr 106 } // namespace android 107