1*e1997b9aSAndroid Build Coastguard Worker /* 2*e1997b9aSAndroid Build Coastguard Worker * Copyright (C) 2023 The Android Open Source Project 3*e1997b9aSAndroid Build Coastguard Worker * 4*e1997b9aSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*e1997b9aSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*e1997b9aSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*e1997b9aSAndroid Build Coastguard Worker * 8*e1997b9aSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*e1997b9aSAndroid Build Coastguard Worker * 10*e1997b9aSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*e1997b9aSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*e1997b9aSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*e1997b9aSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*e1997b9aSAndroid Build Coastguard Worker * limitations under the License. 15*e1997b9aSAndroid Build Coastguard Worker */ 16*e1997b9aSAndroid Build Coastguard Worker 17*e1997b9aSAndroid Build Coastguard Worker //! Stable API definition copied from uapi/linux/fsverity.h 18*e1997b9aSAndroid Build Coastguard Worker 19*e1997b9aSAndroid Build Coastguard Worker use nix::{ioctl_readwrite, ioctl_write_ptr}; 20*e1997b9aSAndroid Build Coastguard Worker 21*e1997b9aSAndroid Build Coastguard Worker const FS_IOCTL_MAGIC: u8 = b'f'; 22*e1997b9aSAndroid Build Coastguard Worker const FS_IOC_ENABLE_VERITY: u8 = 133; 23*e1997b9aSAndroid Build Coastguard Worker const FS_IOCTL_READ_VERITY_METADATA: u8 = 135; 24*e1997b9aSAndroid Build Coastguard Worker 25*e1997b9aSAndroid Build Coastguard Worker pub const FS_VERITY_HASH_ALG_SHA256: u32 = 1; 26*e1997b9aSAndroid Build Coastguard Worker pub const FS_VERITY_METADATA_TYPE_MERKLE_TREE: u64 = 1; 27*e1997b9aSAndroid Build Coastguard Worker pub const FS_VERITY_METADATA_TYPE_SIGNATURE: u64 = 3; 28*e1997b9aSAndroid Build Coastguard Worker 29*e1997b9aSAndroid Build Coastguard Worker #[repr(C)] 30*e1997b9aSAndroid Build Coastguard Worker pub struct fsverity_read_metadata_arg { 31*e1997b9aSAndroid Build Coastguard Worker pub metadata_type: u64, 32*e1997b9aSAndroid Build Coastguard Worker pub offset: u64, 33*e1997b9aSAndroid Build Coastguard Worker pub length: u64, 34*e1997b9aSAndroid Build Coastguard Worker pub buf_ptr: u64, 35*e1997b9aSAndroid Build Coastguard Worker pub __reserved: u64, 36*e1997b9aSAndroid Build Coastguard Worker } 37*e1997b9aSAndroid Build Coastguard Worker 38*e1997b9aSAndroid Build Coastguard Worker ioctl_readwrite!( 39*e1997b9aSAndroid Build Coastguard Worker read_verity_metadata, 40*e1997b9aSAndroid Build Coastguard Worker FS_IOCTL_MAGIC, 41*e1997b9aSAndroid Build Coastguard Worker FS_IOCTL_READ_VERITY_METADATA, 42*e1997b9aSAndroid Build Coastguard Worker fsverity_read_metadata_arg 43*e1997b9aSAndroid Build Coastguard Worker ); 44*e1997b9aSAndroid Build Coastguard Worker 45*e1997b9aSAndroid Build Coastguard Worker #[repr(C)] 46*e1997b9aSAndroid Build Coastguard Worker pub struct fsverity_enable_arg { 47*e1997b9aSAndroid Build Coastguard Worker pub version: u32, 48*e1997b9aSAndroid Build Coastguard Worker pub hash_algorithm: u32, 49*e1997b9aSAndroid Build Coastguard Worker pub block_size: u32, 50*e1997b9aSAndroid Build Coastguard Worker pub salt_size: u32, 51*e1997b9aSAndroid Build Coastguard Worker pub salt_ptr: u64, 52*e1997b9aSAndroid Build Coastguard Worker pub sig_size: u32, 53*e1997b9aSAndroid Build Coastguard Worker pub __reserved1: u32, 54*e1997b9aSAndroid Build Coastguard Worker pub sig_ptr: u64, 55*e1997b9aSAndroid Build Coastguard Worker pub __reserved2: [u64; 11], 56*e1997b9aSAndroid Build Coastguard Worker } 57*e1997b9aSAndroid Build Coastguard Worker 58*e1997b9aSAndroid Build Coastguard Worker ioctl_write_ptr!(enable_verity, FS_IOCTL_MAGIC, FS_IOC_ENABLE_VERITY, fsverity_enable_arg); 59