nvme_admin_passthru(2)
π nvme_admin_passthru β bestie's guide to yeeting an admin command at your NVMe π
okay so this is a page from the libnvme API manual β section 2, the syscall-ish zone β and it's all about nvme_admin_passthru. yes it's a mouthful. no we're not renaming it. she's iconic, she's lowercase, and she's about to hand-roll an NVMe command for you. sit down, grab a strawberry π, let's go.
β¨ NAME β¨
nvme_admin_passthru β submit an NVMe passthrough command. that's it, that's the whole name section, no notes. π
π¦ SYNOPSIS π¦
int nvme_admin_passthru (int fd , __u8 opcode , __u8 flags , __u16 rsvd
, __u32 nsid , __u32 cdw2 , __u32 cdw3 , __u32 cdw10 , __u32 cdw11 ,
__u32 cdw12 , __u32 cdw13 , __u32 cdw14 , __u32 cdw15 , __u32 data_len ,
void *data , __u32 metadata_len , void *metadata , __u32 timeout_ms ,
__u32 *result );
like, that's a LOT of parameters, bestie. it's giving "the function that knows everybody". but honestly every single one of them is doing a job and we're gonna be so normal about it. π
πΈ ARGUMENTS πΈ
fdβ file descriptor of the NVMe device. your ticket in. ποΈopcodeβ the nvme io command you're sending. the "what am i even doing here" field.flagsβ NVMe command flags. and here's the tea: they're not used. reserved, ignored, sitting in the corner being decorative. πrsvdβ reserved for future use. it's a maybe-baby. don't touch, don't expect anything.nsidβ namespace identifier. which namespace are we talking to, bestie?cdw2β command dword 2.cdw3β command dword 3.cdw10β command dword 10.cdw11β command dword 11.cdw12β command dword 12.cdw13β command dword 13.cdw14β command dword 14.cdw15β command dword 15.
(and yes, the list literally jumps from cdw3 to cdw10 β that is not a typo, that is just how the NVMe spec does dwords, we do not question it, we respect it. π«Ά)
data_lenβ length of the data transferred in this command, in bytes. πdataβ pointer to the user address of the data buffer.metadata_lenβ length of metadata transferred in this command.metadataβ pointer to the user address of the metadata buffer.timeout_msβ how long the kernel waits for the command to complete. patience: measured. β³resultβ optional field to return the result from the CQE dword 0. optional!! so it can be a little β¨nothingβ¨ and that's valid.
π DESCRIPTION π
so basically this is the parameterized form of nvme_submit_admin_passthru. same energy, but you're handing over every single piece yourself instead of pointing at a struct.
what she does under the hood: sets up and submits a struct nvme_passthru_cmd. one struct, fully dressed, ready for the kernel runway. π
and if you're wondering "okay but what are the valid opcode values??" β the known values for opcode are defined in enum nvme_admin_opcode. go look, it's all there. iykyk. π
π₯ RETURN π₯
two possible endings, choose your fighter:
- the nvme command status if a response was received β check
enum nvme_status_fieldfor what the number is actually saying. it's giving fortune cookie but in hex. -1witherrnoset otherwise. classic. the universal "something went sideways, checkerrnobestie" π
real talk: if you get back a status, read the status. don't just stare at it. enum nvme_status_field is literally right there waiting for you. π
that's the whole page, no crumbs left. written with love, submitted with struct nvme_passthru_cmd, and signed off from the libnvme API manual, section nvme_admin_passthru(2), dated July 2026. periodt. πβ¨π
π¦ where this page comes from
- ubuntu stonking: libnvme-dev 1.16.2-1build1 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms