Operating System - File System



A file is a named collection of related information that is recorded on secondary storage such as magnetic disks, magnetic tapes and optical disks. In general, a file is a sequence of bits, bytes, lines or records whose meaning is defined by the files creator and user.

File Structure

A File Structure should be according to a required format that the operating system can understand.

  • A file has a certain defined structure according to its type.
  • A text file is a sequence of characters organized into lines.
  • A source file is a sequence of procedures and functions.
  • An object file is a sequence of bytes organized into blocks that are understandable by the machine.
  • When operating system defines different file structures, it also contains the code to support these file structure. Unix, MS-DOS support minimum number of file structure.

Types of Files

File type refers to the ability of the operating system to distinguish different types of file such as text files source files and binary files etc. Many operating systems support many types of files. Operating system like MS-DOS and UNIX have the following types of files −

Ordinary files

  • These are the files that contain user information.
  • These may have text, databases or executable programs.
  • The user can apply various operations on such files like add, modify, delete or even remove the entire file.

Directory files

  • These files contain list of file names and other information related to these files.

Special files

  • These files are also known as device files.
  • These files represent physical device like disks, terminals, printers, networks, tape drive etc.

These files are of two types, Character special files and Block special files. In character special files, data is handled character by character as in case of terminals or printers. In block special files, data is handled in blocks as in the case of disks and tapes.

File System

A file system is a structure used by an operating system to organize and manage files on storage devices such as hard drives, SSDs, and USB drives. It stores data in a hierarchical manner, i.e., in directories (folders) and subdirectories. The file system defines how data is stored, accessed, and managed on the storage device.

Example

Here is an example of a file system structure −

C:\
│── Program Files
│   │── App1        
│   │── App2
│       │── Users
│           │── User1
│               │── Documents
│                   │── File1.txt
│                   │── File2.docx
│           │── User2
│── Pictures
    │── Image1.jpg
    │── Image2.png

In the above example, the file system is organized in a hierarchical structure. The root directory is "C:\", which contains two main directories: "Program Files" and "Pictures". The "Program Files" directory contains subdirectories for different applications, and each application may have its own subdirectories for user data. The "Pictures" directory contains image files.

File Access Mechanisms

File access mechanism refers to the manner in which the records of a file may be accessed. There are several ways to access files −

  • Sequential access − A sequential access is that in which the records are accessed in some sequence, i.e., the information in the file is processed in order, one record after the other. This access method is the most primitive one. Example: Compilers usually access files in this fashion.
  • Direct/Random access − Random access file organization provides, accessing the records directly. Each record has its own address on the file with by the help of which it can be directly accessed for reading or writing. The records need not be in any sequence within the file and they need not be in adjacent locations on the storage medium.
  • Indexed sequential access − This mechanism is built up on base of sequential access. An index is created for each file which contains pointers to various blocks. The index is searched sequentially and its pointer is used to access the file directly.

Space Allocation

Files are allocated disk spaces by operating system. Operating systems deploy following three main ways to allocate disk space to files.

  • Contiguous Allocation − Each file occupies a contiguous address space on disk. Assigned disk address is in linear order. Easy to implement. External fragmentation is a major issue with this type of allocation technique.
  • Linked Allocation − Each file is a linked list of disk blocks which may be scattered anywhere on the disk. No external fragmentation. Suitable for sequential access files. Difficult to implement direct access files.
  • Indexed Allocation − Each file has its own index block which contains pointers to the actual data blocks. This allows for efficient random access and eliminates external fragmentation.

Types of File Systems

Depending on the operating system and storage device, there are few types of file systems −

  • FAT (File Allocation Table)
  • NTFS (New Technology File System)
  • exFAT (Extended File Allocation Table)
  • HFS+ (Hierarchical File System Plus)
  • APFS (Apple File System)

1. FAT (File Allocation Table)

The FAT file system the oldest and simplest file system. It was widely used in early versions of Windows and is still used in some removable storage devices. FAT has several variants, such as FAT12, FAT16, and FAT32, which differ in their maximum file size and partition size limits.

The maximum file size that FAT supports by FAT32 is 4GB. It also supports a maximum partition size of 2TB. FAT Systems lack advanced features like file permissions and journaling. So it is not suitable for modern operating systems.

2. NTFS (New Technology File System)

NTFS is the default file system used by modern versions of Windows. It have several advanced features, such as file permissions, encryption, compression, and journaling. NTFS supports large file sizes (up to 16TB) and large partition sizes (up to 256TB).

3. exFAT (Extended File Allocation Table)

exFAT is a file system designed for flash drives and other removable storage devices (like SD cards). It supports large file sizes (up to 16 exabytes) and large partition sizes (up to 128PB). exFAT is compatible with both Windows and macOS. So it is widely used sharing files between different operating systems.

4. HFS+ (Hierarchical File System Plus)

HFS+ is the file system used in older versions of macOS. It supports major features like file permissions, journaling, and metadata . It is compatible with large file sizes (up to 8EB) and large partition sizes (up to 8EB).

5. APFS (Apple File System)

APFS is the default file system used by modern versions of macOS, iOS, and other Apple devices. It is very optimized for solid-state drives (SSDs) and flash storage. APFS supports advanced features like file cloning, snapshots, encryption, and space sharing. It is the main reason behind the smooth ecosystem of Apple devices.

Advertisements