devicemapper/
shared_macros.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5// A module to contain functionality shared among the various types of
6// devices and implemented by means of macros.
7
8macro_rules! device {
9    ($s:ident) => {
10        $s.dev_info.device()
11    };
12}
13
14macro_rules! name {
15    ($s:ident) => {
16        match $s.dev_info.name() {
17            Some(n) => n,
18            None => panic!("Name is required for device"),
19        }
20    };
21}
22
23macro_rules! uuid {
24    ($s:ident) => {
25        $s.dev_info.uuid()
26    };
27}
28
29macro_rules! devnode {
30    ($s:ident) => {
31        ["/dev", &format!("dm-{}", $s.dev_info.device().minor)]
32            .iter()
33            .collect()
34    };
35}
36
37macro_rules! to_raw_table_unique {
38    ($s:ident) => {
39        vec![(
40            *$s.table.start,
41            *$s.table.length,
42            $s.table.params.target_type().to_string(),
43            $s.table.params.param_str(),
44        )]
45    };
46}
47
48macro_rules! table {
49    ($s:ident) => {
50        &$s.table
51    };
52}
53
54macro_rules! status {
55    ($s:ident, $dm:ident, $options:ident) => {
56        get_status(
57            &$dm.table_status(&$crate::core::DevId::Name($s.name()), $options)?
58                .1,
59        )?
60        .parse()
61    };
62}