1 /*
2  * Copyright (C) 2023 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 //! Stable API definition copied from uapi/linux/fsverity.h
18 
19 use nix::{ioctl_readwrite, ioctl_write_ptr};
20 
21 const FS_IOCTL_MAGIC: u8 = b'f';
22 const FS_IOC_ENABLE_VERITY: u8 = 133;
23 const FS_IOCTL_READ_VERITY_METADATA: u8 = 135;
24 
25 pub const FS_VERITY_HASH_ALG_SHA256: u32 = 1;
26 pub const FS_VERITY_METADATA_TYPE_MERKLE_TREE: u64 = 1;
27 pub const FS_VERITY_METADATA_TYPE_SIGNATURE: u64 = 3;
28 
29 #[repr(C)]
30 pub struct fsverity_read_metadata_arg {
31     pub metadata_type: u64,
32     pub offset: u64,
33     pub length: u64,
34     pub buf_ptr: u64,
35     pub __reserved: u64,
36 }
37 
38 ioctl_readwrite!(
39     read_verity_metadata,
40     FS_IOCTL_MAGIC,
41     FS_IOCTL_READ_VERITY_METADATA,
42     fsverity_read_metadata_arg
43 );
44 
45 #[repr(C)]
46 pub struct fsverity_enable_arg {
47     pub version: u32,
48     pub hash_algorithm: u32,
49     pub block_size: u32,
50     pub salt_size: u32,
51     pub salt_ptr: u64,
52     pub sig_size: u32,
53     pub __reserved1: u32,
54     pub sig_ptr: u64,
55     pub __reserved2: [u64; 11],
56 }
57 
58 ioctl_write_ptr!(enable_verity, FS_IOCTL_MAGIC, FS_IOC_ENABLE_VERITY, fsverity_enable_arg);
59