Skip to main content

libnvme/
lib.rs

1//! Safe, idiomatic Rust bindings for the Linux `libnvme` C library.
2//!
3//! `libnvme` is the userspace library that backs `nvme-cli`. This crate exposes
4//! a memory-safe wrapper over its handle tree:
5//!
6//! ```text
7//! Root → Host → Subsystem → Controller → Namespace
8//! ```
9//!
10//! Every handle borrows from the [`Root`] via the `'r` lifetime, so dropping
11//! the [`Root`] cascades-frees the entire tree.
12//!
13//! # Example
14//!
15//! ```no_run
16//! use libnvme::Root;
17//!
18//! let root = Root::scan()?;
19//! for host in root.hosts() {
20//!     for subsys in host.subsystems() {
21//!         for ctrl in subsys.controllers() {
22//!             println!("{} {}", ctrl.name()?, ctrl.model()?);
23//!             let id = ctrl.identify()?;
24//!             println!("  NVMe spec: {}", id.nvme_version());
25//!             for ns in ctrl.namespaces() {
26//!                 println!("  {} ({} bytes)", ns.name()?, ns.size_bytes());
27//!             }
28//!         }
29//!     }
30//! }
31//! # Ok::<(), Box<dyn std::error::Error>>(())
32//! ```
33
34mod admin;
35mod commands;
36mod controller;
37mod error;
38mod fabrics;
39mod features;
40mod host;
41mod identify;
42mod io;
43mod log;
44mod namespace;
45mod path;
46mod root;
47mod subsystem;
48mod util;
49
50pub use admin::{
51    FeatureSelect, FirmwareAction, MetadataSettings, ProtectionInfo, ProtectionLocation,
52    SanitizeAction, SecureErase, SelfTestAction,
53};
54pub use commands::{GetLbaStatusArgs, LockdownArgs, PassthruArgs, Sanitize};
55pub use controller::{Controller, Controllers};
56pub use error::{Error, Result};
57pub use fabrics::{Connect, DiscoveryLog, DiscoveryLogEntry, Transport};
58pub use features::{
59    AutoPst, Features, HostBehavior, HostMemBufAttrs, LbaRangeType, PlmConfig, Timestamp,
60};
61pub use host::{Host, Hosts};
62pub use identify::{IdentifyController, IdentifyNamespace, LbaFormat, NvmeVersion};
63pub use io::{
64    Compare, Copy, CopyRange, Dsm, DsmAttr, DsmRange, Read, Verify, Write, WriteUncorrectable,
65    WriteZeroes,
66};
67pub use log::{ErrorLogEntry, FirmwareSlotLog, SmartLog};
68pub use namespace::{Format, Namespace, Namespaces};
69pub use path::{Path, Paths};
70#[cfg(has_hostid_generate)]
71pub use root::generate_hostid;
72#[cfg(has_hostid_from_file)]
73pub use root::hostid_from_file;
74pub use root::{generate_hostnqn, hostnqn_from_file, Root};
75pub use subsystem::{Subsystem, Subsystems};