STREAMS-UX Programmer's Guide (February 2007)

STREAMS Mechanism and System Calls
Attaching and Detaching a Stream to a File - Named Streams
Chapter 2
40
Attaching and Detaching a Stream to a File - Named Streams
User applications can associate a stream or STREAMS-based pipe with an existing node in the file system
name space. This enables other processes to communicate with this process. For example, a process creates a
pipe and names one end of the pipe using fattach(). When another unrelated process opens this file, it gets
access to the named end of the pipe. The two processes can then communicate with each other like parent and
child processes communicating over the pipe. STREAMS users can access this feature by using the
fattach() and fdetach() library calls.
The fattach() library routine internally uses a special file system called ffs to support named streams.
The fattach (3C) System Call
fattach() attaches a STREAMS file descriptor to an object in the file system name space. A STREAMS file
descriptor refers to either a STREAMS-based pipe or a STREAMS device driver.
Synopsis
#include <stropts.h>
int fattach(int fd, const char *path);
Arguments
fd A STREAMS file descriptor.
path Path name of an existing object in the file system.
The path cannot have a stream already attached to it. The path cannot be a mount point for a file system or
the root of a file system. The caller must be an owner of the path with write permission or a user with the
appropriate privileges to attach the file descriptor. A STREAMS device or pipe can be attached to more than
one node in the file system name space. On attaching to a file system node, any operation on any of these
paths acts on the STREAMS device or pipe, instead of the file system object path.
Once the stream is named, the stat(2) system call on the path shows information for the stream. If the
named stream is a pipe, the stat(2) information shows that the path is a pipe. If the stream is a device
driver or a pseudo-device driver, the path appears as a device. Following are the attributes of a fattached
stream: the permissions, group ID, user ID, and times are set to those of the path. The number of links and
the size as well as the device number are set to those of the STREAMS device or pipe designated by the fd
parameter. If any attributes of the fattached stream are subsequently changed, the attributes of the
underlying object are not affected. For example, chown(2).
Return Values
Upon successful completion, fattach(3) returns 0. Otherwise, it returns a value of -1, and errno is set to
indicate the error.
The fdetach(3C) System Call
The fdetach() system call detaches a STREAMS file descriptor from an object in the file system name space.
Synopsis
#include <stropts.h>
int fdetach(const char *path);