blob: 46d8f974384496420fefec11b2e542ff07bd9346 [file] [log] [blame]
Ken Sumrall7574c032012-01-06 19:09:42 -08001/*
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 Condra3ad3d1c2013-02-22 18:11:41 -080020#include <stdint.h>
21#include <linux/dm-ioctl.h>
22
Paul Lawrencebbb36312014-10-09 14:22:49 +000023// 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
Sami Tolvanenacbf9be2015-03-19 10:00:34 +000030#ifdef __cplusplus
31extern "C" {
32#endif
33
Sami Tolvanen51bf11a2015-02-16 10:27:21 +000034// Verity modes
35enum verity_mode {
36 VERITY_MODE_EIO = 0,
37 VERITY_MODE_LOGGING = 1,
38 VERITY_MODE_RESTART = 2,
Sami Tolvanen946a0f32015-03-22 12:40:05 +000039 VERITY_MODE_LAST = VERITY_MODE_RESTART,
40 VERITY_MODE_DEFAULT = VERITY_MODE_RESTART
Sami Tolvanen51bf11a2015-02-16 10:27:21 +000041};
42
JP Abgrall5c01dac2014-06-18 14:54:37 -070043/*
44 * The entries must be kept in the same order as they were seen in the fstab.
45 * Unless explicitly requested, a lookup on mount point should always
46 * return the 1st one.
47 */
Ken Sumrallab6b8522013-02-13 12:58:40 -080048struct fstab {
49 int num_entries;
50 struct fstab_rec *recs;
51 char *fstab_filename;
52};
53
54struct fstab_rec {
55 char *blk_device;
56 char *mount_point;
57 char *fs_type;
58 unsigned long flags;
59 char *fs_options;
60 int fs_mgr_flags;
61 char *key_loc;
Geremy Condra3ad3d1c2013-02-22 18:11:41 -080062 char *verity_loc;
Ken Sumrallab6b8522013-02-13 12:58:40 -080063 long long length;
64 char *label;
65 int partnum;
Ken Sumrall5bc31a22013-07-08 19:11:55 -070066 int swap_prio;
67 unsigned int zram_size;
Paul Lawrence4e898a02016-05-24 04:56:37 -070068 unsigned int file_encryption_mode;
Ken Sumrallab6b8522013-02-13 12:58:40 -080069};
70
Sami Tolvanenacbf9be2015-03-19 10:00:34 +000071// Callback function for verity status
72typedef void (*fs_mgr_verity_state_callback)(struct fstab_rec *fstab,
Sami Tolvanen45474232015-03-30 11:38:38 +010073 const char *mount_point, int mode, int status);
Sami Tolvanenacbf9be2015-03-19 10:00:34 +000074
Ken Sumrallab6b8522013-02-13 12:58:40 -080075struct fstab *fs_mgr_read_fstab(const char *fstab_path);
76void fs_mgr_free_fstab(struct fstab *fstab);
JP Abgrallf22b7452014-07-02 13:16:04 -070077
Paul Lawrence1098aac2016-03-04 15:52:33 -080078#define FS_MGR_MNTALL_DEV_FILE_ENCRYPTED 5
79#define FS_MGR_MNTALL_DEV_NEEDS_RECOVERY 4
80#define FS_MGR_MNTALL_DEV_NEEDS_ENCRYPTION 3
81#define FS_MGR_MNTALL_DEV_MIGHT_BE_ENCRYPTED 2
82#define FS_MGR_MNTALL_DEV_NOT_ENCRYPTED 1
83#define FS_MGR_MNTALL_DEV_NOT_ENCRYPTABLE 0
Paul Lawrencec410b3b2015-03-26 15:49:42 +000084#define FS_MGR_MNTALL_FAIL -1
Ken Sumrallab6b8522013-02-13 12:58:40 -080085int fs_mgr_mount_all(struct fstab *fstab);
Paul Lawrencecf234dc2014-09-09 10:44:51 -070086
87#define FS_MGR_DOMNT_FAILED -1
88#define FS_MGR_DOMNT_BUSY -2
Paul Lawrence5b8a1082016-05-05 11:00:44 -070089
Ken Sumrallab6b8522013-02-13 12:58:40 -080090int fs_mgr_do_mount(struct fstab *fstab, char *n_name, char *n_blk_device,
91 char *tmp_mount_point);
Ken Sumrall7574c032012-01-06 19:09:42 -080092int fs_mgr_do_tmpfs_mount(char *n_name);
Ken Sumrallab6b8522013-02-13 12:58:40 -080093int fs_mgr_unmount_all(struct fstab *fstab);
94int fs_mgr_get_crypt_info(struct fstab *fstab, char *key_loc,
95 char *real_blk_device, int size);
Sami Tolvanen51bf11a2015-02-16 10:27:21 +000096int fs_mgr_load_verity_state(int *mode);
Sami Tolvanenacbf9be2015-03-19 10:00:34 +000097int fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback);
Ken Sumrallab6b8522013-02-13 12:58:40 -080098int fs_mgr_add_entry(struct fstab *fstab,
99 const char *mount_point, const char *fs_type,
Sasha Levitskiycdc1cfb2014-04-10 17:10:21 -0700100 const char *blk_device);
Ken Sumrallab6b8522013-02-13 12:58:40 -0800101struct fstab_rec *fs_mgr_get_entry_for_mount_point(struct fstab *fstab, const char *path);
Paul Lawrencec410b3b2015-03-26 15:49:42 +0000102int fs_mgr_is_voldmanaged(const struct fstab_rec *fstab);
103int fs_mgr_is_nonremovable(const struct fstab_rec *fstab);
104int fs_mgr_is_verified(const struct fstab_rec *fstab);
105int fs_mgr_is_encryptable(const struct fstab_rec *fstab);
106int fs_mgr_is_file_encrypted(const struct fstab_rec *fstab);
Paul Lawrence4e898a02016-05-24 04:56:37 -0700107const char* fs_mgr_get_file_encryption_mode(const struct fstab_rec *fstab);
Paul Lawrenceb262d682015-10-29 10:31:02 -0700108int fs_mgr_is_convertible_to_fbe(const struct fstab_rec *fstab);
Paul Lawrencec410b3b2015-03-26 15:49:42 +0000109int fs_mgr_is_noemulatedsd(const struct fstab_rec *fstab);
Paul Lawrence84b0bab2015-03-26 14:53:19 +0000110int fs_mgr_is_notrim(struct fstab_rec *fstab);
Chris Fries79f33842013-09-05 13:19:21 -0500111int fs_mgr_is_formattable(struct fstab_rec *fstab);
Daniel Rosenbergd38e3c52016-04-07 20:10:25 -0700112int fs_mgr_is_nofail(struct fstab_rec *fstab);
Ken Sumrall5bc31a22013-07-08 19:11:55 -0700113int fs_mgr_swapon_all(struct fstab *fstab);
Chris Fries79f33842013-09-05 13:19:21 -0500114
115int fs_mgr_do_format(struct fstab_rec *fstab);
116
Ken Sumrallab6b8522013-02-13 12:58:40 -0800117#ifdef __cplusplus
118}
119#endif
Ken Sumrall7574c032012-01-06 19:09:42 -0800120
121#endif /* __CORE_FS_MGR_H */