441 lines
12 KiB
HTML
441 lines
12 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
|
|
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
|
|
<title>mknod</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="mknod"></a> <a name="tag_03_373"></a><!-- mknod -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_03_373_01"></a>NAME</h4>
|
|
|
|
<blockquote>mknod - make a directory, a special file, or a regular file</blockquote>
|
|
|
|
<h4><a name="tag_03_373_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt=
|
|
"[Option Start]" border="0"> #include <<a href="../basedefs/sys/stat.h.html">sys/stat.h</a>><br>
|
|
<br>
|
|
int mknod(const char *</tt><i>path</i><tt>, mode_t</tt> <i>mode</i><tt>, dev_t</tt> <i>dev</i><tt>); <img src=
|
|
"../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div>
|
|
|
|
<tt><br>
|
|
</tt></blockquote>
|
|
|
|
<h4><a name="tag_03_373_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>mknod</i>() function shall create a new file named by the pathname to which the argument <i>path</i> points.</p>
|
|
|
|
<p>The file type for <i>path</i> is OR'ed into the <i>mode</i> argument, and the application shall select one of the following
|
|
symbolic constants:</p>
|
|
|
|
<center>
|
|
<table border="1" cellpadding="3" align="center">
|
|
<tr valign="top">
|
|
<th align="center">
|
|
<p class="tent"><b>Name</b></p>
|
|
</th>
|
|
<th align="center">
|
|
<p class="tent"><b>Description</b></p>
|
|
</th>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_IFIFO</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">FIFO-special</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_IFCHR</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Character-special (non-portable)</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_IFDIR</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Directory (non-portable)</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_IFBLK</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Block-special (non-portable)</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_IFREG</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Regular (non-portable)</p>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
|
|
<p>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>
|
|
|
|
<p>The permissions for the new file are OR'ed into the <i>mode</i> argument, and may be selected from any combination of the
|
|
following symbolic constants:</p>
|
|
|
|
<center>
|
|
<table border="1" cellpadding="3" align="center">
|
|
<tr valign="top">
|
|
<th align="center">
|
|
<p class="tent"><b>Name</b></p>
|
|
</th>
|
|
<th align="center">
|
|
<p class="tent"><b>Description</b></p>
|
|
</th>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_ISUID</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Set user ID on execution.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_ISGID</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Set group ID on execution.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_IRWXU</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Read, write, or execute (search) by owner.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_IRUSR</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Read by owner.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_IWUSR</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Write by owner.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_IXUSR</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Execute (search) by owner.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_IRWXG</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Read, write, or execute (search) by group.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_IRGRP</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Read by group.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_IWGRP</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Write by group.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_IXGRP</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Execute (search) by group.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_IRWXO</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Read, write, or execute (search) by others.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_IROTH</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Read by others.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_IWOTH</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Write by others.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_IXOTH</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Execute (search) by others.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="left">
|
|
<p class="tent">S_ISVTX</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">On directories, restricted deletion flag.</p>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
|
|
<p>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's group ID to the group ID of the parent directory. Implementations may, but need not, provide an
|
|
implementation-defined way to initialize the file's 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>
|
|
|
|
<p>If <i>path</i> names a symbolic link, <i>mknod</i>() shall fail and set <i>errno</i> to [EEXIST].</p>
|
|
|
|
<p>Upon successful completion, <i>mknod</i>() shall mark for update the <i>st_atime</i>, <i>st_ctime</i>, and <i>st_mtime</i>
|
|
fields of the file. Also, the <i>st_ctime</i> and <i>st_mtime</i> fields of the directory that contains the new entry shall be
|
|
marked for update.</p>
|
|
|
|
<p>Only a process with appropriate privileges may invoke <i>mknod</i>() for file types other than FIFO-special.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_373_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>Upon successful completion, <i>mknod</i>() shall return 0. Otherwise, it shall return -1, the new file shall not be created, and
|
|
<i>errno</i> shall be set to indicate the error.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_373_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>mknod</i>() function shall fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EACCES]</dt>
|
|
|
|
<dd>A component of the path prefix denies search permission, or write permission is denied on the parent directory.</dd>
|
|
|
|
<dt>[EEXIST]</dt>
|
|
|
|
<dd>The named file exists.</dd>
|
|
|
|
<dt>[EINVAL]</dt>
|
|
|
|
<dd>An invalid argument exists.</dd>
|
|
|
|
<dt>[EIO]</dt>
|
|
|
|
<dd>An I/O error occurred while accessing the file system.</dd>
|
|
|
|
<dt>[ELOOP]</dt>
|
|
|
|
<dd>A loop exists in symbolic links encountered during resolution of the <i>path</i> argument.</dd>
|
|
|
|
<dt>[ENAMETOOLONG]</dt>
|
|
|
|
<dd>
|
|
The length of a pathname exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}.</dd>
|
|
|
|
<dt>[ENOENT]</dt>
|
|
|
|
<dd>A component of the path prefix specified by <i>path</i> does not name an existing directory or <i>path</i> is an empty
|
|
string.</dd>
|
|
|
|
<dt>[ENOSPC]</dt>
|
|
|
|
<dd>The directory that would contain the new file cannot be extended or the file system is out of file allocation resources.</dd>
|
|
|
|
<dt>[ENOTDIR]</dt>
|
|
|
|
<dd>A component of the path prefix is not a directory.</dd>
|
|
|
|
<dt>[EPERM]</dt>
|
|
|
|
<dd>The invoking process does not have appropriate privileges and the file type is not FIFO-special.</dd>
|
|
|
|
<dt>[EROFS]</dt>
|
|
|
|
<dd>The directory in which the file is to be created is located on a read-only file system.</dd>
|
|
</dl>
|
|
|
|
<p>The <i>mknod</i>() function may fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[ELOOP]</dt>
|
|
|
|
<dd>More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the <i>path</i> argument.</dd>
|
|
|
|
<dt>[ENAMETOOLONG]</dt>
|
|
|
|
<dd>
|
|
Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_03_373_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<h5><a name="tag_03_373_06_01"></a>Creating a FIFO Special File</h5>
|
|
|
|
<p>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>
|
|
|
|
<pre>
|
|
<tt>#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
<br>
|
|
dev_t dev;
|
|
int status;
|
|
...
|
|
status = mknod("/home/cnd/mod_done", S_IFIFO | S_IWUSR |
|
|
S_IRUSR | S_IRGRP | S_IROTH, dev);
|
|
</tt>
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_373_07"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>The <a href="../functions/mkfifo.html"><i>mkfifo</i>()</a> function is preferred over this function for making FIFO special
|
|
files.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_373_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>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 <a href="../functions/chown.html"><i>chown</i>()</a> to set the group ID after the file is created,
|
|
or determine under what conditions the implementation will set the desired group ID.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_373_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_373_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="chmod.html"><i>chmod</i>()</a> , <a href="creat.html"><i>creat</i>()</a> , <a href="exec.html"><i><a href=
|
|
"../functions/exec.html">exec</a></i>()</a> , <a href="mkdir.html"><i>mkdir</i>()</a> , <a href="mkfifo.html"><i>mkfifo</i>()</a> ,
|
|
<a href="open.html"><i>open</i>()</a> , <a href="stat.html"><i>stat</i>()</a> , <a href="umask.html"><i>umask</i>()</a> , the Base
|
|
Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/sys/stat.h.html"><i><sys/stat.h></i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_373_11"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 4, Version 2.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_373_12"></a>Issue 5</h4>
|
|
|
|
<blockquote>
|
|
<p>Moved from X/OPEN UNIX extension to BASE.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_373_13"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>The DESCRIPTION is updated to avoid use of the term "must" for application requirements.</p>
|
|
|
|
<p>The wording of the mandatory [ELOOP] error condition is updated, and a second optional [ELOOP] error condition is added.</p>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® is a registered Trademark of The IEEE.<br>
|
|
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
|
|
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
|
|
]</font></center>
|
|
|
|
<!--footer end-->
|
|
<hr size="2" noshade>
|
|
</body>
|
|
</html>
|
|
|