{"id":4792,"date":"2022-12-20T18:36:52","date_gmt":"2022-12-20T21:36:52","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/mknod-man3p\/"},"modified":"2022-12-20T18:36:52","modified_gmt":"2022-12-20T21:36:52","slug":"mknod-man3p","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/mknod-man3p\/","title":{"rendered":"MKNOD (man3p)"},"content":{"rendered":"<h1 align=\"center\">MKNOD<\/h1>\n<p> <a href=\"#PROLOG\">PROLOG<\/a><br \/> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#RETURN VALUE\">RETURN VALUE<\/a><br \/> <a href=\"#ERRORS\">ERRORS<\/a><br \/> <a href=\"#EXAMPLES\">EXAMPLES<\/a><br \/> <a href=\"#APPLICATION USAGE\">APPLICATION USAGE<\/a><br \/> <a href=\"#RATIONALE\">RATIONALE<\/a><br \/> <a href=\"#FUTURE DIRECTIONS\">FUTURE DIRECTIONS<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#COPYRIGHT\">COPYRIGHT<\/a> <\/p>\n<hr>\n<h2>PROLOG <a name=\"PROLOG\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This manual page is part of the POSIX Programmer\u2019s Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.<\/p>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">mknod, mknodat \u2014 make directory, special file, or regular file<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">#include <sys\/stat.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">int mknod(const char *<i>path<\/i>, mode_t <i>mode<\/i>, dev_t <i>dev<\/i>);<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">#include <fcntl.h><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">int mknodat(int <i>fd<\/i>, const char *<i>path<\/i>, mode_t <i>mode<\/i>, dev_t <i>dev<\/i>);<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>mknod<\/i>() function shall create a new file named by the pathname to which the argument <i>path<\/i> points.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The file type for <i>path<\/i> is OR\u2019ed into the <i>mode<\/i> argument, and the application shall select one of the following symbolic constants:<\/p>\n<p align=\"center\" style=\"margin-top: 1em\"><img decoding=\"async\" src=\"grohtml-818081.png\" alt=\"Image grohtml-818081.png\"><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The only portable use of <i>mknod<\/i>() is to create a FIFO-special file. If <i>mode<\/i> is not S_IFIFO or <i>dev<\/i> is not 0, the behavior of <i>mknod<\/i>() is unspecified.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The permissions for the new file are OR\u2019ed into the <i>mode<\/i> argument, and may be selected from any combination of the following symbolic constants:<\/p>\n<p align=\"center\" style=\"margin-top: 1em\"><img decoding=\"async\" src=\"grohtml-818082.png\" alt=\"Image grohtml-818082.png\"><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The user ID of the file shall be initialized to the effective user ID of the process. The group ID of the file shall be initialized to either the effective group ID of the process or the group ID of the parent directory. Implementations shall provide a way to initialize the file\u2019s group ID to the group ID of the parent directory. Implementations may, but need not, provide an implementation-defined way to initialize the file\u2019s group ID to the effective group ID of the calling process. The owner, group, and other permission bits of <i>mode<\/i> shall be modified by the file mode creation mask of the process. The <i>mknod<\/i>() function shall clear each bit whose corresponding bit in the file mode creation mask of the process is set.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If <i>path<\/i> names a symbolic link, <i>mknod<\/i>() shall fail and set <i>errno<\/i> to <b>[EEXIST]<\/b>.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Upon successful completion, <i>mknod<\/i>() shall mark for update the last data access, last data modification, and last file status change timestamps of the file. Also, the last data modification and last file status change timestamps of the directory that contains the new entry shall be marked for update.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Only a process with appropriate privileges may invoke <i>mknod<\/i>() for file types other than FIFO-special.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>mknodat<\/i>() function shall be equivalent to the <i>mknod<\/i>() function except in the case where <i>path<\/i> specifies a relative path. In this case the newly created directory, special file, or regular file is located relative to the directory associated with the file descriptor <i>fd<\/i> instead of the current working directory. If the access mode of the open file description associated with the file descriptor is not O_SEARCH, the function shall check whether directory searches are permitted using the current permissions of the directory underlying the file descriptor. If the access mode is O_SEARCH, the function shall not perform the check.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If <i>mknodat<\/i>() is passed the special value AT_FDCWD in the <i>fd<\/i> parameter, the current working directory shall be used and the behavior shall be identical to a call to <i>mknod<\/i>().<\/p>\n<h2>RETURN VALUE <a name=\"RETURN VALUE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Upon successful completion, these functions shall return 0. Otherwise, these functions shall return \u22121 and set <i>errno<\/i> to indicate the error. If \u22121 is returned, the new file shall not be created.<\/p>\n<h2>ERRORS <a name=\"ERRORS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">These functions shall fail if:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EACCES<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>A component of the path prefix denies search permission, or write permission is denied on the parent directory.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EEXIST<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>The named file exists.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EINVAL<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>An invalid argument exists.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EIO<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>An I\/O error occurred while accessing the file system.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>ELOOP<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>A loop exists in symbolic links encountered during resolution of the <i>path<\/i> argument.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ENAMETOOLONG<\/b><\/p>\n<p style=\"margin-left:22%;\">The length of a component of a pathname is longer than {NAME_MAX}.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>ENOENT<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>A component of the path prefix of <i>path<\/i> does not name an existing file or <i>path<\/i> is an empty string.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ENOENT<\/b> or <b>ENOTDIR<\/b><\/p>\n<p style=\"margin-left:22%;\">The <i>path<\/i> argument contains at least one non-<slash> character and ends with one or more trailing <slash> characters. If <i>path<\/i> without the trailing <slash> characters would name an existing file, an <b>[ENOENT]<\/b> error shall not occur.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>ENOSPC<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>The directory that would contain the new file cannot be extended or the file system is out of file allocation resources.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ENOTDIR<\/b><\/p>\n<p style=\"margin-left:22%;\">A component of the path prefix names an existing file that is neither a directory nor a symbolic link to a directory.<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"7%\">\n<p><b>EPERM<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"78%\">\n<p>The invoking process does not have appropriate privileges and the file type is not FIFO-special.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"7%\">\n<p><b>EROFS<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"78%\">\n<p>The directory in which the file is to be created is located on a read-only file system.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>mknodat<\/i>() function shall fail if:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p style=\"margin-top: 1em\"><b>EACCES<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p style=\"margin-top: 1em\">The access mode of the open file description associated with <i>fd<\/i> is not O_SEARCH and the permissions of the directory underlying <i>fd<\/i> do not permit directory searches.<\/p>\n<\/td>\n<\/tr>\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"9%\">\n<p><b>EBADF<\/b><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"78%\">\n<p>The <i>path<\/i> argument does not specify an absolute path and the <i>fd<\/i> argument is neither AT_FDCWD nor a valid file descriptor open for reading or searching.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ENOTDIR<\/b><\/p>\n<p style=\"margin-left:22%;\">The <i>path<\/i> argument is not an absolute path and <i>fd<\/i> is a file descriptor associated with a non-directory file.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">These functions may fail if:<\/p>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"11%\"><\/td>\n<td width=\"7%\">\n<p><b>ELOOP<\/b><\/p>\n<\/td>\n<td width=\"4%\"><\/td>\n<td width=\"78%\">\n<p>More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the <i>path<\/i> argument.<\/p>\n<\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:11%;\"><b>ENAMETOOLONG<\/b><\/p>\n<p style=\"margin-left:22%;\">The length of a pathname exceeds {PATH_MAX}, or pathname resolution of a symbolic link produced an intermediate result with a length that exceeds {PATH_MAX}.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>The following sections are informative.<\/i><\/p>\n<h2>EXAMPLES <a name=\"EXAMPLES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i><b>Creating a FIFO Special File<\/b><\/i> <br \/> The following example shows how to create a FIFO special file named <b>\/home\/cnd\/mod_done<\/b>, with read\/write permissions for owner, and with read permissions for group and others.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">#include <sys\/types.h> <br \/> #include <sys\/stat.h><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">dev_t dev; <br \/> int status; <br \/> &#8230; <br \/> status = mknod(&#8220;\/home\/cnd\/mod_done&#8221;, S_IFIFO | S_IWUSR | <br \/> S_IRUSR | S_IRGRP | S_IROTH, dev);<\/p>\n<h2>APPLICATION USAGE <a name=\"APPLICATION USAGE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The <i>mkfifo<\/i>() function is preferred over this function for making FIFO special files.<\/p>\n<h2>RATIONALE <a name=\"RATIONALE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">The POSIX.1-1990 standard required that the group ID of a newly created file be set to the group ID of its parent directory or to the effective group ID of the creating process. FIPS 151-2 required that implementations provide a way to have the group ID be set to the group ID of the containing directory, but did not prohibit implementations also supporting a way to set the group ID to the effective group ID of the creating process. Conforming applications should not assume which group ID will be used. If it matters, an application can use <i>chown<\/i>() to set the group ID after the file is created, or determine under what conditions the implementation will set the desired group ID.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The purpose of the <i>mknodat<\/i>() function is to create directories, special files, or regular files in directories other than the current working directory without exposure to race conditions. Any part of the path of a file could be changed in parallel to a call to <i>mknod<\/i>(), resulting in unspecified behavior. By opening a file descriptor for the target directory and using the <i>mknodat<\/i>() function it can be guaranteed that the newly created directory, special file, or regular file is located relative to the desired directory.<\/p>\n<h2>FUTURE DIRECTIONS <a name=\"FUTURE DIRECTIONS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">None.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><i>chmod<\/i>(), <i>creat<\/i>(), <i>exec<\/i>, <i>fstatat<\/i>(), <i>mkdir<\/i>(), <i>mkfifo<\/i>(), <i>open<\/i>(), <i>umask<\/i>()<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The Base Definitions volume of POSIX.1-2017, <b><fcntl.h><\/b>, <b><sys_stat.h><\/b><\/p>\n<h2>COPYRIGHT <a name=\"COPYRIGHT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology &#8212; Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http:\/\/www.opengroup.org\/unix\/online.html .<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https:\/\/www.kernel.org\/doc\/man-pages\/reporting_bugs.html .<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  mknod, mknodat \u2014 make directory, special file, or regular file <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3779,1],"tags":[1594,1708],"class_list":["post-4792","post","type-post","status-publish","format-standard","hentry","category-3pm-perl-llamadas-de-bibliotecas","category-sin-categoria","tag-man3p","tag-mknod"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4792","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=4792"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/4792\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=4792"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=4792"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=4792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}