File System Implementation Operating System Concepts 8 th

  • Slides: 30
Download presentation
File System Implementation Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne

File System Implementation Operating System Concepts – 8 th Edition Silberschatz, Galvin and Gagne © 2009

File System Implementation: Objectives n File-System Structure l File-System l Directory Implementation n Allocation

File System Implementation: Objectives n File-System Structure l File-System l Directory Implementation n Allocation Methods l Free-Space Management n Recovery from failure n Remote file access: NFS Operating System Concepts – 8 th Edition 11. 2 Silberschatz, Galvin and Gagne © 2009

Layered File System Operating System Concepts – 8 th Edition 11. 3 Silberschatz, Galvin

Layered File System Operating System Concepts – 8 th Edition 11. 3 Silberschatz, Galvin and Gagne © 2009

File-System Implementation n Boot control block contains info needed by system to boot OS

File-System Implementation n Boot control block contains info needed by system to boot OS from that volume n Volume control block contains volume details n Directory structure organizes the files n Per-file File Control Block (FCB) contains many details about the file Operating System Concepts – 8 th Edition 11. 4 Silberschatz, Galvin and Gagne © 2009

A Typical File Control Block Operating System Concepts – 8 th Edition 11. 5

A Typical File Control Block Operating System Concepts – 8 th Edition 11. 5 Silberschatz, Galvin and Gagne © 2009

In-Memory File System Structures Operating System Concepts – 8 th Edition 11. 6 Silberschatz,

In-Memory File System Structures Operating System Concepts – 8 th Edition 11. 6 Silberschatz, Galvin and Gagne © 2009

Virtual File Systems n Virtual File Systems (VFS) provide an object- oriented way of

Virtual File Systems n Virtual File Systems (VFS) provide an object- oriented way of implementing file systems. n VFS allows the same system call interface (the API) to be used for different types of file systems. n The API is to the VFS interface, rather than any specific type of file system. Operating System Concepts – 8 th Edition 11. 7 Silberschatz, Galvin and Gagne © 2009

Schematic View of Virtual File System Operating System Concepts – 8 th Edition 11.

Schematic View of Virtual File System Operating System Concepts – 8 th Edition 11. 8 Silberschatz, Galvin and Gagne © 2009

Directory Implementation n Linear list of file names with pointer to the data blocks.

Directory Implementation n Linear list of file names with pointer to the data blocks. l simple to program l time-consuming to execute n Hash Table – linear list with hash data structure. l decreases directory search time l collisions – situations where two file names hash to the same location Operating System Concepts – 8 th Edition 11. 9 Silberschatz, Galvin and Gagne © 2009

Allocation Methods n An allocation method refers to how disk blocks are allocated for

Allocation Methods n An allocation method refers to how disk blocks are allocated for files: n Contiguous allocation n Linked allocation n Indexed allocation Operating System Concepts – 8 th Edition 11. 10 Silberschatz, Galvin and Gagne © 2009

Contiguous Allocation of Disk Space Operating System Concepts – 8 th Edition 11. 11

Contiguous Allocation of Disk Space Operating System Concepts – 8 th Edition 11. 11 Silberschatz, Galvin and Gagne © 2009

Contiguous Allocation n Each file occupies a set of contiguous blocks on the disk

Contiguous Allocation n Each file occupies a set of contiguous blocks on the disk n Advantages: l Simple – only starting location (block #) and length (number of blocks) are required l Fast Random access n Disadvantages: l Not easy to grow files. l Wasteful of space (e. g. external fragmentation) Operating System Concepts – 8 th Edition 11. 12 Silberschatz, Galvin and Gagne © 2009

Linked Allocation n Each file is a linked list of disk blocks: blocks may

Linked Allocation n Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk. block = pointer Operating System Concepts – 8 th Edition 11. 13 Silberschatz, Galvin and Gagne © 2009

MS-DOS: File-Allocation Table Operating System Concepts – 8 th Edition 11. 14 Silberschatz, Galvin

MS-DOS: File-Allocation Table Operating System Concepts – 8 th Edition 11. 14 Silberschatz, Galvin and Gagne © 2009

Linked Allocation (Cont. ) n Advantages l Simple – need only starting address l

Linked Allocation (Cont. ) n Advantages l Simple – need only starting address l Free-space management system – no waste of space n Disadvantages: l No random access n Logical address mapping Q-th block LA/511 R - offset Block to be accessed is the Qth block in the linked chain of blocks representing the file. Displacement into block = R + 1 Operating System Concepts – 8 th Edition 11. 15 Silberschatz, Galvin and Gagne © 2009

Indexed Allocation n Brings all pointers together into the index block n Logical view

Indexed Allocation n Brings all pointers together into the index block n Logical view index table Operating System Concepts – 8 th Edition 11. 16 Silberschatz, Galvin and Gagne © 2009

Example of Indexed Allocation Operating System Concepts – 8 th Edition 11. 17 Silberschatz,

Example of Indexed Allocation Operating System Concepts – 8 th Edition 11. 17 Silberschatz, Galvin and Gagne © 2009

Indexed Allocation (Cont. ) n Advantages Support dynamic random access l No external fragmentation.

Indexed Allocation (Cont. ) n Advantages Support dynamic random access l No external fragmentation. l n Disadvantages: l Space overhead to store index blocks n Mapping from logical to physical in a file of maximum size of 256 K words and block size of 512 words. We need only 1 block for index table Q LA/512 R Q = displacement into index table R = offset within a block Operating System Concepts – 8 th Edition 11. 18 Silberschatz, Galvin and Gagne © 2009

Indexed Allocation – Mapping (Cont. ) outer-index table Operating System Concepts – 8 th

Indexed Allocation – Mapping (Cont. ) outer-index table Operating System Concepts – 8 th Edition 11. 19 file Silberschatz, Galvin and Gagne © 2009

Indexed Allocation – Mapping (Cont. ) n Two-level index (maximum file size is 5123

Indexed Allocation – Mapping (Cont. ) n Two-level index (maximum file size is 5123 words) Q 1 LA / (512 x 512) R 1 Q 1 = displacement into outer-index R 1 is used as follows: Q 2 R 1 / 512 R 2 Q 2 = displacement into block of index table R 2 displacement into block of file: Operating System Concepts – 8 th Edition 11. 20 Silberschatz, Galvin and Gagne © 2009

Combined Scheme: UNIX UFS (4 K bytes per block) Operating System Concepts – 8

Combined Scheme: UNIX UFS (4 K bytes per block) Operating System Concepts – 8 th Edition 11. 21 Silberschatz, Galvin and Gagne © 2009

Free-Space Management n Bit vector (n blocks) 0 1 2 n-1 … bit[i] =

Free-Space Management n Bit vector (n blocks) 0 1 2 n-1 … bit[i] = 0 block[i] free 1 block[i] occupied Block number calculation (number of bits per word) * (number of 0 -value words) + offset of first 1 bit Operating System Concepts – 8 th Edition 11. 22 Silberschatz, Galvin and Gagne © 2009

Free-Space Management (Cont. ) n Bit map requires extra space l Example: block size

Free-Space Management (Cont. ) n Bit map requires extra space l Example: block size = 212 bytes disk size = 230 bytes (1 gigabyte) n = 230/212 = 218 bits (or 32 K bytes) n Linked list (free list) l Advantages: 4 Do not need contiguous space 4 No waste of space Operating System Concepts – 8 th Edition 11. 23 Silberschatz, Galvin and Gagne © 2009

Performance n disk cache – separate section of main memory for frequently used blocks

Performance n disk cache – separate section of main memory for frequently used blocks n free-behind and read-ahead – techniques to optimize sequential access n improve PC performance by dedicating section of memory as virtual disk, or RAM disk Operating System Concepts – 8 th Edition 11. 24 Silberschatz, Galvin and Gagne © 2009

I/O Using a Unified Buffer Cache Operating System Concepts – 8 th Edition 11.

I/O Using a Unified Buffer Cache Operating System Concepts – 8 th Edition 11. 26 Silberschatz, Galvin and Gagne © 2009

Recovery n Consistency checking – compares data in directory structure with data blocks on

Recovery n Consistency checking – compares data in directory structure with data blocks on disk, and tries to fix inconsistencies n Use system programs to back up data from disk to another storage device n Recover lost file or disk by restoring data from backup Operating System Concepts – 8 th Edition 11. 27 Silberschatz, Galvin and Gagne © 2009

Log Structured File Systems n Log structured file systems record each update to the

Log Structured File Systems n Log structured file systems record each update to the file system as a transaction n All transactions are written to a log l l A transaction is considered committed once it is written to the log However, the file system may not yet be updated n The transactions in the log are asynchronously written to the file system l When the file system is modified, the transaction is removed from the log n If the file system crashes, all remaining transactions in the log must still be performed Operating System Concepts – 8 th Edition 11. 28 Silberschatz, Galvin and Gagne © 2009

The Sun Network File System (NFS) n Transparent shared file access among independent machines

The Sun Network File System (NFS) n Transparent shared file access among independent machines and file systems l A remote directory is mounted over a local file system directory 4 The mounted directory looks like an integral subtree of the local file system Operating System Concepts – 8 th Edition 11. 29 Silberschatz, Galvin and Gagne © 2009

Schematic View of NFS Architecture Operating System Concepts – 8 th Edition 11. 30

Schematic View of NFS Architecture Operating System Concepts – 8 th Edition 11. 30 Silberschatz, Galvin and Gagne © 2009

NFS Protocol n Provides a set of remote procedure calls (RPC) for remote file

NFS Protocol n Provides a set of remote procedure calls (RPC) for remote file operations: l searching for a file within a directory l reading a set of directory entries l manipulating links and directories l accessing file attributes l reading and writing files n NFS servers are stateless; each request has to provide a full set of arguments n Modified data must be committed to the server’s disk before results are returned to the client n Support data exchange format conversion using an External Data Representation (XDR) protocol Operating System Concepts – 8 th Edition 11. 31 Silberschatz, Galvin and Gagne © 2009