__register_chrdev(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ __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, or 0 if 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: the name of 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:

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