Presentation is loading. Please wait.

Presentation is loading. Please wait.

File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File.

Similar presentations


Presentation on theme: "File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File."— Presentation transcript:

1 File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File system organized into layers. §File control block – storage structure consisting of information about a file.

2 File System Mounting §A file system must be mounted before it is available to use. l The OS is given the name of the device and the location within the file structure at which to attach the file system. l The OS verifies that the device contains a valid file system. l The OS notes in its directory structure that a file system is mounted at the specified mount point.

3 Allocation Methods §Three major methods of allocating disk space are in wide use: l Contiguous l Linked l Indexed

4 Contiguous Allocation §Each file occupies a set of contiguous blocks on the disk. §Simple – only the starting location (block #) and its length (number of blocks) are required. §Random access is fairly easy. §Wasteful of space (dynamic storage allocation problem).

5 Contiguous Allocation (cont) §Files cannot grow. §Mapping from logical to physical. l Block to be accessed = Q + starting address l Displacement into block = R LA/512 Q R

6 Linked Allocation §Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk. pointer block =

7 Linked Allocation (cont) §Allocate as needed, link together; e.g., file starts at block 9

8 Linked Allocation (cont) §Simple – needs only a starting address. §Free space management system – no waste of space. §No random access.

9 Linked Allocation (cont) §Mapping l Block to be accessed is the Qth block in the linked list of blocks representing the file. l Displacement into block = R + 1 §File allocation table (FAT) – disk space allocation used by MSDOS and OS/2 l Contains one entry for each disk block. l Use much like the linked list; contains pointers. LA/511 Q R

10 Indexed Allocation §Brings all pointers together into the index block. §Logical view. index table

11 Example of Indexed Allocation

12 Indexed Allocation (cont) §Need index table. §Random access is possible. §Dynamic access without external fragmentation, but have overhead of index block.

13 Indexed Allocation (cont) §Mapping from logical to physical in a file of maximum size of 256K words and block size of 512 words. We need only 1 block for index table. l Q = displacement into index table l R = displacement into block LA/512 Q R

14 Indexed Allocation – Mapping §Mapping from logical to physical in a file of unbounded length (block size of 512 words). §Linked scheme – Link blocks of index table (no limit on size).

15 Indexed Allocation – Mapping (cont) l Q 1 = block of index table l R 1 is used as follows: l Q 2 = displacement into block of index table l R 2 = displacement into block of file LA / (512 x 511) Q1Q1 R1R1 R 1 / 512 Q2Q2 R2R2

16 Indexed Allocation – Mapping (cont) §Two-level index (maximum file size is 512 3 ) l Q 1 = displacement into outer index l R 1 is used as follows: l Q 2 = displacement into block of index table l R 2 = displacement into block of file LA / (512 x 512) Q1Q1 R1R1 R 1 / 512 Q2Q2 R2R2

17 Indexed Allocation – Mapping (cont)  outer-index index table file

18 Combined Scheme: UNIX (4K bytes per block)

19 Free Space Management §Bit vector (n blocks) §Block number calculation … 012n-1 bit[i] = 0  block[i] free 1  block[i] occupied (number of bits per word)  (number of 0-value words) + offset of first 1 bit

20 Free Space Management (cont) §Bit map requires extra space. Example: block size = 2 12 bytes disk size = 2 30 bytes (1 gigabyte) n = 2 30 /2 12 = 2 18 bits (or 32K bytes) §Easy to get contiguous files

21 Free Space Management (cont) §Linked list (free list) l Cannot get contiguous space easily. l No waste of space. §Grouping l Store the addresses of n free blocks into the first free block. §Counting l Maintain address of block and the number of contiguous blocks that are free.

22 Free Space Management (cont) §Need to protect: l Pointer to free list l Bit map Must be kept on disk Copy in memory and disk may differ. Cannot allow for block[i] to have a situation where bit[i] = 1 in memory and bit[i] = 0 on disk. l Solution: Set bit[i] = 1 in disk. Allocate block[i] Set bit[i] = 1 in memory

23 Directory Implementation §Linear list of file names with pointer to the data blocks. l Simple to program. l Time-consuming to execute. §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. l Fixed size of hash table is a problem.

24 Efficiency and Performance §Efficiency dependent on: l Disk allocation and directory algorithms. l Types of data kept in file’s directory entry. §Performance l Disk cache – separate section of main memory for frequently used blocks. l Free-behind and read-ahead – techniques to optimize sequential access. l Improve PC performance by dedicating section of memory as virtual disk, or RAM disk.

25 Various Disk-Caching Locations

26 Recovery §Consistency checker – compares data in directory structure with data blocks on disk and tries to fix inconsistencies. §Use system programs to back up data from disk to another storage device (floppy disk, magnetic tape). §Recover lost file or disk by restoring data from backup.


Download ppt "File System Structure §File structure l Logical storage unit l Collection of related information §File system resides on secondary storage (disks). §File."

Similar presentations


Ads by Google