Filesystem Manager

In QNX a file is an object that can be written to, read from, or both. QNX implements six types of files; five of these are managed by Fsys: Fsys maintains four different times for each file:
  1. date of last access (read)
  2. date of last write
  3. date of last modification
  4. date of creation

Regular files and directories

Regular files

QNX views a regular file as a randomly accessible sequence of bytes that has no other predefined internal structure. Applications are responsible for understanding the structure and content of any regular file.

Directories

A directory is a file that contains directory entries. Each directory entry associates a filename with a file. A filename is a symbolic name that lets you identify and access a file. A file may be identified by more than one filename. Although a directory behaves much like a standard file, the Filesystem Manager imposes some restrictions on the operations you can perform on a directory. You can not open a directory for writing, nor can you link to a directory with the link() C function.

To read directory entries, you can use a set of POSIX-defined C finctions. These functions include:

Since QNX directories are simply files that contaion "known" information, you can also read directory entries directly using the open() and read() functions. This technique is not portable, however, the format of directory entries varies from operating system to operating system.

Links and inodes

In QNX, file data can be referenced by more than one name. Each filename is called a link. There are actually two kinds of links: hard links, which we refer to simply as "links", and symbolic links. To support links for each file, the filename information is separated from the other information that describes a file. The non-filename information is stored in a structure called an inode. Note that you can create a link to a file only if the file and the link are in the same filesystem.

If a file has only one link, the inode information is stored in the directory entry for the file, otherwise the inode is stored as a record in a special file named /.inode, as are the file's directory entry points to the inode record. There are two other cases in which a file can have an entry in the /.inodes file:

You can create links from within the shell using ln utility, or from within programs with link() C function. You can not create hard links to directories.

When a file is created, it is given a link count of one. As links to the file are added, this link count is incremented; as links to the file are removed, the link count is decremented. The file is removed when its link count goes to zero and all programs using the file have closed it. To remove links from whitin the shell use rm utility, or from within programs use remove() or unlink() C functions.

Symbolic links

A symbolic link is a special file that has a pathname as its data. When a symbolic link is named in an I/O request (by open(), for example), the link portion of the pathname is replaced by the link's "data" and the path is re-evaluated. Unlike hard links, symnolic links can cross filesystems and can also create links to directories.

Several functions operate directly on the symbolic link. For these functions, the replacement of the symbolic element of the pathname with its target is not performed. These functions include unlink() (which removes the symbolic link), lstat(), and readlink().

Pipes and FIFOs

Pipes

A pipe is an unnamed file that serves as an I/O channel between two or more cooperating processes, one process writes into the pipe, the other reads from the pipe. The Filesystem Manager takes care of buffering the data. A typical application for a pipe is connectiong the output of one program to the input of another program. This connection is often made by the Shell. For example:

ls | more

directs the standard output from the ls utility through a pipe to the standard input of the more utility. If you want to create pipes from within the shell, use the pipe symbol ("|"), or if you want to create pipes from within programs, use pipe() or popen() C functions.

On diskless workstations, you can run the Pipe Manager (Pipe) inplace of the Filesystem Manager when only pipes are required. The Pipe Manager is optimized for pipe I/O.

FIFOs

FIFOs are essentially the same as pipes, except that FIFOs are named permanent files that are stored in filesystem directories. FIFOs can be created by mkfifo utility from within the shell, or mkfifo() C function from within programs. To remove FIFOs, use rm utility or remove() or unlink() function.