Unix::Mknod(3pm)

πŸ’– Unix::Mknod β€” the mknod, major, minor & makedev era πŸ’–

okay bestie, sit down, hydrate, because this is Unix::Mknod(3pm) β€” a lil User Contributed Perl Documentation page β€” and she is lowkey iconic. no cap, she's giving "tiny module, huge main character energy". ✨


🌸 NAME 🌸

Unix::Mknod β€” a Perl extension for mknod, major, minor, and makedev. that's the whole vibe. πŸŽ€


✨ SYNOPSIS ✨

the way you just do this:

use Unix::Mknod qw(:all);
use File::stat;
use Fcntl qw(:mode);

$st=stat('/dev/null');
$major=major($st->rdev);
$minor=minor($st->rdev);

mknod('/tmp/special', S_IFCHR|0600, makedev($major,$minor+1));

obsessed. copy it, run it, slay. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so basically this module is your backstage pass to the device routines major() / minor() / makedev() β€” those lil guys that may or may not be macros in .h files. nobody knows! it's a mystery! πŸ•΅οΈβ€β™€οΈ

it also hands you the keys to the mknod(2) system call. periodt. πŸ”₯


πŸ‘‘ FUNCTIONS πŸ‘‘

πŸ’œ mknod($filename, $mode, $rdev)

makes a block or character device special file named $filename. 🧚

⚠️ bestie, she must be run as a privileged user β€” usually root. no skips, no shortcuts.

returns 0 on success and -1 on failure, just like POSIX::mkfifo does. 🌈

πŸ’œ $major = major($rdev)

gives you the major number for the device special file, as defined by the st_rdev field from the stat(3) call. iykyk. ⭐

πŸ’œ $minor = minor($rdev)

gives you the minor number for the device special file, also as defined by that st_rdev field from the stat(3) call. twin energy, same source. πŸ’–

πŸ’œ $rdev = makedev($major, $minor)

gives you back the st_rdev number for the device special file, built from the $major and $minor numbers. the glow-up from two numbers into one. ✨


πŸŽ€ NOTES πŸŽ€

there are 2 other perl modules that implement the mknod(2) system call, and honestly? they have problems working on some platforms. not naming names but… ok fine, naming names:

  • Sys::Mknod doesn't work on AIX because it uses the syscall(2) generic system call, and AIX simply does not have that. πŸ’€
  • Mknod implements S_IFIFO, which on most platforms is not implemented in mknod(1), but rather in mkfifo(1) (which is implemented in the POSIX perl module). πŸ’…

also, the perl module File::Stat::Bits implements major() and minor() too β€” plus a version of makedev() called dev_join. 🫢 they do it as a program to get the bit masks at compile time, but here's the tea: if major() and minor() are implemented as sub routines, then the argument could be something as simple as an index to a lookup table (and thereby having no decernable relation to its result). spooky. πŸ™ˆ


😭 BUGS 😭

running make test as non root will not truly test the functions, because in most UNIX like OSes, mknod(2) needs to be invoked by a privelaged user β€” usually root. so you're testing the vibe, not the function. crying in the club. 😭


🌈 SEE ALSO 🌈

  • $ERRNO or $! for the specific error message. πŸ“
  • File::Stat::Bits, Mknod, POSIX, Sys::Mknod
  • major(9), minor(9), mkfifo(1), mknod(8)

⭐ AUTHOR ⭐

Jim Pirzyk, <pirzyk@freebsd.org> β€” give him his flowers. 🌸


Copyright (c) 2005-2023 University of Illinois Board of Trustees All rights reserved. πŸ‘‘

Developed by:

Campus Information Technologies and Educational Services,
University of Illinois at Urbana-Champaign

permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ``Software''), to deal with the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers. πŸ’…
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation and/or other materials provided with the distribution. πŸ’…
  • Neither the names of Campus Information Technologies and Educational Services, University of Illinois at Urbana-Champaign, nor the names of its contributors may be used to endorse or promote products derived from this Software without specific prior written permission. πŸ’…

THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.


and that's the whole page, bestie!! 🫢 this lil gem is running on perl v5.42.3, dated 2026-08-19, and lives under the name Unix::Mknod(3pm). go make some device nodes, be safe with your privileges, and remember: root access is not a personality trait. πŸ’œβœ¨πŸŽ€

πŸ“¦ where this page comes from