The file system is one of the most visible aspect of an operating system, which provides the mechanism for storage as well as access to both data and programs of the operating system.
The file system consists of two distinct parts: a collection of files, each storing related data, and a directory structure, which organizes and provides information about all the files in the system. However, to properly understand file systems, let us first look at what exactly is a file and what are its attributes and operations.
In order to make the use of computer systems convenient for the user, the operating system provides a uniform logical view of stored information by separating the data into logical storage units known as a ‘file’, which can be easily isolated and identified.
Hence, this prevents storage mediums to simply be one large body of data with no way to tell where one piece of data stops and the next begins. These files are mapped by the operating system onto the physical storage devices.
A file may be defined as a named collection of related information that is recorded on secondary storage. From a user’s perspective, a file is the smallest allotment of logical secondary storage; that is, data cannot be written to secondary storage unless they are within a file. Commonly, files represent programs as well as data, which may be numeric, alphabetic, alphanumeric, or binary. 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.
File Attributes
There are different types of information which can be stored in a file such as source or executable programs, numeric or text data, photos, music, video, etc. The information in a file is defined by its creator. A file also has a certain defined structure, which depends on its type. For example, a text file is a sequence of characters organized into lines, whereas an executable file is a series of code sections that the loader can bring into memory and execute.
A file’s attributes vary from one operating system to another but typically consist of the following:
- Name: The file name is an information kept in human- readable form which can be defined by the creator.
- Identifier: This unique tag, usually a number, identifies the file within the file system; it is the non-human-readable name for the file.
- Type: This information is needed for systems that support different types of files.
- Location: This information 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, executing, and so on.
- Time, date, and user identification: This information may be kept for creation, last modification, and last use. These data can be useful for protection, security, and usage monitoring.
File Operations
In order to properly define a file, we need to consider the operations that can be performed on files. The operating system can create, write, read, reposition, delete, and truncate files. Let us also look into what the operating system must do to perform each of these six basic file operations:
- Creating a file: There are to requirements for creating a file – firstly, there should be sufficient space in the file system for the file; secondly, an entry for the new file must be made in the directory.
- Writing a file: To write a file, we need to specify both the name of the file as well as the information to be written to the file. Given the name of the file, the system searches the directory to find the file’s location. The system must keep a write pointer to the location in the file where the next write is to take place. The write pointer must further update whenever a write occurs.
- Reading a file: To read from a file, we again need to specify the name of the file and where (in memory) the next block of the file should be put. Again, the directory is searched for the associated entry, and the system needs to keep a read pointer to the location in the file where the next read is to take place. A Read pointer is maintained by the OS, pointing to the position up to which, the data has been read. Once the read has taken place, the read pointer is updated.
- Repositioning within a file: Re-positioning is simply moving the file pointers forward or backward depending upon the user’s requirement. The directory is searched for the appropriate entry, and the current file position pointer is repositioned to a given value. This file operation is also known as a file seek.
- Deleting a file: To delete a file, we search the directory for the named file. Having found the associated directory entry, we release all file space, so that it can be reused by other files, and erase the directory entry. Hence, deleting the file will not only delete all the data stored inside the file, but it will also delete all the attributes of the file.
- Truncating a file: Truncating is simply deleting the contents of the file without deleting the file attributes.The user may want to erase the contents of a file but keep its attributes. Rather than forcing the user to delete the file and then recreate it, this function allows all attributes to remain unchanged — except for file length—but lets the file be reset to length zero and its file space released.
These six basic operations comprise the minimal set of required file operations. Other common operations include appending new information
to the end of an existing file and renaming an existing file. These basic operations can then be combined to perform other file operations, such as creating a copy of a file or copying the file to another device, such as a printer or a display—by creating a new file and then reading from the old and writing to the new. It should then be easy to see how other similar operations, such as renaming a file, can be implemented.
Leave a Reply