OS-11: File System

An introduction to the concepts related to file systems.

File Concepts

A file is a named collection of related information stored on secondary storage.

Types:

  • Text
  • Source/object programs
  • Executable programs
  • Database records
  • Graphic images
  • Multimedia
file typeusual extensionfunction
executableexe, com, bin or noneready-to-run machine language program
objectobj, ocompiled, machine language, not linked
source codec,cc,java,pas, asm, asource code in various languages
batchbat, shcommands to the command interpreter
texttxt, doctextual data, documents
word processorwp, tex, rtf, docvarious word-processor formats
librarylib, a, so, dlllibraries of routines for programmers
print or viewps, pdf, jpgASCII or binary file in a format for printing or viewing
archivearc, zip, tarrelated files grouped into one file, sometimes com pressed, for archiving or storage
multimediampeg, mov, rm, mp3,avibinary file containing audio or information

File Attributes

  • Name
  • Identifier:
    • A unique identifier inside the file system
    • Assigned by the operating system
  • Type
  • Location:
    • The location of the file on disk
    • Assigned by the operating system
  • Size
  • Protection information:
    • Access permissions
    • File owner
    • Access permissions of other users
  • Time, date and user identification:
    • Creation time
    • Modification time
    • Last access time
    • User identification

File Structure

  • No structure
  • Simple structure
    • Fixed-length records
    • Variable length
  • Complex structure
    • Formatted documents
    • Relocatable load files

File Operations

Create, open, close, read, write, rename, delete, reposition (it allows a user or program to directly access a specific position in a file without having to read the whole file sequentially.)

File Access Methods and Protection

Access Methods

  • Sequential Access
    • Reading can only start from the beginning of the file
    • Only sequential access is possible
  • Direct Access
    • Allows reading and writing at any position in the file
    • Allows random access
  • Indexed Access

Protection

Basic operation permissions: r w x read, write, execute

User groups: owner, group, public

Directory Structures

A disk can be subdivided into multiple partitions, which are also called minidisks or slices.

A partition can be used to store a file system; an entity that contains a file system is called a volume.

Each volume records the relevant information about its file system in a device directory or volume table of contents.

A disk or partition can also choose not to use a file system, i.e. be used as a raw device, or be formatted and then used with a specific file system.

Disks can be protected with RAID to guard against failures.

Directory Structure

Directory typeStructural characteristicsAdvantagesDisadvantagesApplication scenarios and examples
Single-level directoryAll users share one directory; files are stored directly in that directory with no hierarchySimple structure, easy to understand and implementLow file lookup efficiency; lookup time grows sharply as the number of files increases; prone to naming conflicts, different users can hardly use the same file name; cannot effectively protect users’ private files, since all files are on the same level and can easily be accessed and modified by other users; lacks the ability to group files, making it inconvenient to categorize and manage themEarly simple operating systems, or specific scenarios with very few files and low requirements for security and ease of management. For example, some simple embedded systems that only store a few configuration files may use it
Two-level directoryAn independent directory is created for each user, forming a two-level structure; each user’s files are stored under their own directorySolves the file name conflict problem between different users; the same file name can exist in different user directories; file lookup efficiency is improved compared with a single-level directory, since only the specific user directory needs to be searchedLimited file grouping capability; files can only be roughly distinguished by user, and cannot be grouped more finely by file attributes, purpose, etc.Suitable for scenarios with a relatively fixed number of users that have certain security requirements for file management but not very complex file grouping needs. For example, early multi-user small office systems, where each user has their own file directory
Tree-structured directoryStarting from the root directory, a multi-level tree hierarchy is formed; a directory can contain files and subdirectoriesClear hierarchy, convenient for categorizing, managing and finding files; users can put files into different subdirectories by category; flexible file organization that can be extended in depth and breadth as needed-Widely used in all kinds of operating systems, such as the file management of mainstream operating systems like Windows, Linux and Unix. Users create different folders in the operating system to store different types of files such as documents, pictures and programs
Acyclic-graph directoryAllows shared subdirectories and files; files or subdirectories are shared through linksCan effectively reduce the storage space occupied by files; multiple directories can share the same file or subdirectory, avoiding duplicate storage; convenient for file sharing and collaboration, multiple users or projects can share the same file resourcesDeleting a shared file may cause dangling pointer problems; if handled improperly, pointers point to invalid locations, affecting system stability; implementation and management are relatively complex, requiring extra handling of shared links and consistency maintenanceSuitable for scenarios with high file sharing demands, such as a company’s internal document management system, where multiple departments may need to share certain files; in software development teams, multiple projects may share some common code files
General graph directoryA more complex directory structure with more flexible linking, allowing links to files and subdirectoriesProvides extremely high flexibility; complex file relationships can be built according to actual needsThe cycle problem that may arise when adding links must be solved, otherwise the directory structure becomes chaotic; difficult to implement and manage, with high demands on system resources and algorithmsMay be used in some professional fields with extremely high requirements for file organization flexibility, such as the organization of data files in large database management systems; file management for complex research projects that need to build complex file relationships

1

Two ways of implementing an acyclic-graph directory:

  • Links
  • Duplicating the file information

Deleting a file easily produces dangling pointers; this can be handled by dealing with the links when the file is deleted / keeping the file until all references are deleted.
2

General graph directory: files/subdirectories can be linked, but cycles are not allowed (garbage collection)

Directory Implementation

  • Linear List
  • Hash Table

File System Structures and Operations

Front end: concerned with how the file system is presented to users, providing users with an interface for operating on files

Back end: responsible for creating the algorithms and data structures that map the logical file system onto the physical secondary storage devices

Layered File System

1

LayerFunctionCharacteristicsRelationship with other layersRelated data structures
Device driver layer (I/O control layer)Translates logical addresses into hardware-specific commands and controls data transfer of I/O devicesActs like a translator, interacting directly with the hardwareReceives commands from the basic file system and operates the hardwareNo independent specific data structure; relies on the data structures of the hardware controller
Basic file system layerIssues commands to the device driver layer based on logical addresses; manages I/O scheduling, memory buffers and cachesResponsible for low-level data block reads and writes, optimizing I/O operationsGets information from the file-organization module, issues commands to the device driver layer, and provides data to the logical file systemMemory buffers, caches
File-organization module layerManages the logical structure of files, keeps track of logical blocks and free blocks, and allocates spaceUnderstands the logical blocks of files and manages free spaceReceives requests from the logical file system and provides logical block information to the basic file systemData structures related to the free-space manager
Logical file system layerManages metadata, translates file names into file numbers etc., and performs directory management and file protectionMaintains the logical view and security of the file systemInteracts with applications and calls the functions of the file-organization moduleFile control block (FCB, e.g. the inode in Unix), containing permissions, dates and other information

File-System Operations

  1. On-storage data structures
    • Boot control block: one per volume; if the volume contains the operating system, it is usually located at the beginning of the volume and stores the information needed to boot the system.
    • Volume control block: one per volume; records detailed information such as the total number of blocks, the number of free blocks, the block size and free-block pointers.
    • Directory structure: organizes files and stores file names and inode numbers etc., making files easy to locate and access.
    • File control block: one per file; contains the file’s detailed attributes such as identifier, permissions, size and dates.
  2. In-memory data structures
    • Mount table: records information about each mounted volume, used by the system to identify and manage volumes.
    • Directory-structure cache: caches recently accessed directory information to improve the efficiency of file lookup and operations.
    • System-wide open-file table: stores a copy of the FCB of each open file and other related information, tracking and managing all open files.
    • Per-process open-file table: contains pointers into the system-wide open-file table, as well as process-specific information about the files it has opened.
    • Buffers: temporarily hold file system blocks during file reads and writes, bridging the speed gap between disk and memory.

Partitions and Mounting

  1. Partition
    • Definition and purpose: partitioning divides a disk into multiple relatively independent logical regions. A partition can be a “cooked” volume containing a file system; if that file system is bootable, the partition also needs to store boot information. It can also be a “raw” volume that contains no file system and is just a sequence of blocks. The root partition is generally used to hold the operating system, while other partitions can store different types of operating systems, file systems, or remain raw.
    • Booting: the boot block is crucial in a partition; it can point to the boot volume or to a set of boot-loader blocks containing the code that loads the kernel. In the case of booting multiple operating systems, the boot block can point to a boot manager.
  2. Mounting
    • Concept of mounting: mounting is the process of attaching a storage device or its file system to the operating system’s directory tree, so that the files on the device become accessible to the system. For example, after an external storage device is mounted onto some directory of the system, users can access the files on the device through that directory path.
    • Mounting methods: the root partition is usually mounted at system boot, while the mounting of other partitions is more flexible: they can be mounted automatically at system boot, or mounted manually by users as needed.

Allocation Methods

An allocation method refers to how disk blocks are allocated for files

  • Contiguous Allocation
  • Linked Allocation
  • Indexed Allocation

Extension: File-Allocation Table (FAT)

I-node Example

1
Green: logical blocks. Black: physical disk blocks

Combined with Disk Scheduling
2

Free Space Management

  • Bit Vector/Map: a bit vector indicates whether each block is free (0/1)
  • Linked List: all free blocks are organized into a linked list
  • Grouping and Counting: the free blocks on the storage device are divided into groups, and a counter is set for each group of free blocks
  • Space Maps: a data structure is created to record the usage state of each block on the storage device in detail

Virtual and Remote File Systems

VFS: a software layer that provides the operating system with a unified file system interface. It acts as an abstraction layer between the operating system kernel and the concrete file system drivers. It includes a caching mechanism for file system objects and can support multiple different types of file systems at the same time.

Remote file systems enable sharing of files across a network.


Translated from the Chinese original.

Welcome to my other publishing channels

中文