Lab 8: File Systems
Feb. 28/Mar. 1, 2007
[153 Home]       [Introduction]       [Important System Calls]       [Resources]

Introduction
  • Your program should read a floppy disk image provided here:
  • Your program should accept the following commands and convert them into the corresponding function calls:

    COMMAND FUNCTION CALL
    load image int fd_load(char *image)
    ls int fd_ls()
    cd dir int fd_cd(char *directory)
    rm file int fd_rm(char *name)

  • Disk Geometry (CHS) and Logical Block Addressing (LBA):
    • Cylinders (Tracks), Heads (Surfaces), Sectors, Blocks.
          A 1.44 MB floppy disk has 80 cylinders (0-79), 2 heads (0-1) and 18 sectors (1-18),
          total number of blocks = 80*2*18 = 2880
    • Logical sector I on track T, head H, sector S is located at
          I = S-1 + T*(heads*sectorsPerTrack) + H*sectorsPerTrack

  • MS-DOS Floppy Disk Organization:
    1. Reserved Region (Boot Sector)
    2. FAT Region
    3. Root Directory Region
    4. File and Directory Data Region

  • Snapshots captured from khexedit:
    • The boot sector:
    • First sector in the first FAT:
    • The root directory:
    • The directory named "dir1":
    • The file named "file1":


  • How to calculate the logical sector number of a sub-directory?
    1. Take the Starting cluster number at 0x1A of the directory entry
    2. offset = (31 + starting_cluster_number) * bytesPerSector
    3. 31 = 1 (boot sector) + 18 (2 FATs, 9 sectors each) + 14 (224 root directory entries, 32 bytes each) - 2 (logical sector 33 correspond to FAT cluster 2)

Important System Calls
  1. fd = open("floppy.img", O_RDWR);
  2. dest = lseek(fd, sector_number * bytesPerSector, SEEK_SET);
  3. len = read(fd, buffer, bytesPerSector);
  4. len = write(fd, buffer, bytesPerSector);

Resources
  1. Lab manual: p.179-204
  2. KDE hex editor: /usr/bin/khexedit
  3. FAT32 File System Specification
  4. Cylinder-Head-Sector from Wikipedia