__register_blkdev(9)
πΈ __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 β ifmajor = 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\0is non-negotiable, no cap) π·οΈprobeβ this is the pre-devtmpfs/ pre-udevcallback, used to create disks when their pre-created device node gets accessed. Two things to know, fr fr: when a probe call usesadd_diskand 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 = 0parameter 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 π«Ά
bdev_count_inflight(9)add_disk_fwnode(9)device_add_disk(9)blk_mark_disk_dead(9)del_gendisk(9)invalidate_disk(9)disk_release(9)put_disk(9)set_disk_ro(9)
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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms