Ken Sumrall | 7574c03 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 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 | |
Geremy Condra | 3ad3d1c | 2013-02-22 18:11:41 -0800 | [diff] [blame] | 20 | #include <stdint.h> |
Chuanxiao Dong | d78dff1 | 2016-03-08 15:54:55 +0100 | [diff] [blame] | 21 | #include <stdbool.h> |
Geremy Condra | 3ad3d1c | 2013-02-22 18:11:41 -0800 | [diff] [blame] | 22 | #include <linux/dm-ioctl.h> |
| 23 | |
Paul Lawrence | bbb3631 | 2014-10-09 14:22:49 +0000 | [diff] [blame] | 24 | // Magic number at start of verity metadata |
| 25 | #define VERITY_METADATA_MAGIC_NUMBER 0xb001b001 |
| 26 | |
| 27 | // Replacement magic number at start of verity metadata to cleanly |
| 28 | // turn verity off in userdebug builds. |
| 29 | #define VERITY_METADATA_MAGIC_DISABLE 0x46464f56 // "VOFF" |
| 30 | |
Sami Tolvanen | acbf9be | 2015-03-19 10:00:34 +0000 | [diff] [blame] | 31 | #ifdef __cplusplus |
| 32 | extern "C" { |
| 33 | #endif |
| 34 | |
Sami Tolvanen | 51bf11a | 2015-02-16 10:27:21 +0000 | [diff] [blame] | 35 | // Verity modes |
| 36 | enum verity_mode { |
| 37 | VERITY_MODE_EIO = 0, |
| 38 | VERITY_MODE_LOGGING = 1, |
| 39 | VERITY_MODE_RESTART = 2, |
Sami Tolvanen | 946a0f3 | 2015-03-22 12:40:05 +0000 | [diff] [blame] | 40 | VERITY_MODE_LAST = VERITY_MODE_RESTART, |
| 41 | VERITY_MODE_DEFAULT = VERITY_MODE_RESTART |
Sami Tolvanen | 51bf11a | 2015-02-16 10:27:21 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
JP Abgrall | 5c01dac | 2014-06-18 14:54:37 -0700 | [diff] [blame] | 44 | /* |
| 45 | * The entries must be kept in the same order as they were seen in the fstab. |
| 46 | * Unless explicitly requested, a lookup on mount point should always |
| 47 | * return the 1st one. |
| 48 | */ |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 49 | struct fstab { |
| 50 | int num_entries; |
| 51 | struct fstab_rec *recs; |
| 52 | char *fstab_filename; |
| 53 | }; |
| 54 | |
| 55 | struct fstab_rec { |
| 56 | char *blk_device; |
| 57 | char *mount_point; |
| 58 | char *fs_type; |
| 59 | unsigned long flags; |
| 60 | char *fs_options; |
| 61 | int fs_mgr_flags; |
| 62 | char *key_loc; |
Geremy Condra | 3ad3d1c | 2013-02-22 18:11:41 -0800 | [diff] [blame] | 63 | char *verity_loc; |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 64 | long long length; |
| 65 | char *label; |
| 66 | int partnum; |
Ken Sumrall | 5bc31a2 | 2013-07-08 19:11:55 -0700 | [diff] [blame] | 67 | int swap_prio; |
| 68 | unsigned int zram_size; |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 69 | }; |
| 70 | |
Sami Tolvanen | acbf9be | 2015-03-19 10:00:34 +0000 | [diff] [blame] | 71 | // Callback function for verity status |
| 72 | typedef void (*fs_mgr_verity_state_callback)(struct fstab_rec *fstab, |
Sami Tolvanen | 4547423 | 2015-03-30 11:38:38 +0100 | [diff] [blame] | 73 | const char *mount_point, int mode, int status); |
Sami Tolvanen | acbf9be | 2015-03-19 10:00:34 +0000 | [diff] [blame] | 74 | |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 75 | struct fstab *fs_mgr_read_fstab(const char *fstab_path); |
| 76 | void fs_mgr_free_fstab(struct fstab *fstab); |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 77 | |
Paul Lawrence | c410b3b | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 78 | #define FS_MGR_MNTALL_DEV_NON_DEFAULT_FILE_ENCRYPTED 5 |
| 79 | #define FS_MGR_MNTALL_DEV_DEFAULT_FILE_ENCRYPTED 4 |
JP Abgrall | cee2068 | 2014-07-02 14:26:54 -0700 | [diff] [blame] | 80 | #define FS_MGR_MNTALL_DEV_NEEDS_RECOVERY 3 |
JP Abgrall | f22b745 | 2014-07-02 13:16:04 -0700 | [diff] [blame] | 81 | #define FS_MGR_MNTALL_DEV_NEEDS_ENCRYPTION 2 |
| 82 | #define FS_MGR_MNTALL_DEV_MIGHT_BE_ENCRYPTED 1 |
| 83 | #define FS_MGR_MNTALL_DEV_NOT_ENCRYPTED 0 |
Chih-Hung Hsieh | c713bce | 2016-05-18 15:59:37 -0700 | [diff] [blame] | 84 | #define FS_MGR_MNTALL_FAIL (-1) |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 85 | int fs_mgr_mount_all(struct fstab *fstab); |
Paul Lawrence | cf234dc | 2014-09-09 10:44:51 -0700 | [diff] [blame] | 86 | |
Chih-Hung Hsieh | c713bce | 2016-05-18 15:59:37 -0700 | [diff] [blame] | 87 | #define FS_MGR_DOMNT_FAILED (-1) |
| 88 | #define FS_MGR_DOMNT_BUSY (-2) |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 89 | int fs_mgr_do_mount(struct fstab *fstab, char *n_name, char *n_blk_device, |
| 90 | char *tmp_mount_point); |
Ken Sumrall | 7574c03 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 91 | int fs_mgr_do_tmpfs_mount(char *n_name); |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 92 | int fs_mgr_unmount_all(struct fstab *fstab); |
| 93 | int fs_mgr_get_crypt_info(struct fstab *fstab, char *key_loc, |
| 94 | char *real_blk_device, int size); |
Sami Tolvanen | 51bf11a | 2015-02-16 10:27:21 +0000 | [diff] [blame] | 95 | int fs_mgr_load_verity_state(int *mode); |
Sami Tolvanen | acbf9be | 2015-03-19 10:00:34 +0000 | [diff] [blame] | 96 | int fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback); |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 97 | int fs_mgr_add_entry(struct fstab *fstab, |
| 98 | const char *mount_point, const char *fs_type, |
Sasha Levitskiy | cdc1cfb | 2014-04-10 17:10:21 -0700 | [diff] [blame] | 99 | const char *blk_device); |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 100 | struct fstab_rec *fs_mgr_get_entry_for_mount_point(struct fstab *fstab, const char *path); |
Paul Lawrence | c410b3b | 2015-03-26 15:49:42 +0000 | [diff] [blame] | 101 | int fs_mgr_is_voldmanaged(const struct fstab_rec *fstab); |
| 102 | int fs_mgr_is_nonremovable(const struct fstab_rec *fstab); |
| 103 | int fs_mgr_is_verified(const struct fstab_rec *fstab); |
| 104 | int fs_mgr_is_encryptable(const struct fstab_rec *fstab); |
| 105 | int fs_mgr_is_file_encrypted(const struct fstab_rec *fstab); |
| 106 | int fs_mgr_is_noemulatedsd(const struct fstab_rec *fstab); |
Paul Lawrence | 84b0bab | 2015-03-26 14:53:19 +0000 | [diff] [blame] | 107 | int fs_mgr_is_notrim(struct fstab_rec *fstab); |
Chris Fries | 79f3384 | 2013-09-05 13:19:21 -0500 | [diff] [blame] | 108 | int fs_mgr_is_formattable(struct fstab_rec *fstab); |
Daniel Rosenberg | de551ff | 2016-04-07 20:10:25 -0700 | [diff] [blame] | 109 | int fs_mgr_is_nofail(struct fstab_rec *fstab); |
Ken Sumrall | 5bc31a2 | 2013-07-08 19:11:55 -0700 | [diff] [blame] | 110 | int fs_mgr_swapon_all(struct fstab *fstab); |
Chris Fries | 79f3384 | 2013-09-05 13:19:21 -0500 | [diff] [blame] | 111 | |
Chuanxiao Dong | d78dff1 | 2016-03-08 15:54:55 +0100 | [diff] [blame] | 112 | int fs_mgr_do_format(struct fstab_rec *fstab, bool reserve_footer); |
Chris Fries | 79f3384 | 2013-09-05 13:19:21 -0500 | [diff] [blame] | 113 | |
Ken Sumrall | ab6b852 | 2013-02-13 12:58:40 -0800 | [diff] [blame] | 114 | #ifdef __cplusplus |
| 115 | } |
| 116 | #endif |
Ken Sumrall | 7574c03 | 2012-01-06 19:09:42 -0800 | [diff] [blame] | 117 | |
| 118 | #endif /* __CORE_FS_MGR_H */ |