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_H 18 #define __CORE_FS_MGR_H 19 20 #include <stdint.h> 21 #include <linux/dm-ioctl.h> 22 23 // Magic number at start of verity metadata 24 #define VERITY_METADATA_MAGIC_NUMBER 0xb001b001 25 26 // Replacement magic number at start of verity metadata to cleanly 27 // turn verity off in userdebug builds. 28 #define VERITY_METADATA_MAGIC_DISABLE 0x46464f56 // "VOFF" 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 // Verity modes 35 enum verity_mode { 36 VERITY_MODE_EIO = 0, 37 VERITY_MODE_LOGGING = 1, 38 VERITY_MODE_RESTART = 2, 39 VERITY_MODE_LAST = VERITY_MODE_RESTART, 40 VERITY_MODE_DEFAULT = VERITY_MODE_RESTART 41 }; 42 43 // Mount modes 44 enum mount_mode { 45 MOUNT_MODE_DEFAULT = 0, 46 MOUNT_MODE_EARLY = 1, 47 MOUNT_MODE_LATE = 2 48 }; 49 50 /* 51 * The entries must be kept in the same order as they were seen in the fstab. 52 * Unless explicitly requested, a lookup on mount point should always 53 * return the 1st one. 54 */ 55 struct fstab { 56 int num_entries; 57 struct fstab_rec *recs; 58 char *fstab_filename; 59 }; 60 61 struct fstab_rec { 62 char *blk_device; 63 char *mount_point; 64 char *fs_type; 65 unsigned long flags; 66 char *fs_options; 67 int fs_mgr_flags; 68 char *key_loc; 69 char *verity_loc; 70 long long length; 71 char *label; 72 int partnum; 73 int swap_prio; 74 unsigned int zram_size; 75 unsigned int file_encryption_mode; 76 }; 77 78 // Callback function for verity status 79 typedef void (*fs_mgr_verity_state_callback)(struct fstab_rec *fstab, 80 const char *mount_point, int mode, int status); 81 82 struct fstab *fs_mgr_read_fstab(const char *fstab_path); 83 void fs_mgr_free_fstab(struct fstab *fstab); 84 85 #define FS_MGR_MNTALL_DEV_FILE_ENCRYPTED 5 86 #define FS_MGR_MNTALL_DEV_NEEDS_RECOVERY 4 87 #define FS_MGR_MNTALL_DEV_NEEDS_ENCRYPTION 3 88 #define FS_MGR_MNTALL_DEV_MIGHT_BE_ENCRYPTED 2 89 #define FS_MGR_MNTALL_DEV_NOT_ENCRYPTED 1 90 #define FS_MGR_MNTALL_DEV_NOT_ENCRYPTABLE 0 91 #define FS_MGR_MNTALL_FAIL -1 92 int fs_mgr_mount_all(struct fstab *fstab, int mount_mode); 93 94 #define FS_MGR_DOMNT_FAILED -1 95 #define FS_MGR_DOMNT_BUSY -2 96 97 int fs_mgr_do_mount(struct fstab *fstab, char *n_name, char *n_blk_device, 98 char *tmp_mount_point); 99 int fs_mgr_do_tmpfs_mount(char *n_name); 100 int fs_mgr_unmount_all(struct fstab *fstab); 101 int fs_mgr_get_crypt_info(struct fstab *fstab, char *key_loc, 102 char *real_blk_device, int size); 103 int fs_mgr_load_verity_state(int *mode); 104 int fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback); 105 int fs_mgr_add_entry(struct fstab *fstab, 106 const char *mount_point, const char *fs_type, 107 const char *blk_device); 108 struct fstab_rec *fs_mgr_get_entry_for_mount_point(struct fstab *fstab, const char *path); 109 int fs_mgr_is_voldmanaged(const struct fstab_rec *fstab); 110 int fs_mgr_is_nonremovable(const struct fstab_rec *fstab); 111 int fs_mgr_is_verified(const struct fstab_rec *fstab); 112 int fs_mgr_is_encryptable(const struct fstab_rec *fstab); 113 int fs_mgr_is_file_encrypted(const struct fstab_rec *fstab); 114 const char* fs_mgr_get_file_encryption_mode(const struct fstab_rec *fstab); 115 int fs_mgr_is_convertible_to_fbe(const struct fstab_rec *fstab); 116 int fs_mgr_is_noemulatedsd(const struct fstab_rec *fstab); 117 int fs_mgr_is_notrim(struct fstab_rec *fstab); 118 int fs_mgr_is_formattable(struct fstab_rec *fstab); 119 int fs_mgr_is_nofail(struct fstab_rec *fstab); 120 int fs_mgr_is_latemount(struct fstab_rec *fstab); 121 int fs_mgr_swapon_all(struct fstab *fstab); 122 123 int fs_mgr_do_format(struct fstab_rec *fstab); 124 125 #ifdef __cplusplus 126 } 127 #endif 128 129 #endif /* __CORE_FS_MGR_H */ 130