Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

Section 4.3 File Types 95


Note that most members of thestatstructureare specified by a primitive system
data type (see Section 2.8).We’ll go through each member of this structure to examine
the attributes of a file.
The biggest user of thestatfunctions is probably thels -lcommand, to learn all
the information about a file.

4.3 FileTy pes


We’ve talked about two different types of files so far: regular files and directories. Most
files on a UNIX system areeither regular files or directories, but thereare additional
types of files. The types are


  1. Regular file. The most common type of file, which contains data of some form.
    There is no distinction to the UNIX kernel whether this data is text or binary.
    Any interpretation of the contents of a regular file is left to the application
    processing the file.


One notable exception to this is with binary executable files.To execute a program, the
kernel must understand its format. All binary executable files conform to a format that
allows the kernel to identify where to load a program’s text and data.


  1. Directory file. Afile that contains the names of other files and pointers to
    information on these files. Any process that has read permission for a directory
    file can read the contents of the directory,but only the kernel can write directly
    to a directory file. Processes must use the functions described in this chapter to
    make changes to a directory.

  2. Block special file.Atype of file providing buffered I/O access in fixed-size units
    to devices such as disk drives.


Note that FreeBSD no longer supports block special files. All access to devices is through
the character special interface.


  1. Character special file. Atype of file providing unbuffered I/O access in
    variable-sized units to devices. All devices on a system areeither block special
    files or character special files.

  2. FIFO.Atype of file used for communication between processes. It’s sometimes
    called a named pipe.We describe FIFOs in Section 15.5.

  3. Socket.Atype of file used for network communication between processes. A
    socket can also be used for non-network communication between processes on a
    single host.We use sockets for interprocess communication in Chapter 16.

  4. Symbolic link. A type of file that points to another file. We talk moreabout
    symbolic links in Section 4.17.
    The type of a file is encoded in thest_modemember of thestatstructure. Wecan
    determine the file type with the macros shown in Figure4.1. The argument to each of
    these macros is thest_modemember from thestatstructure.

Free download pdf