MKNOD(2)
π MKNOD(2) π
okay bestie, sit down, hydrate, because today we're talking about the System Calls Manual page for mknod and mknodat β the little syscalls that let you make a special file node. this is real one-on-one unix lore and i am obsessed π
β¨ NAME β¨
mknod, mknodat β make a special file node
π LIBRARY π
Standard C Library (libc, -lc)
π§ SYNOPSIS π§
#include <sys/stat.h>
int
mknod(const char *path, mode_t mode, dev_t dev);
int
mknodat(int fd, const char *path, mode_t mode, dev_t dev);
πΈ DESCRIPTION πΈ
so here's the tea, bestie π
β the file system node at path gets created with the file type and the access permissions you specify in mode. and then, plot twist, those access permissions get modified by the process's umask value. yes, the umask is always in the group chat, always chiming in π
if mode says this is a block or character special file, then dev is a configuration dependent specification that denotes a particular device on the system. if it's not, then dev is just... ignored. ghosted. literally no thoughts, head empty π
β οΈ the mknod() system call requires super-user privileges. like, actual root energy. you can't just walk in there with your little user account and start making device nodes, that's not the vibe.
now for mknodat() β she's mknod()'s cooler cousin, and she's equivalent to mknod() except in the case where path specifies a relative path. in that case, the newly created device node is created relative to the directory associated with the file descriptor fd instead of the current working directory. iconic behavior honestly π
and if you pass mknodat() the special value AT_FDCWD in the fd parameter, then the current working directory is used, and the behavior is identical to a call to mknod(). so basically it's the same girl with a different outfit. slay π
π«Ά RETURN VALUES π«Ά
the mknod() function returns the value 0 if successful. otherwise, the value -1 is returned and the global variable errno is set to indicate the error. that's it, that's the whole vibe check β¨
π ERRORS π
the mknod() system call will fail and the file will be not created if any of these happen:
[ENOTDIR]β a component of thepathprefix is not a directory.[ENAMETOOLONG]β a component of a pathname exceeded255characters, or an entire path name exceeded1023characters. she long, she too long π[ENOENT]β a component of thepathprefix does not exist. where? not here. doesn't exist.[EACCES]β search permission is denied for a component of thepathprefix. no searching for you π«[ELOOP]β too many symbolic links were encountered in translating the pathname. it's giving link loop labyrinth π[EPERM]β the process's effective user ID is not super-user. told you, bestie, root only π[EIO]β an I/O error occurred while making the directory entry or allocating the inode.[EINTEGRITY]β corrupted data was detected while reading from the file system. yikes π[ENOSPC]β the directory in which the entry for the new node is being placed cannot be extended because there is no space left on the file system containing the directory.[ENOSPC]β there are no free inodes on the file system on which the node is being created.[EDQUOT]β the directory in which the entry for the new node is being placed cannot be extended because the user's quota of disk blocks on the file system containing the directory has been exhausted.[EDQUOT]β the user's quota of inodes on the file system on which the node is being created has been exhausted.[EROFS]β the named file resides on a read-only file system. read only means read only, babes π[EEXIST]β the named file exists. it's already here, bestie, we been knew π[EFAULT]β thepathargument points outside the process's allocated address space.[EINVAL]β creating anything else than a block or character special file (or a whiteout) is not supported. sorry, no custom file types, that's not on the menu π
and in addition to the errors returned by mknod(), mknodat() may fail if:
[EBADF]β thepathargument does not specify an absolute path and thefdargument is neitherAT_FDCWDnor a valid file descriptor open for searching.[ENOTDIR]β thepathargument is not an absolute path andfdis neitherAT_FDCWDnor a file descriptor associated with a directory.
π¦ SEE ALSO π¦
chmod(2), mkfifo(2), stat(2), umask(2)
β STANDARDS β
the mknodat() system call follows The Open Group Extended API Set 2 specification. she's certified, she's spec-compliant, she's got receipts πβ¨
π HISTORY π
the mknod() function appeared in Version 4 AT&T UNIX. the mknodat() system call appeared in FreeBSD 8.0. two icons from two different eras, and we love both π
and that's the whole page, bestie!! this manual page came from Debian and it's dated March 30, 2020 β so it's a lil vintage but it's still serving exactly what it needs to serve π«Ά go forth and make your special file nodes (if you're root, which you're probably not, no offense) πβ¨πΈ
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 1980, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms