Docsity

File System Implementation: Understanding On-Disk and In-Memory Structures, Study notes of Computer Science

Partial preview of the text

Download File System Implementation: Understanding On-Disk and In-Memory Structures and more Study notes Computer Science in PDF only on Docsity!

Operating SystemsOperating Systems

CMPSC 473 CMPSC 473

File System Implementation File System Implementation

April 1, 2008 - LectureApril 1, 2008 - Lecture^1919

Instructor: Trent Jaeger Instructor: Trent Jaeger

  • Last class:
    • File System Interface
  • Today:
    • File System Implementation

File Control Block

• Logical file system’s representation

of a file -- stored on disk

  • In UNIX, called an inode

Structures That Implement

a File System

  • On-disk structures
    • Boot control block
      • Info to boot the OS from the disk
      • Typically, the first block of the boot partition (boot block)
    • Partition control block
      • Info about a file system (number of blocks -- fixed size)
      • Includes free block information (superblock)
    • Directory Structure
    • File Control Blocks

In-memory structures for open() syscall fd=open(“a”,…); … read(fd,…); … close(fd); P fd=open(“a”,…); … read(fd,…); … close(fd); P fd=open(“b”,…); … write(fd,…); … close(fd); P OS i-node of “b” i-node of “a” Per-process Open File Descriptor Table System-wide Open File Descriptor table (all in Memory)

Exercise

• See how you can implement create file,

remove file, open, close, read, write etc for

the UNIX file system.

Partition Structures

• Layout of a file system on a disk

  • Raw: no file system structure
    • E.g., swap space, database, boot
  • Cooked: a file system structure
    • E.g., directories

Boot Partition

• Contains information to boot the system

  • Image to be loaded at boot time

• May boot more than one system

  • How is this done?
  • Bootloader is booted first (GRUB)
    • The you choose the OS to boot

File System Layers

Virtual File System Physical File System Device Drivers

Virtual File System

  • File systems have general and storage method-dependent parts - Virtual file system is specific to the OS - File system-generic operations - Works with inodes (FCB), files, directories, superblocks (partitions) - The stuff that we discussed - Physical file system is specific to how secondary storage will be used to manage data - Converts the objects above into blocks

File System Implementation

• View the disk as a logical sequence of blocks

• A block is the smallest unit of allocation.

• Issues:

  • How do you assign the blocks to files?
  • Given a file, how do you find its blocks?

File Allocation

  • Direct access of disks gives us flexibility in

implementing files

  • Relate to memory management problem
  • Choices
  • Contiguous
  • Non-contiguous
  • Linked
  • Indexed

Linked List Allocation

• Keep a pointer to first block of a file.

• The first few bytes of each block point to the

next block of this file.

• Advantages: No external fragmentation

• Disadvantages: Random access is slow!

File 1 File 2

Linked List Allocn. Using an Index (e.g. DOS)

  • In the prev. scheme, we needed to go to disk to chase pointers since memory cannot hold all the blocks.
  • Why not remove the pointers from the blocks, and maintain the pointers separately?
  • Perhaps, then all (or most) of the pointers can fit in memory.
  • Allocation is still done using linked list.
  • However, pointer chasing can be done “entirely” in memory.