__register_blkdev(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

🌸 __register_blkdev(9) 🌸

hiii bestie, welcome to the kernel API manual πŸ’– this one's from the Linux kernel docs (section 9, the kernel API pages, iykyk), and it's all about registering a brand new block device. Let's get into it ✨


✨ NAME ✨

__register_blkdev β€” register a new block device πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

int __register_blkdev (unsigned int major , const char *name , void (*probe)(dev_t devt) );

That's the whole vibe check right there β€” three args, one int coming back at you πŸ’…


πŸ’œ ARGUMENTS πŸ’œ

  • major β€” the major device number you're requesting, and it's gotta be in the range [1..BLKDEV_MAJOR_MAX-1]. But wait β€” plot twist β€” if major = 0, the kernel is basically like "bestie pick one for me" and tries to allocate any unused major number 🎲
  • name β€” the name of your new block device, as a zero terminated string (yes, that \0 is non-negotiable, no cap) 🏷️
  • probe β€” this is the pre-devtmpfs / pre-udev callback, used to create disks when their pre-created device node gets accessed. Two things to know, fr fr: when a probe call uses add_disk and it fails, the driver must cleanup resources (no leaving mess around πŸ™ˆ), and also this interface may soon be removed. So like, enjoy it while it lasts πŸ’€

πŸ‘‘ DESCRIPTION πŸ‘‘

Okay so first thing, big rule: the name must be unique within the system. No duplicates, periodt βœ‹

The return value depends on what you passed in for major:

  • if a major device number was requested in range [1..BLKDEV_MAJOR_MAX-1] then the function returns zero on success, or a negative error code 😭
  • if any unused major number was requested with the major = 0 parameter then the return value is the allocated major number in range [1..BLKDEV_MAJOR_MAX-1] or a negative error code otherwise πŸŽ‰

Wanna see the list of allocated major numbers? Peep Documentation/admin-guide/devices.txt, iconic reference material ✨

🚨 real talk though: use register_blkdev instead for any new code. This one's giving legacy energy, so don't come for me if you write new stuff with it πŸ™ˆ

🌈 SEE ALSO 🌈

Kernel file ./block/genhd.c plus these besties 🫢


okay that's the whole page, you ate that πŸ’… this one lives under ./block, dated October 2026, and it's from the man page collection where __register_blkdev (9) stays the main character. go forth and register responsibly, mwah πŸ“πŸ§šπŸ’œ

πŸ“¦ where this page comes from