STRUCT NVRAM_OPS(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’Ύ struct nvram_ops(9) β€” the kernel API manual, but make it make sense

okay so bestie, this is a page from the Kernel API Manual (that's the manual name, iykyk πŸ’…) and it's all about one little struct. buckle up.


✨ NAME ✨

struct nvram_ops β€” NVRAM functionality made available to drivers 🫢

like, it's the official handshake between NVRAM hardware and the drivers that wanna talk to it. iconic behavior honestly.


🌸 SYNOPSIS 🌸

struct nvram_ops {
    ssize_t (*get_size)(void);
    unsigned char   (*read_byte)(int);
    void (*write_byte)(unsigned char, int);
    ssize_t (*read)(char *, size_t, loff_t *);
    ssize_t (*write)(char *, size_t, loff_t *);
  #if defined(CONFIG_X86) || defined(CONFIG_M68K);
    long (*initialize)(void);
    long (*set_checksum)(void);
  #endif;
 };

no cap, that #if block is doing a lot of heavy lifting β€” those last two members show up only on CONFIG_X86 or CONFIG_M68K. everybody else? they're not invited.


πŸŽ€ Members πŸŽ€

  • get_size β€” returns the fixed number of bytes in the NVRAM. that's it. that's the vibe check.
  • read_byte β€” loads a single byte from NVRAM. one (1) byte. tiny but mighty πŸ¦‹
  • write_byte β€” stores a single byte to NVRAM. also one byte. also iconic.
  • read β€” validates the checksum (if there even is one) and then loads a range of bytes from NVRAM. it's giving responsible main character energy.
  • write β€” stores a range of bytes to NVRAM and then updates the checksum (again, only if there is one). periodt.

πŸ’œ Description πŸ’œ

so here's the tea β˜• β€” architectures that provide an nvram_ops struct do not have to implement all of these methods. it's not a contract, it's a menu. lowkey generous of them.

if the NVRAM hardware can only be accessed one byte at a time, then it may be sufficient to provide just .read_byte and .write_byte. that's your whole setup. cute, minimal, done.

but if your NVRAM has a checksum (and yes, it's actually going to be checked), then the .read and .write methods are the ones to use β€” they implement that checksum thing efficiently. work smarter not harder bestie πŸ’…

portable drivers may use the wrapper functions defined here. the nvram_read and nvram_write functions call the .read and .write methods when those are available, and fall back on the .read_byte and .write_byte methods otherwise. so like… it figures it out for you. bestie behavior fr fr πŸ”₯


πŸ¦‹ SEE ALSO πŸ¦‹

  • Kernel file ./include/linux/nvram.h β€” go look, it's right there 🌈

ok that's the whole page 🫢 no members were skipped, no flags were harmed, and every single detail is still in there. you're welcome.

β€” signed off with love from the ./include/linux girlies, dated October 2026, bringing you struct nvram_ops(9) βœ¨πŸ’–πŸŽ€

πŸ“¦ where this page comes from