fd - file descriptor files
The /dev/fd file system is a pseudo-file system layered beneath the Virtual
File System (VFS). The file descriptor files (fd*) are those files that
are accessible through file descriptors. The file descriptors use the nam-
ing convention /dev/fd/0, /dev/fd/1, /dev/fd/2 and so on up to any number.
To make the /dev/fd file system known to the operating system, you must
create the directory with the correct privileges, then you must mount the
file system. The following steps describe how to create the directory,
mount the file system both manually and automatically, and how to dismount
the file system:
1. Create the directory using the mkdir and chmod commands:
mkdir /dev/fd; chmod 777 /dev/fd
2. Mount the file system manually using the mount command:
mount -t fdfs /dev/fd /dev/fd
3. Mount the file system automatically by editing either the /etc/fstab
file or the /sbin/bcheckrc file.
Add the following entry to the /etc/fstab file:
/dev/fd /dev/fd fdfs rw 0 0
This entry mounts the pseudodevice /dev/fd on the /dev/fd directory
with read/write privileges. The file system type is fdfs and the
zeros (0) in the remaining fields specify that the file system is not
to be backed up nor can file system checks be performed by the fsck
command as this is a virtual file system.
Add the following entry to the /sbin/bcheckrc file:
# mount fdfs
echo 'Mounting /dev/fd filesystem'
/sbin/mount -a -v -t fdfs
Again, the /dev/fd file system should not be mounted in this manner if
an entire system is to be backed up starting from the root directory.
4. Dismount the file system using the umount command:
For correct truncate() behavior on fd files, you must load your pro-
gram using the -lsys5 flag.
The /dev/fd file descriptors should not be exported.
The following example show how the open and dup functions have the same
effect if file descriptor n is opened:
fd = open("/dev/fd/n", mode);
fd = dup(n);
In the above example, the open function is equal to the creat function and
mode is ignored. Using the dup function, subsequent reads or writes on the
fd file descriptor files fail unless the original file descriptor enables
The following error condition exists:
[EBADF] The file descriptor is not valid.
Commands: chmod(1), mkdir(1), mount(8).
Functions: creat(2), dup(2), open(2).