blob: bd1e165dc20e5408850fc5e4c0ec0865015e5f75 [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;
Frederick Mayle8f795902023-10-23 15:48:34 -070018use zerocopy::AsBytes;
19use zerocopy::FromZeroes;
Jiyong Park86c9b082021-06-04 19:03:48 +090020
21// UAPI for device mapper can be found at include/uapi/linux/dm-ioctl.h
22
23pub const DM_IOCTL: u8 = 0xfd;
24
25#[repr(u16)]
26#[allow(non_camel_case_types)]
27#[allow(dead_code)]
28pub 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 Mayle8f795902023-10-23 15:48:34 -070048#[derive(Copy, Clone, AsBytes, FromZeroes)]
Jiyong Park86c9b082021-06-04 19:03:48 +090049pub 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 Park86c9b082021-06-04 19:03:48 +090064pub const DM_VERSION_MAJOR: u32 = 4;
65pub const DM_VERSION_MINOR: u32 = 0;
66pub const DM_VERSION_PATCHLEVEL: u32 = 0;
67
68pub const DM_NAME_LEN: usize = 128;
69pub const DM_UUID_LEN: usize = 129;
70pub const DM_MAX_TYPE_NAME: usize = 16;
71
Frederick Mayle8f795902023-10-23 15:48:34 -070072#[repr(transparent)]
73#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, AsBytes, FromZeroes)]
74pub struct Flag(u32);
75
Jiyong Park86c9b082021-06-04 19:03:48 +090076bitflags! {
Frederick Mayle8f795902023-10-23 15:48:34 -070077 impl Flag: u32 {
Jiyong Park86c9b082021-06-04 19:03:48 +090078 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}