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, so programs can establish their own boundary markers.

Files are represented in the journaled file system (JFS and JFS2) 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.

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 (IPC) channel. 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 JFS file system enabled for large files is slightly less than 64 gigabytes (68589453312). In other file systems that are enabled for large files and in other JFS file system types, all files not listed as regular in the previous table have a maximum file size of 2 gigabytes minus 1 (2147483647). The maximum size of a file in JFS2 is limited by the size of the file system itself.

The architectural limit on the size of a JFS2 file system is 252 bytes, or 4 petabytes. The maximum file size supported by the 64-bit kernel is 244 - 4096 bytes, or just less than 16 terabytes.

The maximum length of a file name is 255 characters, and the maximum length of a path name is 1023 bytes.

Working with files

The operating system provides many subroutines that manipulate files. For brief descriptions of the most common file-control subroutines, see the following:

Creating files

The following subroutines are used when creating files:
creat
Creates a new, empty, regular file
link
Creates an additional name (directory entry) for an existing file
mkdir
Creates a directory
mkfifo
Creates a named pipe
mknod
Creates a file that defines a device
open
Creates a new, empty file if the O_CREAT flag is set
pipe
Creates an IPC
socket
Creates a socket

Manipulating files (programming)

The following subroutines can be used to manipulate files:
access
Determines the accessibility of a file.
chmod
Changes the access modes of a file.
chown
Changes ownership of a file.
close
Closes open file descriptors (including sockets).
fclear
Creates space in a file.
fcntl, dup, or dup2
Control open file descriptors.
fsync
Writes changes in a file to permanent storage.
ioctl
Controls functions associated with open file descriptors, including special files, sockets, and generic device support, such as the termio general terminal interface.
lockf or flock
Control open file descriptors.
lseek or llseek
Move the I/O pointer position in an open file.
open
Returns a file descriptor used by other subroutines to refer to 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
Gets data from an open file if the appropriate permissions (O_RDONLY or O_RDWR) were set by the open subroutine.
rename
Changes the name of a file.
rmdir
Removes directories from the file system.
stat
Reports the status of a file, including the owner and access modes.
truncate
Changes the length of a file.
write
Puts data into an open file if the appropriate permissions (O_WRONLY or O_RDWR) were set by the open subroutine.