FILE SYSTEMS
example to show effect on read-write time of how a file is stored on a disk
- disk has seek time of 10 milliseconds
- disk spins at 6000 revolutions per minute,
100 revolutions a second,
10 milliseconds per revolution
- 512 bytes per sector
- 2048 sectors per track,
512*2048 = 1048576 bytes per track
- time to RW one whole track is 10 ms,
time to RW one sector is 10/2048 ~= 5 microseconds or 0.005 ms,
IO rate is 100 megabytes per second
- time to RW a random sector = seek time + rotational delay + transfer
time = 10 ms + 5 ms + 5 micros ~= 15 ms
- time to RW a 1 megabyte file scattered in 2048 sectors is 2048 * 15 ms
~= 30 seconds!
- time to RW a 1 megabyte file stored contiguously in one track =
seek time + rotational delay + transfer time = 10 ms + 5 ms + 10ms =
25 ms, less than one thousandth of the scattered RW
IO software layers
- application or user process
- OS
- file system manager, device independent part:
user interface to the file system
- handles system calls (software interrupts)
- groups 2n consecutive sectors on a storage device
into a logical block
- checks permissions (protection) on file access
- translates file name into device and list of sector numbers
or logical block numbers involved
- buffering (buffer cache)
- creates and manages tables of which sectors or logical blocks
each file is stored in
- keeps track of free sectors or logical blocks (free list)
- sends sector numbers to device driver
- file system manager, device dependent part:
device drivers that handle device details
- read and write device controller registers
- hardware interrupt handlers
- hardware controllers: command, status, and data registers
system calls:
open, close, read, write, change attributes such as permissions,
create, delete
logical block size (how many consecutive sectors are grouped into a logical
block) has similar tradeoffs as page size tradeoffs
- internal fragmentation
- table size
- number of seeks
user view of file systems (features)
- file names: number of characters and legal characters
- file types
- regular
- directory
- named pipe (fifo)
- symbolic link (shortcut)
- character special: /dev/tty0, /dev/lp0
- block special: /dev/fd0, /dev/hda1
- attributes
- permissions
- owner
- current size
- last access time, last modification time
- number of hard links to the file
- logical block numbers the file is stored in
- file operations
- create, delete, open, close, read, write, append, seek, get or
set attributes, rename, move (to another directory)
- open: find disk where file is, copy file attributes from disk
to RAM, check permissions against access requested
- close: flush buffers, update changed attributes on disk
- directory: special kind (type) of file that holds file and subdirectory
names, directories form a hierarchy (tree)
- absolute path, relative path
- directory operations: create, delete, opendir, closedir, readdir,
rename, move (to another directory), link (add name to directory),
unlink (remove name from directory)
system view of file system (implementation)
contiguous allocation
- directory entry is pair (name, first logical block number)
plus other attributes like file size
- very efficient sequential IO (one seek)
- disk external fragmentation major problem
- hole list, next fit
- good for read-only file systems like CD-ROMs
- compaction takes hours
- preallocate space so file can grow some without being copied into
larger hole
- random IO is efficient
Example
linked list
- directory entry is pair (name, first logical block number)
plus other attributes like file size
- no external fragmentation like paging
- sequential IO: lots of seeks
- random IO is inefficient (slow): must read file's disk blocks
starting at the beginning
MS-DOS FAT 16 and FAT 32
- read FAT from disk into RAM at boot time
- directory entry is pair (name, first logical block number)
plus other attributes like file size
- first logical block number is also entry (index number) in FAT
whose contents is second logical block number of the file,
second ... third ...
- no external fragmentation
- sequential IO: lots of seeks
- random IO is okay: chase through FAT in RAM but no need to read
disk blocks from file's beginning
- FAT 16 has up to 216 entries forcing 32 kilobyte logical block
size on 2 gigabyte disks and bad internal fragmentation
- FAT 32 has up to 232 entries so 4096 logical block size still
possible on disks larger than 2 gigabytes
Example
UNIX, Linux i-nodes
- each file has an i-node stored on the disk
- directory entry is pair (name, i-node number)
where other attributes like file size are in the i-node itself
- no external fragmentation
- i-node contains file's attributes: type, size, owner, permissions,
last access time, last modification time, link count, 10 direct
logical block numbers, single indirect logical block number,
double indirect logical block number,
triple indirect logical block number
Example
free list
- bit map
- linked list
- linked list where nodes are filled with free block numbers
directories
- MS-DOS directory entries contain file attributes
- UNIX, Linux directory entries do not (the i-node does)
buffer cache: recently used disk blocks, least recently used algorithm
hard and soft links
- soft links are like shortcuts:
a file whose contents is a path to another file
- a hard link is a (name, i-node number) directory entry in UNIX, Linux:
the same i-node number can appear several times in the same directory
or different directories
- removing the last hard link means expunging file and its contents
(but not before last hard link is removed)
- removing a file means soft links to it have no target any more
- removing a soft link has no effect on the target file
disk partitions
- MBR (master boor record) followed by one or more partitions
- MBR contains partition table and active partition
- types: primary, extended
- up to 4 primary partitions allowed
- or one primary partition, and one extended partition containing
one or more logical partitions
- active partition is from where to boot by default
- Linux installs a boot loader to let you choose which partition
to boot
partition containing a DOS file system
- boot sector
- FAT
- backup FAT
- root directory
- free and allocated logical blocks kept track of with FAT
partition containing a UNIX, Linux file system
- boot sector
- super block: number of i-nodes, number of disk blocks, logical
block size, type of free list and pointer to it
- free block bit map or linked list head
- all i-nodes, packed into disk consecutive disk blocks
- root directory
- data blocks for files and directories, some free and some allocated
``defragment'' really means ``descatter'' or store files in contiguous logical
blocks with all free blocks at disk end, there is no external fragmentation,
only way to decrease internal fragmentation is to reduce logical block size
low-level format, high-level format, DOS format command,
UNIX mkfs command, make empty file system
home page:
http://elvis.rowan.edu/~hartley/index.html
e-mail:
hartley@elvis.rowan.edu