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