blob: d32987a093d16370397a5856d4e43004e57b7c60 [file] [log] [blame]
Jiyong Park86c9b082021-06-04 19:03:48 +09001/*
2 * Copyright (C) 2021 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
17use bitflags::bitflags;
Jiyong Park3c327d22021-06-08 20:51:54 +090018use data_model::DataInit;
Jiyong Park86c9b082021-06-04 19:03:48 +090019
20// This UAPI is copied and converted from include/uapi/linux/loop.h Note that this module doesn't
21// implement all the features introduced in loop(4). Only the features that are required to support
22// the `apkdmverity` use cases are implemented.
23
24pub const LOOP_CONTROL: &str = "/dev/loop-control";
25
26pub const LOOP_CTL_GET_FREE: libc::c_ulong = 0x4C82;
Jooyung Han7ce2e532021-06-16 16:52:02 +090027pub const LOOP_SET_FD: libc::c_ulong = 0x4C00;
28pub const LOOP_SET_STATUS64: libc::c_ulong = 0x4C04;
Jiyong Park99a35b82021-06-07 10:13:44 +090029#[cfg(test)]
Jiyong Park86c9b082021-06-04 19:03:48 +090030pub const LOOP_CLR_FD: libc::c_ulong = 0x4C01;
31
32#[repr(C)]
Jiyong Park3c327d22021-06-08 20:51:54 +090033#[derive(Copy, Clone)]
Jiyong Park86c9b082021-06-04 19:03:48 +090034pub struct loop_config {
35 pub fd: u32,
36 pub block_size: u32,
37 pub info: loop_info64,
38 pub reserved: [u64; 8],
39}
40
Jiyong Park3c327d22021-06-08 20:51:54 +090041// SAFETY: C struct is safe to be initialized from raw data
42unsafe impl DataInit for loop_config {}
43
Jiyong Park86c9b082021-06-04 19:03:48 +090044#[repr(C)]
Jiyong Park3c327d22021-06-08 20:51:54 +090045#[derive(Copy, Clone)]
Jiyong Park86c9b082021-06-04 19:03:48 +090046pub struct loop_info64 {
47 pub lo_device: u64,
48 pub lo_inode: u64,
49 pub lo_rdevice: u64,
50 pub lo_offset: u64,
51 pub lo_sizelimit: u64,
52 pub lo_number: u32,
53 pub lo_encrypt_type: u32,
54 pub lo_encrypt_key_size: u32,
55 pub lo_flags: Flag,
56 pub lo_file_name: [u8; LO_NAME_SIZE],
57 pub lo_crypt_name: [u8; LO_NAME_SIZE],
58 pub lo_encrypt_key: [u8; LO_KEY_SIZE],
59 pub lo_init: [u64; 2],
60}
61
Jooyung Han7ce2e532021-06-16 16:52:02 +090062// SAFETY: C struct is safe to be initialized from raw data
63unsafe impl DataInit for loop_info64 {}
64
Jiyong Park86c9b082021-06-04 19:03:48 +090065bitflags! {
66 pub struct Flag: u32 {
67 const LO_FLAGS_READ_ONLY = 1 << 0;
68 const LO_FLAGS_AUTOCLEAR = 1 << 2;
69 const LO_FLAGS_PARTSCAN = 1 << 3;
70 const LO_FLAGS_DIRECT_IO = 1 << 4;
71 }
72}
73
74pub const LO_NAME_SIZE: usize = 64;
75pub const LO_KEY_SIZE: usize = 32;