MKFIFO(2)

πŸ‘‘ MKFIFO πŸ‘‘

hi bestie πŸ’– so this lil cutie lives in section 2 of the System Calls Manual, and it's giving "I make fifo files and I do it flawlessly". no cap. let's get into it.


🌸 NAME 🌸

mkfifo, mkfifoat β€” make a fifo file πŸŽ€


πŸ“š LIBRARY πŸ“š

Standard C Library (libc, -lc) ✨


🌈 SYNOPSIS 🌈

#include <sys/types.h>
#include <sys/stat.h>

int
mkfifo(const char *path, mode_t mode);

int
mkfifoat(int fd, const char *path, mode_t mode);

πŸ’… DESCRIPTION πŸ’…

okay so mkfifo() is the system call that creates a brand new fifo file, and its name is path 🫢. the access permissions? those come from mode, and they get restricted by the umask(2) of whatever process is doing the calling. yes, your umask is always in the group chat, always has opinions.

the fifo's owner ID is set to the process's effective user ID πŸ‘‘. and the fifo's group ID? that gets set to the group of the parent directory it's created in. it's giving "inherited the family group chat" energy fr fr.

now mkfifoat() is literally the same as mkfifo() except when path is a relative path 🌟. in that specific case, the newly created FIFO gets created relative to the directory associated with the file descriptor fd, instead of the current working directory. main character behaviour honestly. and if you pass mkfifoat() the special value AT_FDCWD in the fd parameter? then the current working directory is used and the behaviour is identical to calling mkfifo(). twin behaviour, no notes πŸ’€βœ¨


πŸŽ€ RETURN VALUES πŸŽ€

mkfifo() returns the value 0 if it slayed (successful, obviously). otherwise it returns the value -1 and the global variable errno gets set to indicate the error 😭. so yeah, check your errno bestie.


πŸ’– ERRORS πŸ’–

⚠️ heads up: the mkfifo() system call will fail and no fifo will be created if any of these happen:
  • [ENOTSUP] β€” the kernel has not been configured to support fifo's πŸ’€
  • [ENOTDIR] β€” a component of the path prefix is not a directory πŸ™ˆ
  • [ENAMETOOLONG] β€” a component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters 😭
  • [ENOENT] β€” a component of the path prefix does not exist πŸ‘»
  • [EACCES] β€” a component of the path prefix denies search permission, or write permission is denied on the parent directory of the fifo to be created 🚫
  • [ELOOP] β€” too many symbolic links were encountered in translating the pathname πŸ”
  • [EROFS] β€” the named file would reside on a read-only file system 🧊
  • [EEXIST] β€” the named file exists. it's already there bestie, you can't sit with us πŸ’…
  • [EPERM] β€” the parent directory of the named file has its immutable flag set, see the chflags(2) manual page for more information πŸ”’
  • [ENOSPC] β€” the directory in which the entry for the new fifo 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 fifo is being created πŸ“‰
  • [EDQUOT] β€” the directory in which the entry for the new fifo 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 fifo is being created has been exhausted πŸ’Έ
  • [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 🧨
  • [EFAULT] β€” the path argument points outside the process's allocated address space 🚨

and on top of all the errors that mkfifo() returns, mkfifoat() might also fail if:

  • [EBADF] β€” the path argument does not specify an absolute path and the fd argument is neither AT_FDCWD nor a valid file descriptor open for searching 😡
  • [ENOTDIR] β€” the path argument is not an absolute path and fd is neither AT_FDCWD nor a file descriptor associated with a directory 😡

πŸ¦‹ SEE ALSO πŸ¦‹

chflags(2), chmod(2), mknod(2), stat(2), umask(2) β€” go read these too, they're all iconic in their own way 🌟


⭐ STANDARDS ⭐

the mkfifo() system call is expected to conform to ISO/IEC 9945-1:1990 (β€œPOSIX.1”) πŸ“œ. and the mkfifoat() system call follows The Open Group Extended API Set 2 specification 🫢. standards queen behaviour, we love to see it.


🌈 HISTORY 🌈

the mkfifoat() system call appeared in FreeBSD 8.0 πŸŽ‰. a legend was born.


and that's the whole page bestie!! this one shipped from Debian and it's dated March 30, 2020 πŸ’– now go make some fifos, you absolute icon πŸ‘‘βœ¨

πŸ“¦ where this page comes from