Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/dm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
slice, str,
};

use nix::libc::ioctl as nix_ioctl;
use nix::libc::{dev_t, ioctl as nix_ioctl};

use crate::{
core::{
Expand Down Expand Up @@ -58,6 +58,7 @@ impl DmOptions {
flags: clean_flags.bits(),
event_nr,
data_start: size_of::<dmi::Struct_dm_ioctl>() as u32,
dev: dev_t::from(self.device()),
..Default::default()
};

Expand Down
29 changes: 27 additions & 2 deletions src/core/dm_options.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use crate::core::dm_flags::{DmCookie, DmFlags};
use crate::{
core::dm_flags::{DmCookie, DmFlags},
Device,
};

/// Encapsulates options for device mapper calls
#[derive(Clone, Copy, Debug, Default)]
#[derive(Clone, Copy, Debug)]
pub struct DmOptions {
flags: DmFlags,
cookie: DmCookie,
device: Device,
}

impl DmOptions {
Expand All @@ -25,6 +29,13 @@ impl DmOptions {
self
}

/// Sets the `Device` value for self. Replaces the previous value.
/// Consumes self.
pub fn set_device(mut self, device: Device) -> DmOptions {
self.device = device;
self
}

/// Retrieve the flags value
pub fn flags(&self) -> DmFlags {
self.flags
Expand All @@ -34,4 +45,18 @@ impl DmOptions {
pub fn cookie(&self) -> DmCookie {
self.cookie
}

pub fn device(&self) -> Device {
self.device
}
}

impl Default for DmOptions {
fn default() -> Self {
Self {
flags: Default::default(),
cookie: Default::default(),
device: Device { major: 0, minor: 0 },
}
}
}