You are on page 1of 19

File System Management

Storage Media Magnetic Disks Files and Directories File Implementation Directory Implementation Free Block Management File System Layout Disk Performance Floppy Disks
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Directory Implementation
Before accessing a file, the file must first be opened by the operating system. For that, the OS uses the path name supplied by the user to locate the directory entry. A directory entry provides the name of the file, the information needed to find the blocks of the file, and information about the files attributes.
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Directory Entry
Attribute placement
Directory Implementation

The attributes may be stored a) together with the file name in the directory entry (MS-DOS, VMS) b) or off the directory entry (Unix)
Figure from [Ta01 p.406]
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Directory Entry
MS-DOS directory entry
Directory Implementation
Figure from [Ta01 p.440]

Directory entry size: 32 byte File attributes stored in entry. First block number points to first file block, respectively to the corresponding entry in the FAT (DOS uses chained pointers).
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Directory Entry
Unix directory entry (Unix V7)
Directory Implementation

attributes

directory entry

Entry size: 16 byte.


Modern Unix versions allow for longer file names.

File attributes are stored in the inode. The rest of the inode points to the file blocks
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Directory Entry
MS-DOS file attributes
Directory Implementation
Figure from [Ta01 p.440]

ADVSHR

A : Archive flag D: Directory flag V: Volume label flag

S : System file flag H: Hidden flag R: Read-only flag


Computer Architecture WS 06/07

of file creation

Dr.-Ing. Stefan Freinatis

Directory Implementation
An MS-DOS directory (not the entry) itself is a file (a binary file) with the file type attribute set to directory. The disk blocks pointed to contain other directory entries (each again of 32 byte size) which either depict files or subsequent directories (sub directories). Upon installing an MS-DOS file system, there is automatically created a root directory. Similar applies to Unix. When the file type attribute is set to directory, the file blocks contain directory entries. Windows 2000 and descendants (NTFS) treat directories as entities different from files.
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Directory Implementation
MS-DOS directory
disk block

directory entry

directory entry directory entry directory entry directory entry directory entry

pointing to disk blocks containing directory entries pointing to disk blocks containing file data

...

Legend:

directory entry directory entry

= Directory attribute set = Directory attribute not set. Regular file.


Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

File Lookup
Directory Implementation

How to find a file name in a directory Linear Search


Each directory entry has to be compared against the search name (string compare). Slow for large directories.

Binary Search
Needs a sorted directory (by name). Entering and deleting files requires moving directory entries around in order to keep them sorted (Insertion Sort).

Hash Table
In addition to each file name, an hash value (a number) is created and stored. Search is then done on the hash value, not on the name.

B-tree
File names are nodes and leafs in a balanced tree. NTFS.
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

File Lookup
Figure from [Ta01 p.447]

Directory Implementation

The steps in looking up the file /usr/ast/mbox in classical Unix


Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

File System Management


Storage Media Magnetic Disks Files and Directories File Implementation Directory Implementation Free Block Management File System Layout Disk Performance Floppy Disks
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Free Block Management


To keep track of the blocks available for allocation (free blocks), the operating system must somehow maintain a free block pool. When a file is created, the pool is searched for free blocks. When a file is deleted, the freed blocks are added to the pool. File systems using a FAT do not need a separate free block pool. Free blocks are simply marked in the table by a 0.

Linked List
Free Block Pool Implementations: Free List

Bit Map
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Free Block Management


Linked List
The free blocks form a linked list where each block points to the next one (chained blocks).
Figure from [Sil00 p.388]

Simple Implementation
Only first block number needed.

Quick Access
New blocks are prepended (LIFO principle)

Disk I/O
Updating the pointers involves I/O.

Block Modification
Modified content hinders undelete of the block.
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Free Block Management


Figure from [Ta01 p.413]

Free List
The free block numbers are listed in a table. The table is stored in disk blocks. The table blocks may be linked together.

Space
17 18 0

Each free block requires 4 byte in table

Management
Adding and deleting block numbers needs time, in particular when a table block is almost full (additional disk I/O required).
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Free Block Management


Bit Map
To each existing block on disk a bit is assigned. When a block is free, the bit is set. When the block is occupied, the bit is reset (or vice versa). All bits form a bit map.

Compact
Each block represented by a single bit. Fixed size.

Logical order
Neighboring bits represent neighboring blocks (logical order). Quite easy to find contiguous blocks, or blocks located close together.

Conversion block number bit position


From the block number the corresponding bit position must be calculated and vice versa.
Figure from [Ta01 p.413]
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

File System Management


Storage Media Magnetic Disks Files and Directories File Implementation Directory Implementation Free Block Management File System Layout Disk Performance Floppy Disks
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

File System Layout

File system

Each Partition starts with a boot block (first block) which is followed by the file system. The boot block may be modified by the file system.
Computer Architecture

Figure from [Ta01 p.400], modified


WS 06/07 Dr.-Ing. Stefan Freinatis

File System Layout


Layout of FAT file system
Information about the filesystem location is stored in the boot block.
A copy of the FAT for reliability reasons

FAT

FAT copy

Root dir

Files and directories

Number of entries in root directory is limited, except for FAT-32 where it is a cluster chain.

Microsoft FAT-32 specification at


http://www.microsoft.com/whdc/system/platform/firmware/fatgen.mspx
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

File System Layout


Possible file system layouts for a UNIX file system

Super block

Inodes

Root dir

Files and directories

The inode for the root directory is located at a fixed place. Bit map free block management

Super block

Free block pool

Inodes

Root dir

Files and directories

Information about filesystem (block size, volume label, size of inode list, next free inode, next free block, ...)

Computer Architecture

WS 06/07

Dr.-Ing. Stefan Freinatis

File System Layout


Layout of NTFS file system
Information about the filesystem location is stored in the boot block.
Master File Table. Linear sequence of 1kB records. Each record describes one file or directory. MFT is a file, may be located anywhere on disk.

MFT

System files

File area

Files for storing metadata about the file system. Actually, the MFT itself is a system file.

More about NTFS: http://www.ntfs.com/ntfs_basics.htm


Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

File System Management


Storage Media Magnetic Disks Files and Directories File Implementation Directory Implementation Free Block Management File System Layout Disk Performance Floppy Disks
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Cylinder Skew
Disk Performance

Cylinder skew example


Assumption: Reading from inner tracks towards outer tracks. Here: skew = 3 sectors. After head has moved to next track, sector 0 arrives just in time. Reading can continue right away. Performance improvement when reading multiple tracks.
Physical disk geometry, figure from [Ta01 p.316]
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Disk Scheduling

Disk Performance

Modern disk drives are addressed as large one-dimensional arrays of logical blocks, where the logical block is the smallest unit of transfer. The array of logical blocks is mapped into the sectors of the disk sequentially. Sector 0 is the first sector of the first track on the outermost cylinder. Mapping proceeds in order through that track, then the rest of the tracks in that cylinder, and then through the rest of the cylinders from outermost to innermost. However, it is difficult to convert a logical block into CHS: The disk may have defective sectors which are replaced by spare sectors from elsewhere on the disk. Owing to zone bit recording the number of sectors per track is not the same for all cylinders. After [Sil00 p.436]
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Disk Scheduling

Disk Performance

Fast access desired (high disk bandwidth)


Disk bandwidth is the total number of bytes transferred, divided by the total time from the first request for service until completion of the last transfer.

Bandwidth depends on
Seek time, the time for the disk to move the heads to the
cylinder containing the desired sector.

Rotational latency, the additional time waiting for the disk to


rotate the desired sector to the disk head.

Seek time seek distance. Scheduling goal: minimizing seek time


Scheduling in earlier days done by OS, nowadays by either OS (then guessing the physical disk geometry) or by the integrated disk drive controller.
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Disk Scheduling
Scheduling Algorithms
Disk Performance

First-Come First-Served (FCFS) Shortest Seek Time First (STTF) SCAN C-SCAN C-LOOK
For the following examples: Assumption that there are 200 tracks on a single sided disk. Read requests are queued in some queue. The queue is currently holding the requests for tracks 98, 183, 37, 122, 14, 124, 65 and 67. The head is at track 53.
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

FCFS
Disk Scheduling

track

time

The requests are serviced in the order of their entry (first entry is served first).
Figure from [Sil00 p.437]

Computer Architecture

WS 06/07

Dr.-Ing. Stefan Freinatis

SSTF
Disk Scheduling
track

The next request served is the one that is closest to current position (shortest seek time).
time Figure from [Sil00 p.438]

Computer Architecture

WS 06/07

Dr.-Ing. Stefan Freinatis

SCAN
Disk Scheduling
track

Disk arm starts at one end of the disk and sweeps over to the other end, thereby servicing the requests.
time

At the other end the head reverses direction and servicing continues on the return trip.
Figure from [Sil00 p.439]

Computer Architecture

WS 06/07

Dr.-Ing. Stefan Freinatis

C-SCAN
Disk Scheduling
track

time

Disk arm starts at one end of the disk and sweeps over to the other end, thereby servicing the requests. At the other end the head returns to the beginning of

the disk without servicing on the return trip.


Figure from [Sil00 p.440]

Computer Architecture

WS 06/07

Dr.-Ing. Stefan Freinatis

C-LOOK
Disk Scheduling
track

Like SCAN or C-SCAN, but the head moves only as far as the final request in each direction.
time Figure from [Sil00 p.441]

Computer Architecture

WS 06/07

Dr.-Ing. Stefan Freinatis

Disk Scheduling
Disk Performance

SSTF is common and has a natural appeal SCAN and C-SCAN perform better for systems that place a heavy load on the disk. Performance depends on the number and types of requests. Requests for disk service are influenced by the file allocation method. Either SSTF or LOOK is a reasonable choice as default algorithm.

Computer Architecture

WS 06/07

Dr.-Ing. Stefan Freinatis

File System Management


Storage Media Magnetic Disks Files and Directories File Implementation Directory Implementation Free Block Management File System Layout Disk Performance Floppy Disks
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Floppy Disks
Portable storage media 8 floppy in 1969 5.25 floppy in 1978 3.5 floppy in 1987
Figure from www.computermuseum.li

8 disk Capacity:
80K ... 1.2M

5.25 disk
360k ... 1.2M

3.5 disk
720K, 1.44 MB

Floppy disks almost displaced by Flash Memory (e.g. USB Stick) now, except for the purpose of booting computers (bootable floppies).
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Floppy Disks
4 22 40 Seite 0 0 Page Sektorerkennung BDOS: 2,0,6 42 Sector number BIOS: (CHS) BIOS: 0,2,6 (Seite, Spur, Sektor) BDOS: 42 23 41 5

(Front)

21

39 42 24 6

Page 1(Rckseite) (Back)


Spurnummer Track index (0, 1, 2, ... )

Seite 1

2 20 38

43 37 44 26 8

25

19

45 BIOS 0,0,1 27 9

Two sided floppy disk

Beginn der Spuren Track start

Drehrichtung Rotation direction

Computer Architecture

WS 06/07

Dr.-Ing. Stefan Freinatis

Floppy Disks
4 22 40 Seite 0 0 (Front) Page 3 21 23 41 Sektorerkennung BDOS: 2,0,6 42 Sector number BIOS: (CHS) BIOS: 0,2,6 (Seite, Spur, Sektor) BDOS: 42 5

39 42 24 6

Page 1(Rckseite) (Back)


Spurnummer Track index (0, 1, 2, ... )

Seite 1

20 38 BIOS = 2 Basic Input Output System

Stored in (EP)ROM
43 7 Sector access through invoking a software-interrupt and addressing 37 19 a sector by means of CHS. 1 45 BDOS = Basic Disk Operating System26 44 25

Originates BIOS 0,0,1

8 Higher abstraction level than BIOS. from CP/M 27 operating system. 9

Sector access through invoking a software-interrupt and addressing a sector by means of a logical consecutive sector number (1, 2, ...). Beginn der Spuren Track start Drehrichtung Rotation direction
Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Floppy Disks
Sector Structure
sectors
1 2 3 4 5 6 7 8 9

Address field

Data field

Sync IAM index index index

track head

sector sector length CRC

DAM data bytes ECC


CRC: ECC: IAM: DAM:

128-1024

CRC/ InterRecord Gap

Cyclic Redundancy Check Error Checking/Correction Index Address Mark Data Address Mark

Computer Architecture

WS 06/07

Dr.-Ing. Stefan Freinatis

Floppy Disks
Starting sector numbers for system and data areas (FAT file system). All numbers are in decimal notation.
Disk 360 K 720 K 1.2 M 1.44 M Boot sector FAT 1 1 1 1 1 2 2 2 2 FAT 2 4 5 9 11 Root dir 6 8 16 20 Data 13 15 30 34

Computer Architecture

WS 06/07

Dr.-Ing. Stefan Freinatis

Floppy Disks
Track 0, Page 0
9 1 Dir. 8 Dir. (3) FAT (1) 7 Dir. (2) FAT (2) Dir. (1) 6 FAT (4) 5 FAT (3) 4 15 3 16 Data Data (4) (4) Dir. (7) 2 (4) Bootstrap Bootstrap Loader Data Data (6) (6) Dir. (5)

Track 0, Page 1
18 10

loader

17

Data (5) (5)


Dir. (6) 11

Data

Data Data (3) (3) Data (2)


(2) 14

12

Data

Data Data (1)


(1) 13

Dir. = allocated space for root directory

Track 0 of a 360 kB floppy disk


Computer Architecture WS 06/07 Dr.-Ing. Stefan Freinatis

Spur 0, Seite 1