FileSystem Structure File structure Logical storage unit Collection

  • Slides: 16
Download presentation
File-System Structure • File structure – Logical storage unit – Collection of related information

File-System Structure • File structure – Logical storage unit – Collection of related information • File system resides on secondary storage (disks). Each file system on a separate disk partition. • File control block – storage structure consisting of information about a file. • OSes use different allocation methods – An allocation method refers to how disk blocks are allocated for files: T Contiguous allocation T Linked allocation T Indexed allocation Operating System Concepts 10. 1 Silberschatz and Galvin revised by Wiseman

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

Contiguous Allocation • • Each file occupies a set of contiguous blocks on the disk. • • Random access. Simple – only starting location (block #) and length (number of blocks) are required. Wasteful of space (dynamic storage-allocation problem). Files cannot grow. Non of the common OSes uses this method. Operating System Concepts 10. 2 Silberschatz and Galvin revised by Wiseman

Contiguous Allocation of Disk Space Operating System Concepts 10. 3 Silberschatz and Galvin revised

Contiguous Allocation of Disk Space Operating System Concepts 10. 3 Silberschatz and Galvin revised by Wiseman

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

Linked Allocation • Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk. • • • Each block contains data and a pointer to the next block. Simple - needs only starting address Free-space management system - no waste of space. No random access. File-allocation table (FAT) - disk-space allocation used by MSDOS and OS/2 employs this method. Operating System Concepts 10. 4 Silberschatz and Galvin revised by Wiseman

Linked Allocation Operating System Concepts 10. 5 Silberschatz and Galvin revised by Wiseman

Linked Allocation Operating System Concepts 10. 5 Silberschatz and Galvin revised by Wiseman

File-Allocation Table Operating System Concepts 10. 6 Silberschatz and Galvin revised by Wiseman

File-Allocation Table Operating System Concepts 10. 6 Silberschatz and Galvin revised by Wiseman

Indexed Allocation • • Brings all pointers together into the index block. Needs an

Indexed Allocation • • Brings all pointers together into the index block. Needs an index table. Random access. Dynamic access without external fragmentation, but has overhead of index block. Operating System Concepts 10. 7 Silberschatz and Galvin revised by Wiseman

Indexed Allocation (Cont. ) Operating System Concepts 10. 8 Silberschatz and Galvin revised by

Indexed Allocation (Cont. ) Operating System Concepts 10. 8 Silberschatz and Galvin revised by Wiseman

Two-level index outer-index table Operating System Concepts 10. 9 file Silberschatz and Galvin revised

Two-level index outer-index table Operating System Concepts 10. 9 file Silberschatz and Galvin revised by Wiseman

UNIX File System (UFS) Operating System Concepts 10. 10 Silberschatz and Galvin revised by

UNIX File System (UFS) Operating System Concepts 10. 10 Silberschatz and Galvin revised by Wiseman

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

Free-Space Management • Bit vector (n blocks) 0 1 2 n-1 … bit[i] = • 0 block[i] free 1 block[i] occupied Bit map requires extra space, but usually a small one. Example: block size = 212 bytes disk size = 230 bytes (1 gigabyte) n = 230/212 = 218 bits (or 32 K bytes) • Easy to get contiguous files. Operating System Concepts 10. 11 Silberschatz and Galvin revised by Wiseman

Linked list (free list) • • Each freed block contains a pointer to the

Linked list (free list) • • Each freed block contains a pointer to the next free block. • • Cannot get contiguous space easily. No need for space of the bit vector, but needs a space for the pointers. (FAT anyway has a space for a pointer in each block) Error in one pointer can be crucial. Operating System Concepts 10. 12 Silberschatz and Galvin revised by Wiseman

Linked list (Cont. ) Operating System Concepts 10. 13 Silberschatz and Galvin revised by

Linked list (Cont. ) Operating System Concepts 10. 13 Silberschatz and Galvin revised by Wiseman

Buffer Cache • • Separate section of main memory for frequently used blocks. Memory-mapped

Buffer Cache • • Separate section of main memory for frequently used blocks. Memory-mapped I/O uses Buffer Cache. Operating System Concepts 10. 14 Silberschatz and Galvin revised by Wiseman

Recovery • If computer is shut down abruptly, buffer cache may not be flashed

Recovery • If computer is shut down abruptly, buffer cache may not be flashed into the disk The disk may have some inconsistencies. • Consistency checking – compares data in directory structure with data blocks on disk, and tries to fix inconsistencies. E. g. try to find blocks which are not free, but do not belonged to any file. • scandisk on Windows and fsck on UNIX can try to automatically fix such inconsistencies. Operating System Concepts 10. 15 Silberschatz and Galvin revised by Wiseman

Journaling • Journaling File System (or Log structured File Systems) records each update to

Journaling • Journaling File System (or Log structured File Systems) records each update to the file system as a transaction. • All transactions are written to a log. The log is on the disk. A transaction is considered committed once it is written to the log. However, the file system may not be updated yet. • The transactions in the log are asynchronously written to the file system. When the file system is modified, the transaction is removed from the log. • If the file system crashes, all remaining transactions in the log must still be performed. Operating System Concepts 10. 16 Silberschatz and Galvin revised by Wiseman