1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// 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/.

//! Low-level devicemapper configuration of the running kernel.
//!
//! # Overview
//!
//! Linux's devicemapper allows the creation of block devices whose
//! storage is mapped to other block devices in useful ways, either by
//! changing the location of its data blocks, or performing some
//! operation on the data itself. This is a low-level facility that is
//! used by higher-level volume managers such as LVM2. Uses may
//! include:
//!
//! * Dividing a large block device into smaller logical volumes (dm-linear)
//! * Combining several separate block devices into a single block
//!   device with better performance and/or redundancy (dm-raid)
//! * Encrypting a block device (dm-crypt)
//! * Performing Copy-on-Write (COW) allocation of a volume's blocks
//!   enabling fast volume cloning and snapshots (dm-thin)
//! * Configuring a smaller, faster block device to act as a cache for a
//!   larger, slower one (dm-cache)
//! * Verifying the contents of a read-only volume (dm-verity)
//!
//! # Usage
//!
//! Before they can be used, DM devices must be created using
//! `DM::device_create()`, have a mapping table loaded using
//! `DM::table_load()`, and then activated with
//! `DM::device_suspend()`. (This function is used for both suspending
//! and activating a device.) Once activated, they can be used as a
//! regular block device, including having other DM devices map to
//! them.
//!
//! Devices have "active" and "inactive" mapping tables. See function
//! descriptions for which table they affect.

#![cfg_attr(feature = "clippy", feature(plugin))]
#![cfg_attr(feature = "clippy", plugin(clippy))]
#![cfg_attr(not(features = "clippy"), allow(unknown_lints))]

#![allow(doc_markdown)]

#![warn(missing_docs)]

#[macro_use]
extern crate custom_derive;
#[macro_use]
extern crate newtype_derive;

extern crate libc;
#[macro_use]
extern crate nix;
extern crate serde;
#[macro_use]
extern crate bitflags;
#[macro_use]
extern crate error_chain;

#[macro_use]
extern crate log;

#[cfg(test)]
extern crate loopdev;
#[cfg(test)]
extern crate tempdir;

#[allow(dead_code, non_camel_case_types)]
mod dm_ioctl;
/// public utilities
mod util;
/// basic types (Bytes, Sectors, DataBlocks)
mod types;
/// shared constants
mod consts;
/// Macros shared by device mapper devices.
#[macro_use]
mod shared_macros;
/// functions to create continuous linear space given device segments
mod lineardev;
/// allocate a device from a pool
mod thindev;
/// the id the pool uses to track its devices
mod thindevid;
/// thinpooldev is shared space for  other thin provisioned devices to use
mod thinpooldev;
/// struct to represent a location, offset and size of a set of disk sectors
mod segment;
/// return results container
mod result;
/// wrapper for C interface for DM
mod deviceinfo;
/// contains device major/minor and associated functions
mod device;
/// core lower level API
mod dm;
/// functionality shared between devices
mod shared;
/// error chain errors for core dm
mod errors;

#[cfg(test)]
mod loopbacked;


pub use consts::{IEC, SECTOR_SIZE};
pub use dm::{DM, DmFlags};

// Export the DmFlags individually. In theory, they can be accessed by
// DmFlags::DM_READONLY, but in practice this requires explicitly using
// an obscure trait generated by the bitflags! macro.
pub use dm::{DM_READONLY, DM_SUSPEND, DM_PERSISTENT_DEV, DM_STATUS_TABLE, DM_ACTIVE_PRESENT,
             DM_INACTIVE_PRESENT, DM_BUFFER_FULL, DM_SKIP_BDGET, DM_SKIP_LOCKFS, DM_NOFLUSH,
             DM_QUERY_INACTIVE_TABLE, DM_UEVENT_GENERATED, DM_UUID, DM_SECURE_DATA, DM_DATA_OUT,
             DM_DEFERRED_REMOVE, DM_INTERNAL_SUSPEND};

pub use device::Device;
pub use lineardev::LinearDev;
pub use result::{DmResult, DmError, ErrorEnum};
pub use segment::Segment;
pub use shared::{DmDevice, device_exists};
pub use thinpooldev::{ThinPoolBlockUsage, ThinPoolDev, ThinPoolStatus, ThinPoolWorkingStatus};
pub use thindev::{ThinDev, ThinStatus};
pub use thindevid::ThinDevId;
pub use types::{Bytes, DataBlocks, DevId, DmName, DmNameBuf, DmUuid, DmUuidBuf, MetaBlocks,
                Sectors, TargetLine, TargetType, TargetTypeBuf};