makedev(3)

โœจ makedev(3) โœจ

okay bestie, welcome to makedev(3), straight outta the Library Functions Manual ๐Ÿ’… and the Standard C library (libc, -lc) ๐ŸŒธ

This one's about device numbers. Three lil functions, one big vibe. Let's go ๐Ÿซถ


๐Ÿ“› NAME ๐Ÿ“›

makedev, major, minor โ€” manage a device number ๐Ÿ’–


๐Ÿ“š LIBRARY ๐Ÿ“š

Standard C library (libc, -lc) โญ


๐ŸŒˆ SYNOPSIS ๐ŸŒˆ

#include <sys/sysmacros.h>

dev_t makedev(unsigned int maj, unsigned int min);

unsigned int major(dev_t dev);
unsigned int minor(dev_t dev);

๐Ÿงš DESCRIPTION ๐Ÿงš

So. A device ID is literally two parts glued together, no cap:

  • a major ID โ€” this is the class of the device, like which family it belongs to ๐Ÿ‘‘
  • a minor ID โ€” this is the specific instance of a device inside that class, the individual lil guy ๐ŸŽ€

And a device ID as a whole? That's represented using the type dev_t. Periodt.

Give makedev() a major and a minor device ID and it combines them into one device ID, which it hands back to you as the function result. Then you can pass that device ID to mknod(2), for example. Iconic behavior, honestly โœจ

Then major() and minor() do the exact opposite task: hand them a device ID and they give you back the major and minor components respectively. These macros are lowkey useful for stuff like decomposing the device IDs in that structure you got back from stat(2) ๐Ÿ”ฅ


๐Ÿ’… ATTRIBUTES ๐Ÿ’…

Need the tea on these terms? Go look at attributes(7), bestie.

  • makedev(), major(), minor() โ€” Thread safety: MT-Safe ๐ŸŒˆ
so like... all three of them are MT-Safe. we love a thread-safe moment fr fr ๐Ÿ’–

๐Ÿฆ‹ VERSIONS ๐Ÿฆ‹

The BSDs expose the definitions for these macros via <sys/types.h>. noted! ๐Ÿ“


โญ STANDARDS โญ

None. ๐Ÿ˜ญ yeah. none. it is what it is.


๐Ÿ‘‘ HISTORY ๐Ÿ‘‘

BSD, HP-UX, Solaris, AIX, Irix. an absolute legend lineup, we have to stan ๐Ÿซถ

These interfaces are defined as macros. And since glibc 2.3.3, they've been aliases for three GNU-specific functions:

  • gnu_dev_makedev()
  • gnu_dev_major()
  • gnu_dev_minor()

Those latter names are exported and everything, but the traditional names are more portable โ€” so use those, bestie, trust ๐Ÿงš

Depending on the version, glibc also exposes definitions for these macros from <sys/types.h> if suitable feature test macros are defined. BUT โ€” and this is the important part โ€”

โš ๏ธ that behavior was deprecated in glibc 2.25, and since glibc 2.28, <sys/types.h> no longer provides these definitions. so don't count on it, fr ๐Ÿ’€

๐Ÿ” SEE ALSO ๐Ÿ”


and that's the whole page, babes ๐Ÿ’œ this came straight from Linux man-pages 6.20, dated 2025-05-17 โ€” that's the source and the date, and now you know it, so go forth and make some devices ๐ŸŽ€โœจ๐Ÿ’–

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: Linux-man-pages-copyleft
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms