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 <stdio.h> 21 #include <stdint.h> 22 #include <stdbool.h> 23 #include <linux/dm-ioctl.h> 24 25 #include <fstab/fstab.h> 26 27 // Magic number at start of verity metadata 28 #define VERITY_METADATA_MAGIC_NUMBER 0xb001b001 29 30 // Replacement magic number at start of verity metadata to cleanly 31 // turn verity off in userdebug builds. 32 #define VERITY_METADATA_MAGIC_DISABLE 0x46464f56 // "VOFF" 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 // Callback function for verity status 51 typedef void (*fs_mgr_verity_state_callback)(struct fstab_rec *fstab, 52 const char *mount_point, int mode, int status); 53 54 #define FS_MGR_MNTALL_DEV_IS_METADATA_ENCRYPTED 7 55 #define FS_MGR_MNTALL_DEV_NEEDS_METADATA_ENCRYPTION 6 56 #define FS_MGR_MNTALL_DEV_FILE_ENCRYPTED 5 57 #define FS_MGR_MNTALL_DEV_NEEDS_RECOVERY 4 58 #define FS_MGR_MNTALL_DEV_NEEDS_ENCRYPTION 3 59 #define FS_MGR_MNTALL_DEV_MIGHT_BE_ENCRYPTED 2 60 #define FS_MGR_MNTALL_DEV_NOT_ENCRYPTED 1 61 #define FS_MGR_MNTALL_DEV_NOT_ENCRYPTABLE 0 62 #define FS_MGR_MNTALL_FAIL (-1) 63 int fs_mgr_mount_all(struct fstab *fstab, int mount_mode); 64 65 #define FS_MGR_DOMNT_FAILED (-1) 66 #define FS_MGR_DOMNT_BUSY (-2) 67 #define FS_MGR_DOMNT_SUCCESS 0 68 69 int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device, 70 char *tmp_mount_point); 71 int fs_mgr_do_mount_one(struct fstab_rec *rec); 72 int fs_mgr_do_tmpfs_mount(const char *n_name); 73 int fs_mgr_unmount_all(struct fstab *fstab); 74 struct fstab_rec const* fs_mgr_get_crypt_entry(struct fstab const* fstab); 75 void fs_mgr_get_crypt_info(struct fstab* fstab, char* key_loc, char* real_blk_device, size_t size); 76 bool fs_mgr_load_verity_state(int* mode); 77 bool fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback); 78 int fs_mgr_swapon_all(struct fstab *fstab); 79 80 int fs_mgr_do_format(struct fstab_rec *fstab, bool reserve_footer); 81 82 #define FS_MGR_SETUP_VERITY_SKIPPED (-3) 83 #define FS_MGR_SETUP_VERITY_DISABLED (-2) 84 #define FS_MGR_SETUP_VERITY_FAIL (-1) 85 #define FS_MGR_SETUP_VERITY_SUCCESS 0 86 int fs_mgr_setup_verity(struct fstab_rec *fstab, bool wait_for_verity_dev); 87 88 #endif /* __CORE_FS_MGR_H */ 89