fs_mgr_priv.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #pragma once
  17. #include <chrono>
  18. #include <string>
  19. #include <android-base/logging.h>
  20. #include <fs_mgr.h>
  21. #include <fstab/fstab.h>
  22. #include "fs_mgr_priv_boot_config.h"
  23. /* The CHECK() in logging.h will use program invocation name as the tag.
  24. * Thus, the log will have prefix "init: " when libfs_mgr is statically
  25. * linked in the init process. This might be opaque when debugging.
  26. * Appends "in libfs_mgr" at the end of the abort message to explicitly
  27. * indicate the check happens in fs_mgr.
  28. */
  29. #define FS_MGR_CHECK(x) CHECK(x) << "in libfs_mgr "
  30. #define FS_MGR_TAG "[libfs_mgr]"
  31. // Logs a message to kernel
  32. #define LINFO LOG(INFO) << FS_MGR_TAG
  33. #define LWARNING LOG(WARNING) << FS_MGR_TAG
  34. #define LERROR LOG(ERROR) << FS_MGR_TAG
  35. #define LFATAL LOG(FATAL) << FS_MGR_TAG
  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. #define CRYPTO_TMPFS_OPTIONS "size=512m,mode=0771,uid=1000,gid=1000"
  42. /* fstab has the following format:
  43. *
  44. * Any line starting with a # is a comment and ignored
  45. *
  46. * Any blank line is ignored
  47. *
  48. * All other lines must be in this format:
  49. * <source> <mount_point> <fs_type> <mount_flags> <fs_options> <fs_mgr_options>
  50. *
  51. * <mount_flags> is a comma separated list of flags that can be passed to the
  52. * mount command. The list includes noatime, nosuid, nodev, nodiratime,
  53. * ro, rw, remount, defaults.
  54. *
  55. * <fs_options> is a comma separated list of options accepted by the filesystem being
  56. * mounted. It is passed directly to mount without being parsed
  57. *
  58. * <fs_mgr_options> is a comma separated list of flags that control the operation of
  59. * the fs_mgr program. The list includes "wait", which will wait till
  60. * the <source> file exists, and "check", which requests that the fs_mgr
  61. * run an fscheck program on the <source> before mounting the filesystem.
  62. * If check is specifed on a read-only filesystem, it is ignored.
  63. * Also, "encryptable" means that filesystem can be encrypted.
  64. * The "encryptable" flag _MUST_ be followed by a = and a string which
  65. * is the location of the encryption keys. It can either be a path
  66. * to a file or partition which contains the keys, or the word "footer"
  67. * which means the keys are in the last 16 Kbytes of the partition
  68. * containing the filesystem.
  69. *
  70. * When the fs_mgr is requested to mount all filesystems, it will first mount all the
  71. * filesystems that do _NOT_ specify check (including filesystems that are read-only and
  72. * specify check, because check is ignored in that case) and then it will check and mount
  73. * filesystem marked with check.
  74. *
  75. */
  76. #define DM_BUF_SIZE 4096
  77. using namespace std::chrono_literals;
  78. enum class FileWaitMode { Exists, DoesNotExist };
  79. bool fs_mgr_wait_for_file(const std::string& filename,
  80. const std::chrono::milliseconds relative_timeout,
  81. FileWaitMode wait_mode = FileWaitMode::Exists);
  82. bool fs_mgr_set_blk_ro(const std::string& blockdev, bool readonly = true);
  83. bool fs_mgr_update_for_slotselect(android::fs_mgr::Fstab* fstab);
  84. bool fs_mgr_is_device_unlocked();
  85. const std::string& get_android_dt_dir();
  86. bool is_dt_compatible();
  87. int load_verity_state(const android::fs_mgr::FstabEntry& entry, int* mode);
  88. bool fs_mgr_is_ext4(const std::string& blk_device);
  89. bool fs_mgr_is_f2fs(const std::string& blk_device);
  90. bool fs_mgr_teardown_verity(android::fs_mgr::FstabEntry* fstab, bool wait);
  91. namespace android {
  92. namespace fs_mgr {
  93. bool UnmapDevice(const std::string& name, const std::chrono::milliseconds& timeout_ms);
  94. } // namespace fs_mgr
  95. } // namespace android