Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Chapter 4 : File Systems What is a file system? What is a file system? Objectives & user requirements Objectives & user requirements Characteristics.

Similar presentations


Presentation on theme: "1 Chapter 4 : File Systems What is a file system? What is a file system? Objectives & user requirements Objectives & user requirements Characteristics."— Presentation transcript:

1 1 Chapter 4 : File Systems What is a file system? What is a file system? Objectives & user requirements Objectives & user requirements Characteristics of files & directories Characteristics of files & directories File system implementation File system implementation Directory implementation Directory implementation Free blocks management Free blocks management Increasing file system performance Increasing file system performance

2 2 File System The collection of algorithms and data structures which perform the translation from logical file operations (system calls) to actual physical storage of information The collection of algorithms and data structures which perform the translation from logical file operations (system calls) to actual physical storage of information

3 3 Objectives of a File System Provide storage of data and manipulation Provide storage of data and manipulation Guarantee consistency of data and minimise errors Guarantee consistency of data and minimise errors Optimise performance (system and user) Optimise performance (system and user) Eliminate data loss (data destruction) Eliminate data loss (data destruction) Support variety of I/O devices Support variety of I/O devices Provide a standard user interface Provide a standard user interface Support multiple users Support multiple users

4 4 User Requirements Access files using a symbolic name Access files using a symbolic name Capability to create, delete and change files Capability to create, delete and change files Controlled access to system and other users’ files Controlled access to system and other users’ files Control own access rights Control own access rights Capability of restructuring files Capability of restructuring files Capability to move data between files Capability to move data between files Backup and recovery of files Backup and recovery of files

5 5 Files Naming Naming Name formation Name formation Extensions (Some typical extensions are shown below) Extensions (Some typical extensions are shown below)

6 6 Structuring Structuring (a) Byte sequence (as in DOS, Windows & UNIX) (a) Byte sequence (as in DOS, Windows & UNIX) (b) Record sequence (as in old systems) (b) Record sequence (as in old systems) (c) Tree structure (as in some mainframe Oses) (c) Tree structure (as in some mainframe Oses) Files (Cont.)

7 7 File types File types Regular (ASCII, binary) Regular (ASCII, binary) Directories Directories Character special files Character special files Block special files Block special files File access File access Sequential access Sequential access Random access Random access

8 8 Files (Cont.) File attributes File attributes Read, write, execute, archive, hidden, system etc. Read, write, execute, archive, hidden, system etc. Creation, last access, last modification Creation, last access, last modification

9 9 Files (Cont.) File operations File operations 1.Create 2.Delete 3.Open 4.Close 5.Read 6.Write 7.Append 8.Seek 9.Get attributes 10.Set Attributes 11.Rename

10 10 Directories Where to store attributes Where to store attributes In directory entry (DOS, Windows) In directory entry (DOS, Windows) In a separate data structure (UNIX) In a separate data structure (UNIX) Path names Path names Absolute path name Absolute path name Relative path name Relative path name Working (current) directory Working (current) directory Operations Operations Create, delete, rename, open directory, close directory, read directory, link (mount), unlink Create, delete, rename, open directory, close directory, read directory, link (mount), unlink

11 11 Directories & Files (UNIX) d2 f3f2 f1 / d1f4 f5f7 d3 d4d5d6 f6 Disk A Disk B Root Directory Linked Branch Working Directory Working directory : d2 Working directory : d2 Absolute path to file f2 : /d1/d2/f2 Absolute path to file f2 : /d1/d2/f2 Relative path to file f2 : f2 Relative path to file f2 : f2

12 12 Physical Disk Space Management Heads Cylinder Each plate is composed of sectors or physical blocks which are laid along concentric tracks Each plate is composed of sectors or physical blocks which are laid along concentric tracks Sectors are at least 512 bytes in size Sectors are at least 512 bytes in size Sectors under the head and accessed without a head movement form a cylinder Sectors under the head and accessed without a head movement form a cylinder Sector Track

13 13 File System Implementation Contiguous allocation Contiguous allocation Linked list allocation Linked list allocation Linked list allocation using an index (DOS file allocation table - FAT) Linked list allocation using an index (DOS file allocation table - FAT) i-nodes (UNIX) i-nodes (UNIX)

14 14 Contiguous Allocation The file is stored as a contiguous block of data allocated at file creation The file is stored as a contiguous block of data allocated at file creation (a) Contiguous allocation of disk space for 7 files (b) State of the disk after files D and E have been removed

15 15 Contiguous Allocation (Cont.) FAT (file allocation table) contains file name, start block, length FAT (file allocation table) contains file name, start block, length Advantages Advantages Simple to implement (start block & length is enough to define a file) Simple to implement (start block & length is enough to define a file) Fast access as blocks follow each other Fast access as blocks follow each other Disadvantages Disadvantages Fragmentation Fragmentation Re-allocation (compaction) Re-allocation (compaction)

16 16 Linked List Allocation The file is stored as a linked list of blocks The file is stored as a linked list of blocks

17 17 Linked List Allocation (Cont.) Each block contains a pointer to the next block Each block contains a pointer to the next block FAT (file allocation table) contains file name, first block address FAT (file allocation table) contains file name, first block address Advantages Advantages Fragmentation is eliminated Fragmentation is eliminated Block size is not a power of 2 because of pointer space Block size is not a power of 2 because of pointer space Disadvantages Disadvantages Random access is very slow as links have to be followed Random access is very slow as links have to be followed

18 18 Linked list allocation using an index (DOS FAT) Disk size EOF 1 Free 5 7 Bad Free … FAT (File allocation table) File blocks n First block address is in directory entry

19 19 Linked list allocation using an index (Cont.) The DOS (Windows) FAT is arranged this way The DOS (Windows) FAT is arranged this way All block pointers are in FAT so that don’t take up space in actual block All block pointers are in FAT so that don’t take up space in actual block Random access is faster since FAT is always in memory Random access is faster since FAT is always in memory 16-bit DOS FAT length is ( )*2 = bytes 16-bit DOS FAT length is ( )*2 = bytes

20 20 Problem 16-bit DOS FAT can only accommodate pointers (ie., a maximum of 64 MB disk) 16-bit DOS FAT can only accommodate pointers (ie., a maximum of 64 MB disk) How can we handle large disks such as a 4 GB disk? How can we handle large disks such as a 4 GB disk?

21 21 i (index)-nodes (UNIX) File mode Number of links UID GID File size Time created Time last accessed Time last modified 10 disk block numbers Single indirect block Triple indirect block Double indirect block Indirect blocksData blocks

22 22 i-nodes (Cont.) Assume each block is 1 KB in size and 32 bits (4 bytes) are used as block numbers Assume each block is 1 KB in size and 32 bits (4 bytes) are used as block numbers Each indirect block holds 256 block numbers Each indirect block holds 256 block numbers First 10 blocks: file size <= 10 KB First 10 blocks: file size <= 10 KB Single indirect: file size <= = 266 KB Single indirect: file size <= = 266 KB Double indirect: file size <= 256* = KB = MB Double indirect: file size <= 256* = KB = MB Triple indirect: file size <= 256*256* = KB = ~16 GB Triple indirect: file size <= 256*256* = KB = ~16 GB

23 23 Directory Implementation DOS (Windows) directory structure DOS (Windows) directory structure UNIX directory structure UNIX directory structure

24 24 DOS (Windows) Directory Structure (32 bytes) File nameExtAReservedTPDSize 8 bytes Attributes (A,D,V,S,H,R) Time of creation Date of creation Pointer to first data block

25 25 UNIX Directory Structure (16 bytes) I-node #File name 2 bytes14 bytes

26 26 The Windows 98 Directory Structure Extended MS DOS Directory Entry An entry for (part of) a long file name

27 27 The Windows 98 Directory Structure An example of how a long name is stored in Windows 98

28 28 Path Name Lookup : /usr/ast/mbox 245 Root (/) i-node bin 7dev 14lib 9etc 6usr Root directory file block i-node 6 of /usr prog 30stu 51html 26ast 45genc /usr directory file block i-node 26 of /usr/ast mbox 92books 81src /usr/ast directory file block 406 i-node 60 of /usr/ast/mbox Blocks of file

29 29 Two ways of handling long file names in a Directory In-line In a heap

30 30 Shared Files File f2 is shared by two paths (users!) and there is one physical copy. File f2 is shared by two paths (users!) and there is one physical copy. The directories d1 & d2 point to the same i-node with link count equal to 2 The directories d1 & d2 point to the same i-node with link count equal to 2 Deletion is done by decrementing the link count. When it reaches zero the file is deleted physically Deletion is done by decrementing the link count. When it reaches zero the file is deleted physically / d1 d2 f1f2f3

31 31 Disk Space Management Dark line (left hand scale) gives data rate of a disk Dark line (left hand scale) gives data rate of a disk Dotted line (right hand scale) gives disk space efficiency Dotted line (right hand scale) gives disk space efficiency All files 2KB All files 2KB Block size

32 32 How to Keep Track of Free Disk Blocks Linked list of disk blocks Linked list of disk blocks Bit maps Bit maps Indexing as used in DOS FAT Indexing as used in DOS FAT

33 33 Linked List of Disk Blocks Allocation is simple. Delete block number from free blocks list

34 34 Bit Maps The bit map is implemented by reserving a bit string whose length equals the number of blocks The bit map is implemented by reserving a bit string whose length equals the number of blocks A ‘1’ may indicate that the block is used and ‘0’ for free blocks A ‘1’ may indicate that the block is used and ‘0’ for free blocks If the disk is nearly full then the bit map method may not be as fast as the linked list method If the disk is nearly full then the bit map method may not be as fast as the linked list method

35 35 Increasing File System Performance Disks (floopies, hard disks, CD ROMS) are still slow when compared to the memory Disks (floopies, hard disks, CD ROMS) are still slow when compared to the memory Use of a memory cache may speed the disk transfers between disk and process Use of a memory cache may speed the disk transfers between disk and process Blocks are read into the cache first. Subsequent accesses are through the cache Blocks are read into the cache first. Subsequent accesses are through the cache Blocks are swapped in & out using replacement algorithms such as FIFO, LRU Blocks are swapped in & out using replacement algorithms such as FIFO, LRU System crashes may cause data loss if modified blocks are not written back to disk System crashes may cause data loss if modified blocks are not written back to disk

36 36 Where to Put the Current “File Position” Field The file position field is a 16 or 32 bit variable which holds the address of the next byte to be read or written in a file The file position field is a 16 or 32 bit variable which holds the address of the next byte to be read or written in a file Put it in the i-node Put it in the i-node Put it in process table Put it in process table

37 37 File Position Field in i-node If two or more processes share the same file, then they must have a different file position If two or more processes share the same file, then they must have a different file position Since i-node is unique for a file, the file position can not be put in the i-node Since i-node is unique for a file, the file position can not be put in the i-node

38 38 File Position Field in Process Table When a process forks, both the parent and the child must have the same file position When a process forks, both the parent and the child must have the same file position Since the parent and the child have different process tables they can not share the same file position Since the parent and the child have different process tables they can not share the same file position So, we can not put in process table So, we can not put in process table

39 39 Solution Use an intermediate table for file positions Use an intermediate table for file positions parent child Process tables position File positions table i-node of file


Download ppt "1 Chapter 4 : File Systems What is a file system? What is a file system? Objectives & user requirements Objectives & user requirements Characteristics."

Similar presentations


Ads by Google