📄 fattach.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-2004 IEEE and The Open Group, All Rights Reserved --><title>fattach</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="fattach"></a> <a name="tag_03_136"></a><!-- fattach --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2004 Edition<br>Copyright © 2001-2004 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_136_01"></a>NAME</h4><blockquote>fattach - attach a STREAMS-based file descriptor to a file in the file system name space (<b>STREAMS</b>)</blockquote><h4><a name="tag_03_136_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('XSR')">XSR</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include <<a href="../basedefs/stropts.h.html">stropts.h</a>><br><br> int fattach(int</tt> <i>fildes</i><tt>, const char *</tt><i>path</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_136_03"></a>DESCRIPTION</h4><blockquote><p>The <i>fattach</i>() function shall attach a STREAMS-based file descriptor to a file, effectively associating a pathname with<i>fildes</i>. The application shall ensure that the <i>fildes</i> argument is a valid open file descriptor associated with aSTREAMS file. The <i>path</i> argument points to a pathname of an existing file. The application shall have the appropriateprivileges or be the owner of the file named by <i>path</i> and have write permission. A successful call to <i>fattach</i>() shallcause all pathnames that name the file named by <i>path</i> to name the STREAMS file associated with <i>fildes</i>, until theSTREAMS file is detached from the file. A STREAMS file can be attached to more than one file and can have several pathnamesassociated with it.</p><p>The attributes of the named STREAMS file shall be initialized as follows: the permissions, user ID, group ID, and times are setto those of the file named by <i>path</i>, the number of links is set to 1, and the size and device identifier are set to those ofthe STREAMS file associated with <i>fildes</i>. If any attributes of the named STREAMS file are subsequently changed (for example,by <a href="../functions/chmod.html"><i>chmod</i>()</a>), neither the attributes of the underlying file nor the attributes of theSTREAMS file to which <i>fildes</i> refers shall be affected.</p><p>File descriptors referring to the underlying file, opened prior to an <i>fattach</i>() call, shall continue to refer to theunderlying file.</p></blockquote><h4><a name="tag_03_136_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, <i>fattach</i>() shall return 0. Otherwise, -1 shall be returned and <i>errno</i> set to indicatethe error.</p></blockquote><h4><a name="tag_03_136_05"></a>ERRORS</h4><blockquote><p>The <i>fattach</i>() function shall fail if:</p><dl compact><dt>[EACCES]</dt><dd>Search permission is denied for a component of the path prefix, or the process is the owner of <i>path</i> but does not havewrite permissions on the file named by <i>path</i>.</dd><dt>[EBADF]</dt><dd>The <i>fildes</i> argument is not a valid open file descriptor.</dd><dt>[EBUSY]</dt><dd>The file named by <i>path</i> is currently a mount point or has a STREAMS file attached to it.</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 size of <i>path</i> exceeds {PATH_MAX} or a component of <i>path</i> is longer than {NAME_MAX}.</dd><dt>[ENOENT]</dt><dd>A component of <i>path</i> does not name an existing file or <i>path</i> is an empty string.</dd><dt>[ENOTDIR]</dt><dd>A component of the path prefix is not a directory.</dd><dt>[EPERM]</dt><dd>The effective user ID of the process is not the owner of the file named by <i>path</i> and the process does not haveappropriate privilege.</dd></dl><p>The <i>fattach</i>() function may fail if:</p><dl compact><dt>[EINVAL]</dt><dd>The <i>fildes</i> argument does not refer to a STREAMS file.</dd><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><dt>[EXDEV]</dt><dd>A link to a file on another file system was attempted.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_136_06"></a>EXAMPLES</h4><blockquote><h5><a name="tag_03_136_06_01"></a>Attaching a File Descriptor to a File</h5><p>In the following example, <i>fd</i> refers to an open STREAMS file. The call to <i>fattach</i>() associates this STREAM with thefile <b>/tmp/named-STREAM</b>, such that any future calls to open <b>/tmp/named-STREAM</b>, prior to breaking the attachment via acall to <a href="../functions/fdetach.html"><i>fdetach</i>()</a>, will instead create a new file handle referring to the STREAMSfile associated with <i>fd</i>.</p><pre><tt>#include <stropts.h>... int fd; char *filename = "/tmp/named-STREAM"; int ret;<br> ret = fattach(fd, filename);</tt></pre></blockquote><h4><a name="tag_03_136_07"></a>APPLICATION USAGE</h4><blockquote><p>The <i>fattach</i>() function behaves similarly to the traditional <i>mount</i>() function in the way a file is temporarilyreplaced by the root directory of the mounted file system. In the case of <i>fattach</i>(), the replaced file need not be adirectory and the replacing file is a STREAMS file.</p></blockquote><h4><a name="tag_03_136_08"></a>RATIONALE</h4><blockquote><p>The file attributes of a file which has been the subject of an <i>fattach</i>() call are specifically set because of an artefactof the original implementation. The internal mechanism was the same as for the <i>mount</i>() function. Since <i>mount</i>() istypically only applied to directories, the effects when applied to a regular file are a little surprising, especially as regardsthe link count which rigidly remains one, even if there were several links originally and despite the fact that all original linksrefer to the STREAM as long as the <i>fattach</i>() remains in effect.</p></blockquote><h4><a name="tag_03_136_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_136_10"></a>SEE ALSO</h4><blockquote><p><a href="fdetach.html"><i>fdetach</i>()</a>, <a href="isastream.html"><i>isastream</i>()</a>, the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/stropts.h.html"><i><stropts.h></i></a></p></blockquote><h4><a name="tag_03_136_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 4, Version 2.</p></blockquote><h4><a name="tag_03_136_12"></a>Issue 5</h4><blockquote><p>Moved from X/OPEN UNIX extension to BASE.</p><p>The [EXDEV] error is added to the list of optional errors in the ERRORS section.</p></blockquote><h4><a name="tag_03_136_13"></a>Issue 6</h4><blockquote><p>This function is marked as part of the XSI STREAMS Option Group.</p><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 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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -