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