Jiyong Park | 86c9b08 | 2021-06-04 19:03:48 +0900 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | use bitflags::bitflags; |
Frederick Mayle | 8f79590 | 2023-10-23 15:48:34 -0700 | [diff] [blame] | 18 | use zerocopy::AsBytes; |
| 19 | use zerocopy::FromZeroes; |
Jiyong Park | 86c9b08 | 2021-06-04 19:03:48 +0900 | [diff] [blame] | 20 | |
| 21 | // UAPI for device mapper can be found at include/uapi/linux/dm-ioctl.h |
| 22 | |
| 23 | pub const DM_IOCTL: u8 = 0xfd; |
| 24 | |
| 25 | #[repr(u16)] |
| 26 | #[allow(non_camel_case_types)] |
| 27 | #[allow(dead_code)] |
| 28 | pub enum Cmd { |
| 29 | DM_VERSION = 0, |
| 30 | DM_REMOVE_ALL, |
| 31 | DM_LIST_DEVICES, |
| 32 | DM_DEV_CREATE, |
| 33 | DM_DEV_REMOVE, |
| 34 | DM_DEV_RENAME, |
| 35 | DM_DEV_SUSPEND, |
| 36 | DM_DEV_STATUS, |
| 37 | DM_DEV_WAIT, |
| 38 | DM_TABLE_LOAD, |
| 39 | DM_TABLE_CLEAR, |
| 40 | DM_TABLE_DEPS, |
| 41 | DM_TABLE_STATUS, |
| 42 | DM_LIST_VERSIONS, |
| 43 | DM_TARGET_MSG, |
| 44 | DM_DEV_SET_GEOMETRY, |
| 45 | } |
| 46 | |
| 47 | #[repr(C)] |
Frederick Mayle | 8f79590 | 2023-10-23 15:48:34 -0700 | [diff] [blame] | 48 | #[derive(Copy, Clone, AsBytes, FromZeroes)] |
Jiyong Park | 86c9b08 | 2021-06-04 19:03:48 +0900 | [diff] [blame] | 49 | pub struct DmIoctl { |
| 50 | pub version: [u32; 3], |
| 51 | pub data_size: u32, |
| 52 | pub data_start: u32, |
| 53 | pub target_count: u32, |
| 54 | pub open_count: i32, |
| 55 | pub flags: Flag, |
| 56 | pub event_nr: u32, |
| 57 | pub padding: u32, |
| 58 | pub dev: u64, |
| 59 | pub name: [u8; DM_NAME_LEN], |
| 60 | pub uuid: [u8; DM_UUID_LEN], |
| 61 | pub data: [u8; 7], |
| 62 | } |
| 63 | |
Jiyong Park | 86c9b08 | 2021-06-04 19:03:48 +0900 | [diff] [blame] | 64 | pub const DM_VERSION_MAJOR: u32 = 4; |
| 65 | pub const DM_VERSION_MINOR: u32 = 0; |
| 66 | pub const DM_VERSION_PATCHLEVEL: u32 = 0; |
| 67 | |
| 68 | pub const DM_NAME_LEN: usize = 128; |
| 69 | pub const DM_UUID_LEN: usize = 129; |
| 70 | pub const DM_MAX_TYPE_NAME: usize = 16; |
| 71 | |
Frederick Mayle | 8f79590 | 2023-10-23 15:48:34 -0700 | [diff] [blame] | 72 | #[repr(transparent)] |
| 73 | #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, AsBytes, FromZeroes)] |
| 74 | pub struct Flag(u32); |
| 75 | |
Jiyong Park | 86c9b08 | 2021-06-04 19:03:48 +0900 | [diff] [blame] | 76 | bitflags! { |
Frederick Mayle | 8f79590 | 2023-10-23 15:48:34 -0700 | [diff] [blame] | 77 | impl Flag: u32 { |
Jiyong Park | 86c9b08 | 2021-06-04 19:03:48 +0900 | [diff] [blame] | 78 | const DM_READONLY_FLAG = 1 << 0; |
| 79 | const DM_SUSPEND_FLAG = 1 << 1; |
| 80 | const DM_PERSISTENT_DEV_FLAG = 1 << 3; |
| 81 | const DM_STATUS_TABLE_FLAG = 1 << 4; |
| 82 | const DM_ACTIVE_PRESENT_FLAG = 1 << 5; |
| 83 | const DM_INACTIVE_PRESENT_FLAG = 1 << 6; |
| 84 | const DM_BUFFER_FULL_FLAG = 1 << 8; |
| 85 | const DM_SKIP_BDGET_FLAG = 1 << 9; |
| 86 | const DM_SKIP_LOCKFS_FLAG = 1 << 10; |
| 87 | const DM_NOFLUSH_FLAG = 1 << 11; |
| 88 | const DM_QUERY_INACTIVE_TABLE_FLAG = 1 << 12; |
| 89 | const DM_UEVENT_GENERATED_FLAG = 1 << 13; |
| 90 | const DM_UUID_FLAG = 1 << 14; |
| 91 | const DM_SECURE_DATA_FLAG = 1 << 15; |
| 92 | const DM_DATA_OUT_FLAG = 1 << 16; |
| 93 | const DM_DEFERRED_REMOVE = 1 << 17; |
| 94 | const DM_INTERNAL_SUSPEND_FLAG = 1 << 18; |
| 95 | } |
| 96 | } |