File Systems in Operating Systems

File Systems (Recap)

  • A file system consists of two main parts:
    • A collection of files, each storing related data.
    • A directory structure, which organizes and provides information about all the files in the system.

Directory

  • A directory is a table that includes the file name and file attributes.
  • A directory may include a file name and a reference to a second location where the attributes are stored.

Windows File System

  • Windows has two different file systems:
    • Old file system based on using File Allocation Table (FAT32).
    • Newer file system named New Technology File System (NTFS).
  • Each of these file systems has a few sub-versions with minor differences.

Directory Structure in Old FAT32

  • Directory contains the file name, attributes, and a pointer to the file data (Microsoft’s FAT).
    • Advantage: Directory table shows file attributes more efficiently since you don't need to look them up in another place.
    • Disadvantage: Hard links cannot be implemented.

Directory Record in Old FAT32

  • Each record in the directory table includes the following data:
    • File name
    • File attributes
    • The ID of the first block
    • File size

File Name

  • File name can be up to 8 characters, and an extension up to 3 characters.
  • Total number of bytes allocated for file name is 11.
  • Extensions are used to define file types.
    • Example: mydata.pdf

File Attributes

  • File attributes is a one-byte field.
  • Each bit has a specific meaning as below:
    • Bit 0 (LSB): Read only - The file is read only.
    • Bit 1: Hidden - File is hidden.
    • Bit 2: System - File is part of the operating system.
    • Bit 3: Volume ID - ID of the disk partition.
    • Bit 4: Directory - File is directory.
    • Bit 5: Archive - File has changed and needs to be archived.
    • Bits 6 and 7: Unused - Are not used and should be zero.

File Size

  • A four-byte field that gives the file size in bytes.
  • The file size is not necessarily a multiple of block size.
  • The maximum file size is 4 GB.

The First Block ID

  • A four-byte attribute that shows the first block of the file.
  • The first block index is used to find the next block in a linked list (FAT32).

File Allocation Table

  • A list of blocks where many linked are created and stored.
  • Each entry of FAT is 32 bits (4 bytes).
  • The list of empty blocks is also stored in FAT32.

FAT32 Example

  • Shows a linked list example including MyFile.dat and Prog1.exe.

Free Blocks List

  • Shows an example of how free blocks are tracked in FAT32.
  • Free Blocks = 2 in given Example.

Using Clusters

  • FAT32 cannot be used with disks of very large capacities.
  • Windows improved the disk capacity of FAT32 by combining a few blocks into a cluster.
  • The disk access unit became clusters, which are 4, 8, or even 16 blocks.

File System Layout

  • Volume ID
  • Reserved Blocks
  • FAT (Main Copy)
  • FAT (Second Copy)
  • Main Directory Table
  • File and Directory Clusters

New Technologies File System (NTFS)

  • All the disk space is allocated as clusters.
  • The size of a cluster is a multiple of the disk block size (n \times 512 bytes, 4k usually).
  • NTFS supports journaling.
  • NTFS supports file data compression.

New Technologies File System (NTFS)

  • Similarly to inodes, NTFS uses Master File Table (MFT).
  • MFT contains records (Microsoft inodes).
  • MFT is organized in B-Tree.

Conclusion

  • File systems need to handle directories and files.
  • Windows uses FAT32 and NTFS in its file systems.
  • Windows Directory table includes file attributes, so no separate location for attributes.
  • FAT32 creates linked lists of blocks allocated to each file.
  • A list is also used to show the free disk blocks.