• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
18 use data_model::DataInit;
19 
20 // UAPI for device mapper can be found at include/uapi/linux/dm-ioctl.h
21 
22 pub const DM_IOCTL: u8 = 0xfd;
23 
24 #[repr(u16)]
25 #[allow(non_camel_case_types)]
26 #[allow(dead_code)]
27 pub 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)]
47 #[derive(Copy, Clone)]
48 pub 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 
63 // SAFETY: C struct is safe to be initialized from raw data
64 unsafe impl DataInit for DmIoctl {}
65 
66 pub const DM_VERSION_MAJOR: u32 = 4;
67 pub const DM_VERSION_MINOR: u32 = 0;
68 pub const DM_VERSION_PATCHLEVEL: u32 = 0;
69 
70 pub const DM_NAME_LEN: usize = 128;
71 pub const DM_UUID_LEN: usize = 129;
72 pub const DM_MAX_TYPE_NAME: usize = 16;
73 
74 bitflags! {
75     pub struct Flag: u32 {
76         const DM_READONLY_FLAG = 1 << 0;
77         const DM_SUSPEND_FLAG = 1 << 1;
78         const DM_PERSISTENT_DEV_FLAG = 1 << 3;
79         const DM_STATUS_TABLE_FLAG = 1 << 4;
80         const DM_ACTIVE_PRESENT_FLAG = 1 << 5;
81         const DM_INACTIVE_PRESENT_FLAG = 1 << 6;
82         const DM_BUFFER_FULL_FLAG = 1 << 8;
83         const DM_SKIP_BDGET_FLAG = 1 << 9;
84         const DM_SKIP_LOCKFS_FLAG = 1 << 10;
85         const DM_NOFLUSH_FLAG = 1 << 11;
86         const DM_QUERY_INACTIVE_TABLE_FLAG = 1 << 12;
87         const DM_UEVENT_GENERATED_FLAG = 1 << 13;
88         const DM_UUID_FLAG = 1 << 14;
89         const DM_SECURE_DATA_FLAG = 1 << 15;
90         const DM_DATA_OUT_FLAG = 1 << 16;
91         const DM_DEFERRED_REMOVE = 1 << 17;
92         const DM_INTERNAL_SUSPEND_FLAG = 1 << 18;
93     }
94 }
95