MODULE 5: DEVICE AND FILE MANAGEMENT
storage unless they are within a file. Commonly, files represent programs (both source and object forms) and data. Data files may be numeric, alphabetic, or alphanumeric etc. Files may be free form, such as text files, or may be formatted rigidly. In general, a file is a sequence of bits, bytes, lines, or records, the meaning of which is defined by the file’s creator and user. The concept of a file is thus extremely general. The information in a file is defined by its creator. Many different types of information may be stored in a file – source programs, object programs, executable programs, numeric data, text, payroll records, graphic images, sound recordings, and so on.
File Attributes
A file is named, for the convenience of its human users, and is referred to by its name. A name is usually a string of characters, such as example.c. Some systems differentiate between upper and lowercase characters in names, whereas other systems consider the two cases to be equivalent.
When a file is named, it becomes independent of the process, the user, and even the system that created it. For instance, one user might create the file example.c, whereas another user might edit that file by specifying its name. The file’s owner might write the file to a floppy disk, send it in an e-mail, or copy it across a network, and it could still be called example.c on the destination system. A file has certain other attributes, which vary from one operating system to another, but typically consists of these: Name, Identifier, Type, Location, Size, Protection, Time, date and user identification.
The information about all files is kept in the directory structure that also resides on secondary storage.
File Operations
A file is an abstract data type. To define a file properly, we need to consider the operations that can be performed on files. The operating system can provide system calls to create, write, read, reposition, delete, and truncate files. The following are five basic operations of the operating systems on files:
Creating a file
Writing a file
Reading a file
Deleting a file
Truncating a file
These five basic operations certainly comprise the minimal set of required file operations. Other common operations include appending new information to the end of an existing file and renaming the file.
File Types
When we design a file system, we always consider whether the operating system should recognize and support file types. If an operating system recognizes the type of a file, it can then operate on the file in reasonable ways.
A common technique for implementing file types is to include the type as a set of the file name.
The name is split into two parts – a name and an extension usually separated by a period (see Table 2.1)
Table 2.1 Some common file types
File Type Usual extension Function
Executable exe, com, bin Read to run machine- Language program Object obj Compiled, machine Language
Source code c, cc, java, pas Source code in Various language
Batch bat, sh Commands to the Command Interpreter
Text txt, doc Textual data, documents
Word processor wp, tex, rrf, doc Various word-processor formats Library lib, dll, mpeg Libraries of routines for programmers Archive arc, zip, tar Related files grouped into one file,
Compressed, for archiving or storage Multimedia mpeg, mov, rm Binary file containing audio
ACCESS METHODS
Files store information, when it is used, this information must be accessed and read into computer memory. The information in the file can be accessed in several ways. Some systems provide only one access method for files. Other systems, support many access methods.
Sequential File
In seque ntial file, records are stored one after the other in a predetermined form. This order is determined by the key fields on each record such as student matriculation number. An example is a magnetic tape where records/files are stored sequentially. To locate a particular record/file implies searching from the beginning of the sequentially file, one after the other until the record is located.
Advantages
It is the simplest access method.
It is easily stored on sequential access devices (ie tape) and random access devices (ie disk).
Disadvantages
For interactive applications that involve queries or updates of individual records, the sequential file provides poor performance.
Addition to the file also present problems.
Direct File
Records in a direct file are not stored physically one after the other, rather, they are stored on a disk with a particular address or location that can be determined by their key field. The file allows programs to read and write records rapidly in no particular order. The direct access is based on disk model since disk allows random access to any file block.
Advantages
Direct access are often used and are very efficient where very rapid access is required ie queries on database.
It supports random access.
Disadvantage
Searching for a record may take a little time since there is no index Index Sequential file
This is a compromise between sequential and direct file. It stores records in a file in a sequential order but has an index associated with it. The index lists the key to each group of records stored and the corresponding disk address for that group. This is similar to the index at the end of a book that gives easy access to the content.
Advantage
The index to the file support random access.
Disadvantage
Creation of index table causes addition overhead