Related Content: CS604 - VU Lectures, Handouts, PPT Slides, Assignments, Quizzes, Papers & Books of Operating Systems
Computers can store information on several different storage media, such as magnetic disks, magnetic tapes and optical disks. The operating system abstracts from the physical properties of its storage devices to define a logical storage unit (the file). Files are mapped by the OS onto physical devices. These storage devices are usually non-volatile, so the contents are persistent through power failures, etc. A file is a named collection of related information that is recorded on secondary storage. Data cannot be written to secondary storage unless they are within a file. Commonly, files represent programs (source and object forms) and data. Data files may be numeric, alphabetic, alphanumeric or binary. In essence it is a contiguous logical address space.
A file has certain defined structure characteristics according to its type. A few common types of file structures are:
None – file is a sequence of words, bytes
Simple record structure
Lines
Fixed length
Variable length
Complex Structures
Formatted document
Relocatable load file
UNIX considers each file to be a sequence of bytes; no interpretation of these bytes is made by the OS. This scheme provides maximum flexibility but little support. Each application program must include its own code to interpret an input file into the appropriate structure. However all operating systems must support at least one structurethat of an executable file-so that the system is able to load and run programs.
Every file has certain attributes, which vary from one OS to another, but typically consist of these:
Name: The symbolic file name is the only information kept in human-readable form
Type: This information is needed for those systems that support different types.
Location: This location is a pointer to a device and to the location of the file on that
device.
Size: The current size of the file (in bytes, words or blocks) and possibly the maximum
allowed size are included in this attribute.
Protection: Access control information determines who can do reading , writing, etc.
Owner
Time and date created: useful for security, protection and usage monitoring.
Time and date last updated: useful for security, protection and usage monitoring.
Read/write pointer value
File attributes are stored in the directory structure, as part of the directory entry for a file, e.g., in DOS, Windows, or in a separate data structure; in UNIX/Linux this structure is known as the inode for the file.
A file is represented in a directory by its directory entry. Contents of a directory entry vary from system to system. For example, in DOS/Windows a directory entry consists of file name and its attributes. In UNIX/Linux, a directory entry consists of file name and inode number. Name can be up to 255 characters in BSD UNIX compliant systems. Inode number is used to access file’s inode. The following diagrams show directory entries for DOS/Windows and UNIX/Linux systems.
Various operations can be performed on files. Here are some of the commonly supported operations. In parentheses are written UNIX/Linux system calls for the corresponding operations.
A common technique for implementing files is to include the type of the file as part of the
file name. The name is split into two parts, a name and an extension, usually separated by
a period character. In this way, the user and the OS can tell from the name alone, what
the type of a file is.
The operating system uses the extension to indicate the type of the file and the type of
operations that can be done on that file. In DOS/Windows only a file with .exe, .com, .bat
extension can be executed.
The UNIX system uses a crude magic number stored at the beginning of some files to
indicate roughly the type of the file-executable program, batch file/shell script, etc. Not
all files have magic numbers, so system features cannot be based solely on this type of
information. UNIX does allow file name extension hints, but these extensions are not
enforced or depended on by the OS; they are mostly to aid users in determining the type
of contents of the file. Extension can be used or ignored by a given application.
The following tables shows some of the commonly supported file extensions on different operating systems.
UNIX does not support supports seven types of file:
Files store information that can be accessed in several ways:
Information in the file is processed in order, one record after the other. A read operation reads the next potion of the file and automatically advances a file pointer which tracks the I/O location. Similarly, a write operation appends to the end of the file and advances to the end of the newly written material. Such a file can be rest to the beginning and on some systems; a program may be able to skip forward or backward, n records.
A file is made up of fixed length logical record that allow program to read and write records in no particular order. For the direct-access method, the file operations must be modified to include the block number as a parameter (read n (n = relative block number), write n for instance). An alternate approach is to retain read next and write next and to add an operation, position file to n, where n is the block number. The block number provided by the user to the OS is normally a relative block number, an index relative to the beginning of the file.
It is a collection of directory entries. To manage all the data, first disks are split into one or more partitions. Each partition contains information about files within it. This information is kept within device directory or volume table of contents.
The following directory operations are commonly supported in contemporary operating systems. Next to each operation are UNIX system calls or commands for the corresponding operation.
When considering a particular directory structure we need to consider the following issues:
All files are contained in the same directory, which is easy to support and understand.
However when the number of files increases or the system has more than one user, it has
limitations. Since all the files are in the same directory, they must have unique names.
Single-level directory structure
There is a separate directory for each user.
When a user refers to a particular file, only his own user file directory (UFD) is
searched. Thus different users can have the same file name as long as the file names
within each UFD are unique. This directory structure allows efficient searching.
However, this structure effectively isolates one user from another, hence provides no
grouping capability.
Here is the tree directory structure. Each user has his/her own directory (known as user’s home directory) under which he/she can create a complete directory tree of his/her own.
The tree has a root directory. Every file in the system has a unique pathname. A path name is the path from the root, through al the subdirectories to a specified file. A directory/subdirectory contains a set of files or subdirectories. In normal use, each user has a current directory. The current directory should contain most of the files that are of current interest to the user. When a reference to a file is made, the current directory is searched. If a file is needed that is not in the current directory, then the user must either specify a path name or change the directory to the directory holding the file( using the cd system call).This structure hence supports efficient searching. Allowing the user to define his own subdirectories permits him to impose a structure on his files.A lso users can access files of other users.