Skip to content

Commit 501d82d

Browse files
Add device parameter to DmOptions
Corresponds to the dev field in the dm_ioctl struct. Used in a few ioctls - in particular, its needed for create with DM_PERSISTENT.
1 parent b9a75ae commit 501d82d

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

src/core/dm.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{
1111
slice, str,
1212
};
1313

14-
use nix::libc::ioctl as nix_ioctl;
14+
use nix::libc::{dev_t, ioctl as nix_ioctl};
1515

1616
use crate::{
1717
core::{
@@ -58,6 +58,7 @@ impl DmOptions {
5858
flags: clean_flags.bits(),
5959
event_nr,
6060
data_start: size_of::<dmi::Struct_dm_ioctl>() as u32,
61+
dev: dev_t::from(self.device()),
6162
..Default::default()
6263
};
6364

src/core/dm_options.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// This Source Code Form is subject to the terms of the Mozilla Public
22
// License, v. 2.0. If a copy of the MPL was not distributed with this
33
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4-
use crate::core::dm_flags::{DmCookie, DmFlags};
4+
use crate::{
5+
core::dm_flags::{DmCookie, DmFlags},
6+
Device,
7+
};
58

69
/// Encapsulates options for device mapper calls
7-
#[derive(Clone, Copy, Debug, Default)]
10+
#[derive(Clone, Copy, Debug)]
811
pub struct DmOptions {
912
flags: DmFlags,
1013
cookie: DmCookie,
14+
device: Device,
1115
}
1216

1317
impl DmOptions {
@@ -25,6 +29,13 @@ impl DmOptions {
2529
self
2630
}
2731

32+
/// Sets the `Device` value for self. Replaces the previous value.
33+
/// Consumes self.
34+
pub fn set_device(mut self, device: Device) -> DmOptions {
35+
self.device = device;
36+
self
37+
}
38+
2839
/// Retrieve the flags value
2940
pub fn flags(&self) -> DmFlags {
3041
self.flags
@@ -34,4 +45,18 @@ impl DmOptions {
3445
pub fn cookie(&self) -> DmCookie {
3546
self.cookie
3647
}
48+
49+
pub fn device(&self) -> Device {
50+
self.device
51+
}
52+
}
53+
54+
impl Default for DmOptions {
55+
fn default() -> Self {
56+
Self {
57+
flags: Default::default(),
58+
cookie: Default::default(),
59+
device: Device { major: 0, minor: 0 },
60+
}
61+
}
3762
}

0 commit comments

Comments
 (0)