file systems
DESCRIPTION
File Systems. 6.1 Files 6.2 Directories 6.3 File system implementation 6.4 Example file systems. Chapter 6. Long-term Information Storage. Must store large amounts of data Information stored must survive the termination of the process using it - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/1.jpg)
1
File Systems
Chapter 6
6.1 Files 6.2 Directories 6.3 File system implementation 6.4 Example file systems
![Page 2: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/2.jpg)
2
Long-term Information Storage
1. Must store large amounts of data
2. Information stored must survive the termination of the process using it
3. Multiple processes must be able to access the information concurrently. In short:
![Page 3: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/3.jpg)
3
Long-term Information Storage
Files: Good!
No Files: Bad!
![Page 4: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/4.jpg)
4
File Naming
Typical file extensions.
![Page 5: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/5.jpg)
5
File Structure
• Three kinds of files– byte sequence– record sequence– tree
![Page 6: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/6.jpg)
6
File Types: Text and Binary
(a) An executable file (b) An archive
![Page 7: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/7.jpg)
7
File Access• Sequential access
– read all bytes/records from the beginning– cannot jump around, could rewind or back up– convenient when medium was mag tape
• Random access– bytes/records read in any order– essential for data base systems– read can be …
• move file marker (seek), then read or …
• read and then move file marker
![Page 8: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/8.jpg)
8
File Attributes
Possible file attributes
![Page 9: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/9.jpg)
9
Example
Assume all counters are currently 0.
Consider the case when pages 0,2,4, and 5 are referenced between last interrupt.
![Page 10: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/10.jpg)
10
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
![Page 11: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/11.jpg)
11
• -rwxr-xr-x 1 dickens spcprj 20580000 Nov 16 2003 BM.Contention.Big• -rw-r--r-- 1 dickens spcprj 5832 Nov 14 2003 LR.Contention.Low• -rwxr-xr-x 1 dickens spcprj 5180000 Nov 14 2003 bitmap.contention.1• -rwxr-xr-x 1 dickens spcprj 12434 Nov 14 2003 Companion.4• -rw-r--r-- 1 dickens spcprj 2767 Nov 14 2003 temp.Swap• -rw-r--r-- 1 dickens spcp 2767 Nov 14 2003 temp• -rwxr-xr-x 1 dickens spc 16969 Nov 14 2003 ind_calc• -rw-r--r-- 1 dickens spcprj 1217 Nov 14 2003 Temp_File.contention
![Page 12: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/12.jpg)
12
An Example Program Using File System Calls (1/2)
![Page 13: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/13.jpg)
13
An Example Program Using File System Calls (2/2)
![Page 14: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/14.jpg)
14
Memory Mapped Files
• Use system calls like: – map (filename, starting address, size);
– unmap (filename, starting address, size) ;
• Implemented through paging mechanism.
• Advantages of this: ?
![Page 15: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/15.jpg)
15
DirectoriesSingle-Level Directory Systems
• A single level directory system– contains 4 files– owned by 3 different people, A, B, and C
![Page 16: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/16.jpg)
16
Two-level Directory Systems
Letters indicate owners of the directories and files
![Page 17: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/17.jpg)
17
Hierarchical Directory Systems
A hierarchical directory system
![Page 18: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/18.jpg)
18
A UNIX directory tree
Path Names
![Page 19: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/19.jpg)
19
To Open dict path is: /usr/jim/dict.
Path Names
![Page 20: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/20.jpg)
20
Directory Operations
1. Create
2. Delete
3. Opendir
4. Closedir
5. Readdir
6. Rename
7. Link
8. Unlink
![Page 21: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/21.jpg)
21
File System Implementation
A possible file system layout
![Page 22: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/22.jpg)
22
Implementing Files (1)
(a) Contiguous allocation of disk space for 7 files(b) State of the disk after files D and E have been removed
![Page 23: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/23.jpg)
23
Implementing Files (2)
Storing a file as a linked list of disk blocks
![Page 24: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/24.jpg)
24
Implementing Files (3)
Linked list allocation using a file allocation table in RAM
![Page 25: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/25.jpg)
25
Entry 4 bytes. Blocks 1K. 20 Million Entries == 80 MB for table.
![Page 26: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/26.jpg)
26
Implementing Files (4)
An example i-node
![Page 27: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/27.jpg)
27
An example i-node
Double Indirection
Triple Indirection
Disk block containing addresses of disk blocks containing addresses
![Page 28: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/28.jpg)
28
Implementing Directories (1)
(a) A simple directoryfixed size entriesdisk addresses and attributes in directory entry
(b) Directory in which each entry just refers to an i-node
![Page 29: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/29.jpg)
29
Implementing Directories (2)
• Two ways of handling long file names in directory– (a) In-line– (b) In a heap
![Page 30: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/30.jpg)
30
Shared Files (1)
File system containing a shared file
![Page 31: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/31.jpg)
31
Shared Files (1)
Cyclic Family Tree
![Page 32: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/32.jpg)
32
Links
(a) Situation prior to linking
(b) After the link is created
(c) After the original owner removes the file
![Page 33: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/33.jpg)
33
Symbolic Links
• Provide the path name of the target file in the linked file
![Page 34: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/34.jpg)
34
Disk Space Management (1)
• Dark line (left hand scale) gives data rate of a disk• Dotted line (right hand scale) gives disk space efficiency• All files 2KB
Block size
![Page 35: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/35.jpg)
35
Disk Space Management (2)
(a) Storing the free list on a linked list(b) A bit map
![Page 36: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/36.jpg)
36
Quotas for keeping track of each user’s disk use
![Page 37: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/37.jpg)
37
Consistency Issues
• File system can become inconsistent if there is a system crash and recent changes have not all been written to disk.
• Consider:– inode cached
– New block allocated to file
– Block filled, written to disk
– Free list updated and written to disk
– System crash
– Now block not on either free list or listed as part of a file
![Page 38: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/38.jpg)
38
• Consider:– inode cached
– Free list cached
– Block 10 deleted from file A. Cached inode updated.
– Block 10 now on free list and allocated to file B.
– File B closed, inode written to disk.
– System crash.
– Now block 10 listed as belonging to two files.
![Page 39: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/39.jpg)
39
File System Consistency
– Build two tables, each of which counts number of blocks.
– Table 1: Number of times block is in a file.
– Table 2: Number of times block is in the free list.
– Read all inodes.
– Increment tables.
![Page 40: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/40.jpg)
40
File System Reliability (3)
• File system states(a) consistent(b) missing block(c) duplicate block in free list(d) duplicate data block
![Page 41: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/41.jpg)
41
– Figure b- missing block.
• Adds it back to the free list.
– Figure c- block listed twice in free list
• Rebuilds the free list.
– Figure d- Same block belongs to two or more files.
• Make copy and insert in one of the files.
![Page 42: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/42.jpg)
42
File System Performance (1)
The block cache data structures
![Page 43: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/43.jpg)
43
Problem with LRU
• If frequently used block is inode or directory block, may want to write it out.
• Modify LRU to account for importance of block.
• Unix: synch()
• MS-DOS: Write-through cache
![Page 44: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/44.jpg)
44
• Most systems write critical blocks to disk immediately (but not necessarily non-critical blocks).
• If system crashes, file system likely intact (but users may become unglued).
• Unix: System call sync that causes all modified blocks to be written to disk.– An update daemon is running in the background and alternates between
sleeping and calling synch. Generally every 30 seconds.
• MS-DOS: Write-through cache. Every change is written through to disk.
![Page 45: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/45.jpg)
45
File System Performance (2)
• I-nodes placed at the start of the disk• Disk divided into cylinder groups
– each with its own blocks and i-nodes
![Page 46: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/46.jpg)
46
CP/M
• 8080 Chip
• Max 64K RAM
• 720K Floppy.
• Size of entire OS: 3584 bytes.
• Shell: 2K bytes.
![Page 47: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/47.jpg)
47
The CP/M File System (1)
Memory layout of CP/M
![Page 48: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/48.jpg)
48
Directory
• One directory
• Entries 32 bytes (fixed).
• After booting, reads in directory and computes free list.
• Does not save free list.
• Provides 38 systems calls, 17 File system related.
• File blocks are 1K.
![Page 49: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/49.jpg)
49
The CP/M File System (2)
The CP/M directory entry format
![Page 50: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/50.jpg)
50
MS-DOS
• Added hierarchical directory structure.
• Use fixed 32-byte directory entry
• Added attributes: read-only, archived, hidden, system.
• Time field: seconds (5 bits), minutes (6 bits), hours (5 bits).
• Date: day (5 bits), month (4 bits), year (7 bits– only good to 2107).
![Page 51: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/51.jpg)
51
The MS-DOS File System (1)
The MS-DOS directory entry
![Page 52: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/52.jpg)
52
File Allocation Table (FAT)
Entry 4 bytes. Blocks 1K. 20 Million Entries == 80 MB for table.
![Page 53: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/53.jpg)
53
The MS-DOS File System (2)
• Maximum partition for different block sizes• The empty boxes represent forbidden combinations
![Page 54: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/54.jpg)
54
Windows 98
• Used 32-bit FAT.
• Used the additional 10 bits from DOS entry.
• Allowed arbitrarily long file names
• Backward compatible to MS-DOS.
![Page 55: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/55.jpg)
55
The Windows 98 File System (1)
The extended MOS-DOS directory entry used in Windows 98
Bytes
![Page 56: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/56.jpg)
56
The Windows 98 File System (2)
An entry for (part of) a long file name in Windows 98
Bytes
Checksum
![Page 57: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/57.jpg)
57
The Windows 98 File System (3)
An example of how a long name is stored in Windows 98
![Page 58: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/58.jpg)
58
The UNIX V7 File System (1)
A UNIX V7 directory entry
![Page 59: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/59.jpg)
59
The UNIX V7 File System (1)
A UNIX V7 directory entry
![Page 60: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/60.jpg)
60
The UNIX V7 File System (2)
A UNIX i-node
![Page 61: File Systems](https://reader035.vdocuments.site/reader035/viewer/2022070402/56813874550346895da022cb/html5/thumbnails/61.jpg)
61
The UNIX V7 File System (3)
The steps in looking up /usr/ast/mbox