@@ -10,16 +10,13 @@ use std::{cmp, slice, u32};
1010use nix:: libc:: c_ulong;
1111use nix:: libc:: ioctl as nix_ioctl;
1212
13- use crate :: device:: Device ;
14- use crate :: deviceinfo:: { DeviceInfo , DM_NAME_LEN , DM_UUID_LEN } ;
15- use crate :: dm_flags:: DmFlags ;
16- use crate :: dm_ioctl as dmi;
17- use crate :: dm_options:: DmOptions ;
18- use crate :: errors:: ErrorKind ;
13+ use crate :: core:: { DevId , Device , DeviceInfo , DmFlags , DmName , DmNameBuf , DmOptions , DmUuid } ;
1914use crate :: result:: { DmError , DmResult } ;
2015
21- use crate :: types:: { DevId , DmName , DmNameBuf , DmUuid , Sectors , TargetTypeBuf } ;
22- use crate :: util:: { align_to, slice_to_null} ;
16+ use crate :: core:: deviceinfo:: { DM_NAME_LEN , DM_UUID_LEN } ;
17+ use crate :: core:: dm_ioctl as dmi;
18+ use crate :: core:: errors:: ErrorKind ;
19+ use crate :: core:: util:: { align_to, slice_to_null} ;
2320
2421/// Indicator to send IOCTL to DM
2522const DM_IOCTL : u8 = 0xfd ;
@@ -401,7 +398,7 @@ impl DM {
401398 & self ,
402399 id : & DevId ,
403400 options : & DmOptions ,
404- ) -> DmResult < ( DeviceInfo , Vec < ( Sectors , Sectors , TargetTypeBuf , String ) > ) > {
401+ ) -> DmResult < ( DeviceInfo , Vec < ( u64 , u64 , String , String ) > ) > {
405402 let mut hdr = options. to_ioctl_hdr ( Some ( id) , DmFlags :: DM_QUERY_INACTIVE_TABLE ) ;
406403
407404 let data_out = self . do_ioctl ( dmi:: DM_DEV_WAIT_CMD as u8 , & mut hdr, None ) ?;
@@ -423,15 +420,15 @@ impl DM {
423420 /// # Example
424421 ///
425422 /// ```no_run
426- /// use devicemapper::{DM, DevId, DmName, Sectors, TargetTypeBuf };
423+ /// use devicemapper::{DM, DevId, DmName};
427424 /// let dm = DM::new().unwrap();
428425 ///
429426 /// // Create a 16MiB device (32768 512-byte sectors) that maps to /dev/sdb1
430427 /// // starting 1MiB into sdb1
431428 /// let table = vec![(
432- /// Sectors(0) ,
433- /// Sectors( 32768) ,
434- /// TargetTypeBuf::new( "linear".into()).expect("valid" ),
429+ /// 0 ,
430+ /// 32768,
431+ /// "linear".into(),
435432 /// "/dev/sdb1 2048".into()
436433 /// )];
437434 ///
@@ -442,16 +439,16 @@ impl DM {
442439 pub fn table_load (
443440 & self ,
444441 id : & DevId ,
445- targets : & [ ( Sectors , Sectors , TargetTypeBuf , String ) ] ,
442+ targets : & [ ( u64 , u64 , String , String ) ] ,
446443 ) -> DmResult < DeviceInfo > {
447444 let mut targs = Vec :: new ( ) ;
448445
449446 // Construct targets first, since we need to know how many & size
450447 // before initializing the header.
451448 for t in targets {
452449 let mut targ: dmi:: Struct_dm_target_spec = Default :: default ( ) ;
453- targ. sector_start = * t. 0 ;
454- targ. length = * t. 1 ;
450+ targ. sector_start = t. 0 ;
451+ targ. length = t. 1 ;
455452 targ. status = 0 ;
456453
457454 let dst: & mut [ u8 ] = unsafe { & mut * ( & mut targ. target_type [ ..] as * mut [ u8 ] ) } ;
@@ -548,16 +545,15 @@ impl DM {
548545 /// Panics if there is an error parsing the table.
549546 /// Trims trailing white space off final entry on each line. This
550547 /// canonicalization makes checking identity of tables easier.
548+ /// Postcondition: The length of the next to last entry in any tuple is
549+ /// no more than 16 characters.
551550 // Justification: If the ioctl succeeded, the data is correct and
552551 // complete. An error in parsing can only result from a change in the
553552 // kernel. We rely on DM's interface versioning system. Kernel changes
554553 // will either be backwards-compatible, or will increment
555554 // DM_VERSION_MAJOR. Since calls made with a non-matching major version
556555 // will fail, this protects against callers parsing unknown formats.
557- fn parse_table_status (
558- count : u32 ,
559- buf : & [ u8 ] ,
560- ) -> Vec < ( Sectors , Sectors , TargetTypeBuf , String ) > {
556+ fn parse_table_status ( count : u32 , buf : & [ u8 ] ) -> Vec < ( u64 , u64 , String , String ) > {
561557 let mut targets = Vec :: new ( ) ;
562558 if !buf. is_empty ( ) {
563559 let mut next_off = 0 ;
@@ -583,12 +579,7 @@ impl DM {
583579 String :: from_utf8_lossy ( slc) . trim_end ( ) . to_owned ( )
584580 } ;
585581
586- targets. push ( (
587- Sectors ( targ. sector_start ) ,
588- Sectors ( targ. length ) ,
589- TargetTypeBuf :: new ( target_type) . expect ( "< sizeof target_spec" ) ,
590- params,
591- ) ) ;
582+ targets. push ( ( targ. sector_start , targ. length , target_type, params) ) ;
592583
593584 next_off = targ. next as usize ;
594585 }
@@ -629,7 +620,7 @@ impl DM {
629620 & self ,
630621 id : & DevId ,
631622 options : & DmOptions ,
632- ) -> DmResult < ( DeviceInfo , Vec < ( Sectors , Sectors , TargetTypeBuf , String ) > ) > {
623+ ) -> DmResult < ( DeviceInfo , Vec < ( u64 , u64 , String , String ) > ) > {
633624 let mut hdr = options. to_ioctl_hdr (
634625 Some ( id) ,
635626 DmFlags :: DM_NOFLUSH | DmFlags :: DM_STATUS_TABLE | DmFlags :: DM_QUERY_INACTIVE_TABLE ,
@@ -683,13 +674,13 @@ impl DM {
683674 pub fn target_msg (
684675 & self ,
685676 id : & DevId ,
686- sector : Option < Sectors > ,
677+ sector : Option < u64 > ,
687678 msg : & str ,
688679 ) -> DmResult < ( DeviceInfo , Option < String > ) > {
689680 let mut hdr = DmOptions :: new ( ) . to_ioctl_hdr ( Some ( id) , DmFlags :: empty ( ) ) ;
690681
691682 let mut msg_struct: dmi:: Struct_dm_target_msg = Default :: default ( ) ;
692- msg_struct. sector = * sector. unwrap_or_default ( ) ;
683+ msg_struct. sector = sector. unwrap_or_default ( ) ;
693684 let mut data_in = unsafe {
694685 let ptr = & msg_struct as * const dmi:: Struct_dm_target_msg as * mut u8 ;
695686 slice:: from_raw_parts ( ptr, size_of :: < dmi:: Struct_dm_target_msg > ( ) ) . to_vec ( )
@@ -723,10 +714,11 @@ impl DM {
723714#[ cfg( test) ]
724715mod tests {
725716
726- use crate :: errors:: Error ;
727717 use crate :: result:: DmError ;
728718 use crate :: test_lib:: { test_name, test_uuid} ;
729719
720+ use crate :: core:: errors:: Error ;
721+
730722 use super :: * ;
731723
732724 #[ test]
0 commit comments