__register_chrdev(9)
β¨ __register_chrdev(9) β¨
okay bestie, welcome to the Kernel API Manual β this is the Kernel API Manual page for __register_chrdev(9), and we're gonna get you comfy with it fr fr π
πΈ NAME πΈ
__register_chrdev β create and register a cdev occupying a range of minors β¨
like... it makes a char device and claims a whole lil stretch of minor numbers for it. iconic behavior tbh π
π SYNOPSIS π
int __register_chrdev (unsigned int major , unsigned int baseminor ,
unsigned int count , const char *name , const struct file_operations
*fops );
look at her. five arguments. main character energy π
π ARGUMENTS π
majorβ the major device number, or0if you want dynamic allocation. basically "pick for me bestie" π«Άbaseminorβ the first one of the requested range of minor numbers. the starting point of your lil minor era πcountβ how many minor numbers you're asking for. the size of your range, no cap πnameβ name of this range of devices. just a label, see DESCRIPTION, don't get too attached πfopsβ the file operations associated with this devices. yes, that's the original wording, we're keeping it exactly πβ¨
π¦ DESCRIPTION π¦
okay so here's the vibe check π
If major == 0 this functions will dynamically allocate a major and return its number. so you're like "idk you pick" and it literally picks for you, slay π
If major > 0 this function will attempt to reserve a device with the given major number and will return zero on success. zero is the good one here, bestie β that's the win π
Returns a -ve errno on failure. negative errno. as in, things did not go well π read it and cope.
β οΈ important lil note: thenameof this device has nothing to do with the name of the device in/dev. nothing. zero. they're not connected, they're not dating, they don't even follow each other π It only helps to keep track of the different owners of devices. If your module name has only one type of devices it's ok to use e.g. the name of the module here. so like, lowkey just use your module name and move on π
π₯ SEE ALSO π₯
go look at the Kernel file ./fs/char_dev.c for the real lore, and also these icons:
register_chrdev_region(9)alloc_chrdev_region(9)unregister_chrdev_region(9)__unregister_chrdev(9)cdev_add(9)cdev_set_parent(9)cdev_device_add(9)cdev_device_del(9)cdev_del(9)cdev_alloc(9)cdev_init(9)
a whole friend group honestly π«ΆπΈ
and that's the page!! this one lives at ./fs, dated October 2026, and it's the __register_chrdev(9) entry β go register something cute, ily, bye πππ§
π¦ 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