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__BEGIN_DECLS
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// Callback function for verity status
53typedef void (*fs_mgr_verity_state_callback)(struct fstab_rec *fstab,
54        const char *mount_point, int mode, int status);
55
56#define FS_MGR_MNTALL_DEV_IS_METADATA_ENCRYPTED 7
57#define FS_MGR_MNTALL_DEV_NEEDS_METADATA_ENCRYPTION 6
58#define FS_MGR_MNTALL_DEV_FILE_ENCRYPTED 5
59#define FS_MGR_MNTALL_DEV_NEEDS_RECOVERY 4
60#define FS_MGR_MNTALL_DEV_NEEDS_ENCRYPTION 3
61#define FS_MGR_MNTALL_DEV_MIGHT_BE_ENCRYPTED 2
62#define FS_MGR_MNTALL_DEV_NOT_ENCRYPTED 1
63#define FS_MGR_MNTALL_DEV_NOT_ENCRYPTABLE 0
64#define FS_MGR_MNTALL_FAIL (-1)
65int fs_mgr_mount_all(struct fstab *fstab, int mount_mode);
66
67#define FS_MGR_DOMNT_FAILED (-1)
68#define FS_MGR_DOMNT_BUSY (-2)
69#define FS_MGR_DOMNT_SUCCESS 0
70
71int fs_mgr_do_mount(struct fstab *fstab, const char *n_name, char *n_blk_device,
72                    char *tmp_mount_point);
73int fs_mgr_do_mount_one(struct fstab_rec *rec);
74int fs_mgr_do_tmpfs_mount(const char *n_name);
75int fs_mgr_unmount_all(struct fstab *fstab);
76struct fstab_rec const* fs_mgr_get_crypt_entry(struct fstab const* fstab);
77void fs_mgr_get_crypt_info(struct fstab* fstab, char* key_loc, char* real_blk_device, size_t size);
78bool fs_mgr_load_verity_state(int* mode);
79bool fs_mgr_update_verity_state(fs_mgr_verity_state_callback callback);
80int fs_mgr_swapon_all(struct fstab *fstab);
81
82int fs_mgr_do_format(struct fstab_rec *fstab, bool reserve_footer);
83
84#define FS_MGR_SETUP_VERITY_SKIPPED  (-3)
85#define FS_MGR_SETUP_VERITY_DISABLED (-2)
86#define FS_MGR_SETUP_VERITY_FAIL (-1)
87#define FS_MGR_SETUP_VERITY_SUCCESS 0
88int fs_mgr_setup_verity(struct fstab_rec *fstab, bool wait_for_verity_dev);
89
90__END_DECLS
91
92#endif /* __CORE_FS_MGR_H */
93