Files

Files are logical units of information created by processes and are managed by the operating systems. The part of the opearting system dealing with files is known as the file system.


File Naming

When a process creates a file it gives the file a name, and even after this process terminates the file continues to exist and can be accessed by other processes by its name.
The exact rules for file naming might vary from one system to another but almost all operating systems allow strings of one to eight characters along with special characters like underscore.
The file naming as two parts which are seperated by a period. The name of the file after the period is called the file extension which indicates something about the file.

Extension Meaning
.bak backup file
.c C source code
.h C header file
.sh Shell script
.py Python source code
.gif Compuserve Graphical Interchange Format image
.hlp Help file
.html World Wide Web HyperText Markup language document
.jpg Still picture encoded with the JPEG standard
.mp3 Music encoded in MPEG layer 3 audio for mat

File Structure

There are three common ways for structuring of files


Byte Sequence: In this way of structuring, a file is an unstructured sequence of bytes. What is contained inside the file is specific to the program that will write / read them.
Record Sequence: In this structuring, a file is a sequence of fixed-length records, each with some internal structure.
Tree: In this organization, a file consists of a tree of records, not necessarily all the same length, each containing a key field in a fixed position in the record. The tree is sorted on the key field, to allow rapid searching for a particular key. All the basic operations are performed using the key value. This type of file is clearly quite different from the unstructured byte streams used in UNIX and Windows and is used on some large mainframe computers for commercial data processing.
Databases such as Oracle creates files that are like this, without relying on the OS to know the format.


File Types

UNIX and Windows operating systems have regular files and directories.

Regular files: Files containing user information. (This is how the book puts it, but these may also contain system info, such as /etc/passwd.)
Directories: These are the system files for maintaining the structure of file system.

UNIX also has two other types of files:
Character-special files: These files are related to input and output operations. They are used to model serial I/O devices, such as terminals, printers, and networks.
Block-special files: These files are used to model disks.

Regular files are generally ASCII or binary files:

ASCII files: Files containing lines of text. These files can be displayed and printed as is, and they can be edited with any text editor.
They can be used in pipelines, processed by scripts, etc.
Binary Files: These files are not human readable.
Executable binary files: The operating system will execute an executable binary file only if it has the proper format. Format of an executable file has 5 sections:

  1. Header
  2. Text
  3. Data
  4. Relocation bits
  5. Symbol table

Header section indicates that the binary file is executable, and contains other info about the program.

Archive: It consists of a collection of library procedures compiled but not linked. Each one is prefaced by a header telling its name, creation date, owner, protection code, and size.


File Access


File Attributes

Operating systems associate other information related to iles such as date and time when a file was created, ermissions for the file access as file attributes. These attributes are also called metadata. The list of attributes considerably vary from system to system.

Some file attributes:

Attribute Meaning
Protection Who can access the file and in what way
Read-only flag 0 for read/write; 1 for read only
Creation time Date and time the file was created
Time of last change Date and time the file was last changed
Current size Number of bytes in the file
Owner Current owner
Key Length Number of bytes in the key field
Temporary flag 0 for normal; 1 for delete file on process exit
Password Password needed to access the file


File Operations

Files exist to store information and allow it to be retrieved later. Different systems provide different operations to allow storage and retrieval. Some of the Operations are listed below.

Source code

External Links