1 /* 2 * Copyright (C) 2022 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 <string> 20 21 #include <fstab/fstab.h> 22 23 constexpr char kOverlayfsFileContext[] = "u:object_r:overlayfs_file:s0"; 24 25 constexpr char kScratchMountPoint[] = "/mnt/scratch"; 26 constexpr char kOverlayTopDir[] = "overlay"; 27 constexpr char kUpperName[] = "upper"; 28 constexpr char kWorkName[] = "work"; 29 30 #if ALLOW_ADBD_DISABLE_VERITY 31 constexpr bool kAllowOverlayfs = true; 32 #else 33 constexpr bool kAllowOverlayfs = false; 34 #endif 35 36 class AutoSetFsCreateCon final { 37 public: AutoSetFsCreateCon()38 AutoSetFsCreateCon() {} AutoSetFsCreateCon(const std::string & context)39 AutoSetFsCreateCon(const std::string& context) { Set(context); } ~AutoSetFsCreateCon()40 ~AutoSetFsCreateCon() { Restore(); } 41 Ok()42 bool Ok() const { return ok_; } 43 bool Set(const std::string& context); 44 bool Restore(); 45 46 private: 47 bool ok_ = false; 48 bool restored_ = false; 49 }; 50 51 bool fs_mgr_is_dsu_running(); 52 bool fs_mgr_filesystem_has_space(const std::string& mount_point); 53 const std::string fs_mgr_mount_point(const std::string& mount_point); 54 bool OverlayfsSetupAllowed(bool verbose = false); 55 bool MountScratch(const std::string& device_path, bool readonly = false); 56 bool fs_mgr_overlayfs_umount_scratch(); 57 std::vector<const std::string> OverlayMountPoints(); 58 bool fs_mgr_overlayfs_already_mounted(const std::string& mount_point, bool overlay_only = true); 59 bool fs_mgr_wants_overlayfs(android::fs_mgr::FstabEntry* entry); 60 android::fs_mgr::Fstab fs_mgr_overlayfs_candidate_list(const android::fs_mgr::Fstab& fstab); 61 std::string GetEncodedBaseDirForMountPoint(const std::string& mount_point); 62