Brendan Ang

Search

Search IconIcon to open search

File Systems

Last updated Nov 8, 2022 Edit Source

# File Systems

# File

A file is an unstructured sequence of bytes. Each byte is individually addressable from the beginning of the file.

# File access

# Protection

# Data Structures

# File Control Block

400

# Open File Table

open() syscall:

# File Descriptor

A file descriptor is a non-negative integer which indexes into a per-process file descriptor table which is maintained by the kernel. This in turn indexes into a system-wide open file table. It also indexes into the inode table that describes the actual underlying files. All operations are done on the file descriptor

# Storage allocation

File-Organisation Module: allocates storage space for files, translates logical block addresses to physical block addresses, and manages free disk space.

# Contiguous

Each file occupies a set of contiguous blocks on the disk. Advantages:

[! The delete operation] Deleting a data block stored with contiguous allocation requires shifting of the data blocks. e.g. Delete data block 5 in a file with 10 data blocks: i.e. Read block 6, write block 5 with data from block 6, read block 7 and write block 6 with block 7 etc.

# Linked

Each file is a linked list of disk blocks and the blocks may be scattered anywhere on the disk. Advantages:

[! The delete operation] Deleting a data block stored with linked allocation requires an update to the connected pointer. e.g. Delete data block 5 in a file with 10 data blocks: 6 reads to reach block 5. 1 write to update the pointer of block 4 to block 6

# Indexed allocation

Each file has an index block which contains all pointers to the allocated blocks. Directory entry contains the block number of the index block. Similar to a page table for memory allocation. Advantages:

[! The delete operation] Deleting a data block stored with indexed allocation requires an update to the indexed pointers. e.g. Delete data block 5 in a file with 10 data blocks: 1 read for the index block, 4 writes to update pointers

# inode

An inode is an index block. For each file and directory there is an inode. The inode contains file attributes, 12 pointers to direct blocks (data blocks) and 3 pointers point to indirect blocks (index blocks) with 3 levels of indirection. Indirection allows the system to support large file sizes: Using the inode:

# Directories

# Structure

A directory can be structured in two ways:

  1. each entry contains a file name and other attributes
  2. each entry contains a file name and a pointer to another data structure where file attributes can be found

# Tree Structured

Path Name

# Acyclic Graph Directories

The tree structure prohibits sharing of files or directories while an acyclic graph allows this. It is a natural generalisation of the tree structure.

A link is a directory entry which is a poitner to another file or subdirectory

# What happens on deletion?

One possibility is to remove the file whenever anyone deletes it, but this action may leave dangling pointers to the now-nonexistent file. Worse, if the remaining file pointers contain actual disk addresses, and the space is subsequently reused for other files, these dangling pointers may point into the middle of other files. Soft links

# Why not just duplicate the file?

Duplicate directory entries make the original and the copy indistinguishable. A major problem with this is maintaining consistency when a file is modified

# Disk Space Management

Block size affects both data rate and disk space utilisation

# Managing Free Blocks

There is a need to track which blocks are free in order to allocate disk space to files

# Bitmap

Each block is represented by 1 bit, 1 (free) and 0 (allocated) Advantage:

# Linked list

The pointer to the next block is stored in the block itself, hence to read the entire list, each block must be read sequentially requiring substantial I/O time.

# Practice Problems

a. False. Owner and the group which owner belongs to is able to read. b. False. The OFT caches the FCB rather than the data block. c. False. Using linked file allocation, any free data block can be used. a. The previous links will now point to the data of the new file. To avoid this, dangling links need to be cleaned up. b. Single copy

  1. Load inode of usr
  2. Load directory for usr
  3. Load inode for ast
  4. Load directory for ast
  5. Load inode for mbox b. Seek: no disk reads needed Current position is 5900: Logical block 5, byte 900. read(100): 1 disk read by following direct pointer read(200): 2 disk read by following single indirect pointer 3 disk reads total c. Number of pointers in 1 index block = $1000/2=500$ File size supported = $(6+500) \times 1000=506,000B$ File data can be stored across different physical storage blocks. A smaller physical block helps to reduce internal fragmentation as the last block occupied by the file can is only 512B compared to 4KB. Using the larger block size would also help to improve throughput.