blob: 3cecde3411886a47f0faaf007b202457a1fd8905 [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// UAPI for device mapper can be found at include/uapi/linux/dm-ioctl.h
21
22pub const DM_IOCTL: u8 = 0xfd;
23
24#[repr(u16)]
25#[allow(non_camel_case_types)]
26#[allow(dead_code)]
27pub enum Cmd {
28 DM_VERSION = 0,
29 DM_REMOVE_ALL,
30 DM_LIST_DEVICES,
31 DM_DEV_CREATE,
32 DM_DEV_REMOVE,
33 DM_DEV_RENAME,
34 DM_DEV_SUSPEND,
35 DM_DEV_STATUS,
36 DM_DEV_WAIT,
37 DM_TABLE_LOAD,
38 DM_TABLE_CLEAR,
39 DM_TABLE_DEPS,
40 DM_TABLE_STATUS,
41 DM_LIST_VERSIONS,
42 DM_TARGET_MSG,
43 DM_DEV_SET_GEOMETRY,
44}
45
46#[repr(C)]
Jiyong Park3c327d22021-06-08 20:51:54 +090047#[derive(Copy, Clone)]
Jiyong Park86c9b082021-06-04 19:03:48 +090048pub struct DmIoctl {
49 pub version: [u32; 3],
50 pub data_size: u32,
51 pub data_start: u32,
52 pub target_count: u32,
53 pub open_count: i32,
54 pub flags: Flag,
55 pub event_nr: u32,
56 pub padding: u32,
57 pub dev: u64,
58 pub name: [u8; DM_NAME_LEN],
59 pub uuid: [u8; DM_UUID_LEN],
60 pub data: [u8; 7],
61}
62
Jiyong Park3c327d22021-06-08 20:51:54 +090063// SAFETY: C struct is safe to be initialized from raw data
64unsafe impl DataInit for DmIoctl {}
65
Jiyong Park86c9b082021-06-04 19:03:48 +090066pub const DM_VERSION_MAJOR: u32 = 4;
67pub const DM_VERSION_MINOR: u32 = 0;
68pub const DM_VERSION_PATCHLEVEL: u32 = 0;
69
70pub const DM_NAME_LEN: usize = 128;
71pub const DM_UUID_LEN: usize = 129;
72pub const DM_MAX_TYPE_NAME: usize = 16;
73
74bitflags! {
Jakob Vukalovic53fddb32023-04-26 13:57:46 +010075 #[repr(transparent)]
76 #[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
Jiyong Park86c9b082021-06-04 19:03:48 +090077 pub struct Flag: u32 {
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}