[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs

File Types

A file is a one-dimensional array of bytes with at least one hard link (file name). Files can contain ASCII or binary information. Files contain data, shell scripts, or programs. File names are also used to represent abstract objects such as sockets, pipes, and device drivers.

The kernel does not distinguish record boundaries in regular files. Programs can establish their own boundary markers if desired. For example, many programs use line-feed characters to mark the end of lines. "Working with Files" contains a list of the subroutines used to control files.

Files are represented in the journaled file system (JFS) by disk index nodes (i-node). Information about the file (such as ownership, access modes, access time, data addresses, and modification time) is stored in the i-node. For more information about the internal structure of files, see "Working with JFS i-nodes".

The journaled file system supports the following file types:

File Types Supported By Journaled File System
Type of File Macro Name Used in mode.h Description
Regular S_ISREG A sequence of bytes with one or more names. Regular files can contain ASCII or binary data. These files can be randomly accessed (read from or written to) from any byte in the file.
Directory S_ISDIR Contains directory entries (file name and i-number pairs). Directory formats are determined by the file system. Processes read directories as they do ordinary files, but the kernel reserves the right to write to a directory. Special sets of subroutines control directory entries.
Block Special S_ISBLK Associates a structured device driver with a file name.
Character Special S_ISCHR Associates an unstructured device driver with a file name.
Pipes S_ISFIFO Designates an interprocess communication channel (IPC). The mkfifo subroutine creates named pipes. The pipe subroutine creates unnamed pipes.
Symbolic Links S_ISLNK A file that contains either an absolute or relative path name to another file name.
Sockets S_ISSOCK An IPC mechanism that allows applications to exchange data. The socket subroutine creates sockets, and the bind subroutine allows sockets to be named.

The maximum size of a regular file in a file system enabled for large files (available beginning in Version 4.2) is slightly less than 64 gigabytes (68589453312). All nonregular files in a file system enabled for large files and all files in other JFS file system types have a maximum file size of 2 gigabytes minus 1 (2147483647). The maximum length of a file name is 255 characters, and the maximum length of a path name is 1023 bytes. For more information, see "File Space Allocation".

Working with Files

The operating system offers many subroutines that manipulate files. Brief descriptions of the most common file-control subroutines are provided in two categories:

Creating Files

creat Creates a new, empty, regular file.
open Creates a new, empty file if the O_CREAT flag is set.
mkfifo Creates a named pipe.
mkdir Creates a directory.
mknod Creates a file that defines a device.
socket Creates a socket.
pipe Creates an IPC.
link Creates an additional name (directory entry) for an existing file.

Manipulating Files (Programming)

open Returns a file descriptor used by other subroutines to reference the opened file. The open operation takes a regular file name and a permission mode that indicates whether the file is to be read from, written to, or both.
read Removes data from an open file if the appropriate permissions (O_RDONLY or O_RDWR) were set by the open subroutine.
write Puts data into an open file if the appropriate permissions (O_WRONLY or O_RDWR) were set by the open subroutine.
lseek or llseek Moves the I/O pointer position in an open file.
close Closes open file descriptors (including sockets).
rmdir Removes directories from the file system.
chown Changes ownership of a file.
chmod Changes the access modes of a file.
stat Reports the status of a file including the owner and access modes.
access Determines the accessibility of a file.
rename Changes the name of a file.
truncate Changes the length of a file.
ioctl Controls functions associated with open file descriptors, including special files, sockets, and generic device support like the termio general terminal interface.
fclear Creates space in file.
fsync Writes changes in a file to permanent storage.
fcntl, dup, or dup2 Controls open file descriptors.
lockf or flock Controls open file descriptors.

For more information on types and characteristics of file systems, see "File Systems Overview" in AIX Version 4.3 System Management Guide: Operating System and Devices.

Related Information

Files, Directories, and File Systems for Programmers lists other information on these topics.

Working with JFS i-nodes introduces the structure of the i-node and its contents.

File Space Allocation explains how the file system allocates data blocks.


[ Previous | Next | Contents | Glossary | Home | Search ]