The file system is the most prominent aspect of any operating system for most users. This provides users with methods for storage and access to data and programs of the operating system that all computer system users can use.

The file system consists of two distinct parts:

  • A collection of files that store related data.
  • A directory structure that organizes and provides information about all the files in the system.

In this tutorial, you will learn about the different file tributes, concepts of files, and their storage, along with operations on files.

File Attributes

Files are named to make it easy for users to refer to them. A file name is typically a string of characters, such as "filename.cpp", which includes an extension that identifies the file format. Some systems, like Linux, are case-sensitive regarding file names, while others are not.

Once a file is named, it becomes independent of the user, process, or system that created it. For example, one user might create a file called "filename.cpp", while another might edit it using its name. The file's owner could also write it to a CD, send it via email, or copy it across a network, and it would still be known as "filename.cpp" on the destination system.

Fundamental Components of A File

A file's attributes vary from one operating system to another but typically consist of these:

  • Name: Name is the symbolic file name and is the only information kept in human-readable form.
  • Identifier: This unique tag is a number that identifies the file within the file system; it is in the non-human-readable form of the file.
  • Type: This information is needed for systems that support different types of files or their formats.
  • Location: This information is a pointer to a device pointing to the file's location on the device where it is stored.
  • Size: The current file size (which is in bytes, words, etc.), possibly the maximum allowed size, gets included in this attribute.
  • Protection: Access-control information establishes who can do the reading, writing, executing, etc.
  • Date, Time, and user identification: This information might be kept for creating the file, its last modification, and its previous use. These data might be helpful in the field of protection, security, and monitoring its usage.

File Operations

A file is a type of data that is abstract. To define a file properly, we need to consider the various operations that can be performed on it. The operating system provides system calls to create, write, read, reposition, delete, and truncate files. An operating system has six basic file operations: creating, writing, reading, repositioning, deleting, and truncating files.

  • Creating a file: There are two steps necessary for creating a file. First, space in the file system must be found for the file. We discuss how to allocate space for the file. Second, an entry for the new file must be made in the directory.
  • Writing a file: To write a file, you make a system call to specify the file's name and the information to be written to the file.
  • Reading a file: To read from a file, you use a system call that specifies the file's name and where the next file block should be placed within memory.
  • Repositioning inside a file: The directory is then searched for a suitable entry, and the 'current-file-position' pointer is relocated to a given value. Relocating within a file need not require any actual I/O. This file operation is also termed as 'file seek.'
  • Deleting a file: To delete a file, you have to search the directory for the specific file. Deleting that file or directory releases all file space so other files can reuse that space.
  • Truncating a file: The user may wish to erase the contents of a file but keep the attributes same. Rather than deleting the file and then recreating it, this utility allows all attributes to remain unchanged — except the file length — and lets the user add or edit the file content.

Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram