From 724a3dc0e3b6807f4b4669414b90b819e3e98608 Mon Sep 17 00:00:00 2001 From: Alex Parrill Date: Thu, 15 Sep 2022 15:53:41 -0400 Subject: [PATCH] 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. --- src/core/dm.rs | 3 ++- src/core/dm_options.rs | 29 +++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/core/dm.rs b/src/core/dm.rs index e1fc7de5..b2e52cd0 100644 --- a/src/core/dm.rs +++ b/src/core/dm.rs @@ -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::{ @@ -58,6 +58,7 @@ impl DmOptions { flags: clean_flags.bits(), event_nr, data_start: size_of::() as u32, + dev: dev_t::from(self.device()), ..Default::default() }; diff --git a/src/core/dm_options.rs b/src/core/dm_options.rs index a4756772..ad724b8e 100644 --- a/src/core/dm_options.rs +++ b/src/core/dm_options.rs @@ -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 { @@ -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 @@ -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 }, + } + } }