Expand description
Safe, idiomatic Rust bindings for the Linux libnvme C library.
libnvme is the userspace library that backs nvme-cli. This crate exposes
a memory-safe wrapper over its handle tree:
Root → Host → Subsystem → Controller → NamespaceEvery handle borrows from the Root via the 'r lifetime, so dropping
the Root cascades-frees the entire tree.
§Example
use libnvme::Root;
let root = Root::scan()?;
for host in root.hosts() {
for subsys in host.subsystems() {
for ctrl in subsys.controllers() {
println!("{} {}", ctrl.name()?, ctrl.model()?);
let id = ctrl.identify()?;
println!(" NVMe spec: {}", id.nvme_version());
for ns in ctrl.namespaces() {
println!(" {} ({} bytes)", ns.name()?, ns.size_bytes());
}
}
}
}Structs§
- Compare
- Builder returned by
Namespace::compare. - Connect
- Builder for an NVMe-oF Connect operation.
- Controller
- An NVMe controller.
- Controllers
- Iterator over
Controllerentries, returned bycrate::Subsystem::controllers. - Copy
- Builder returned by
Namespace::copy. - Copy
Range - One source range for the NVMe Copy command (format 0).
- Discovery
Log - Discovery-log header + entries returned by a discovery controller’s log page (LID 0x70).
- Discovery
LogEntry - One entry from the discovery log page.
- Dsm
- Builder returned by
Namespace::dsm. - DsmAttr
- DSM attribute bits (CDW11). Combine with
|. - DsmRange
- One DSM range entry. NVMe spec: each entry covers up to 4 GiB of LBAs.
- Error
LogEntry - One entry from the Error Information log page (LID 01h).
- Features
- Get/Set Features accessor for a controller.
- Firmware
Slot Log - Firmware Slot Information log page (LID 03h).
- Format
- Builder for the Format NVM admin command.
- GetLba
Status Args - Parameters for Get LBA Status (NVMe 1.4+).
- Host
- A host entry in the libnvme tree.
- Hosts
- Iterator over
Hostentries, returned byRoot::hosts. - Identify
Controller - Decoded Identify Controller (CNS 01h) data structure.
- Identify
Namespace - Decoded Identify Namespace (CNS 00h) data structure.
- LbaFormat
- One LBA format entry from Identify Namespace.
- Lockdown
Args - Parameters for the Lockdown admin command (NVMe 2.0+).
- Namespace
- An NVMe namespace.
- Namespaces
- Iterator over
Namespaceentries reachable through acrate::Controller. - Nvme
Version - Decoded NVMe specification version, as reported by the controller’s
VERregister and thevsfield of Identify Controller. - Passthru
Args - Parameters for
Controller::admin_passthru/Controller::io_passthru. - Path
- A single multipath route to a namespace.
- Paths
- Iterator over
Pathentries reachable through a [Controller] or [Namespace]. - Read
- Builder returned by
Namespace::read. - Root
- The owning handle to the libnvme tree.
- Sanitize
- Builder for the Sanitize NVM admin command.
- Smart
Log - Decoded SMART / Health Information log page (LID 02h).
- Subsystem
- An NVMe subsystem.
- Subsystems
- Iterator over
Subsystementries, returned bycrate::Host::subsystems. - Verify
- Builder returned by
Namespace::verify. - Write
- Builder returned by
Namespace::write. - Write
Uncorrectable - Builder returned by
Namespace::write_uncorrectable. - Write
Zeroes - Builder returned by
Namespace::write_zeroes.
Enums§
- Error
- Errors returned by this crate.
- Feature
Select - Which “view” of a feature value the Get Features command should return.
- Firmware
Action - What the firmware-commit admin command should do with the slot it targets.
- Metadata
Settings - How metadata is transferred relative to LBA data.
- Protection
Info - End-to-end Data Protection type to apply when formatting.
- Protection
Location - Where the PI guard bytes sit within each LBA.
- Sanitize
Action - Sanitize action — what the Sanitize admin command should do to the drive’s user data area.
- Secure
Erase - How user data should be erased during a Format NVM operation.
- Self
Test Action - Self-test action for the Device Self-Test admin command.
- Transport
- NVMe-oF transport selector. The
Othervariant is an escape hatch for transports added to libnvme after this crate was released.
Functions§
- generate_
hostid - Generate a fresh HostID (random UUID, formatted as a hex string).
- generate_
hostnqn - Generate a fresh HostNQN (NVMe spec format, embeds a freshly-generated UUID).
Equivalent to libnvme’s
nvmf_hostnqn_generate. Returned string is owned. - hostid_
from_ file - Read the local HostID from
/etc/nvme/hostidif it exists. - hostnqn_
from_ file - Read the local HostNQN from
/etc/nvme/hostnqnif it exists.
Type Aliases§
- AutoPst
- Host
Behavior - Host
MemBuf Attrs - LbaRange
Type - PlmConfig
- Result
- Result type alias for fallible operations in this crate.
- Timestamp