Download presentation
Presentation is loading. Please wait.
1
The File Manager Implementation issues
This lecture: From UFID to the physical storage Data structures File allocation Reading: Bacon 7.5 13 August 2019 CS2051 Lecture 14
2
The File System is Layered
Application fread(…), fopen(…), ... Logical File System Directory structures. File-organisation Links logical (user) view with physical view Basic file system Issues instructions to the right device driver I/O control Device drivers + interrupt handlers Physical device We consider hard disks only! 13 August 2019 CS2051 Lecture 14
3
Data Structures File metadata (Bacon) or File Control Block:
file size, permissions, owner, group, dates, ... Information about where data on disk can be found. Active file table in memory: each entry contains metadata for a file currently in use & number of readers/writers. index to the table is the UFID (Unix: file descriptor, Windows NT: file handle) “open file” creates entry in the file table “close file” writes metadata to disk (assumes file is not used by anyone in the system) Implementations vary: a per process table may exist too! 13 August 2019 CS2051 Lecture 14
4
Operating System Data Structures
Process A Process B O.S. 1 2 3 1 2 3 (file pointers) System open file table Active file information table Buffer cache - disk blocks that have been recently read or written Metadata File Storage (files, directories, free blocks) 13 August 2019 CS2051 Lecture 14
5
File System Calls 13 August 2019 CS2051 Lecture 14
6
open(“/usr/ar/timetable”, O_RW) create(“/usr/ar/timetable.1”, 0755)
Find Metadata for root directory read / directory to get SFID for /usr find Metadata for /usr directory read /usr directory to get SFID for ar find Metadata for /usr/ar directory read /usr/ar directory to get SFID for /usr/ar/timetable read /usr/ar/timetable Metadata into Active File Information table create System Open File table entry find free entry in per-process table return UFID 13 August 2019 CS2051 Lecture 14
7
read(4, &buf[0], 8192) find System Open File table entry - get file offset find Active File Information table entry check permissions calculate first file block number(s) read file blocks into block cache copy required data into user space update position pointer in System Open File table entry close(4) release entry in per-process table release entry in System Open File table in Active File Information table: if number of readers and writers is now zero, write Metadata back to disk release Active File Information table entry 13 August 2019 CS2051 Lecture 14
8
File Allocation Methods
Contiguous allocation File occupies contiguous blocks on disk Extent(s) allowed (Bacon, extent lists) Linked Allocation File is a linked list of data blocks (Bacon, chaining in the media) Linked list is saved separately as a block DOS, File Allocation Table (FAT) (Bacon, chaining in a map) Indexed Allocation Each file has a table of pointers to its blocks (Bacon, table...) Unix, inodes (multilevel indexing) 13 August 2019 CS2051 Lecture 14
9
Contiguous Allocation
File … start length 1 3 6 2 Pros: provides very good performance. Cons: hard to predict needs (cf. with memory allocation strategies); fragmentation; can’t eliminate all seeks if there are interleaved user requests. Provide a way of splitting the file using extents. 13 August 2019 CS2051 Lecture 14
10
Linked Allocation FAT 1 1 2 FAT 2 3 3 4 File 1: …start at 4
FAT 1 1 2 FAT 1. eof 6. 3 3. eof 8. 6 2 3 3 4 File 1: …start at 4 File 2: …start at 5 4 5 5 6 6 7 7 8 8 9 9 1st approach: each block has a pointer to the next Pros: no fragmentation, easy to extend a file Cons: random access is difficult; if a block is corrupted the rest of the file is lost. 2nd approach: (DOS) File Allocation Table (FAT) Provides a solution to the above cons (good to cache the FAT) 10 10 13 August 2019 CS2051 Lecture 14
11
Indexed Allocation 1 2 File1 Index Block: 9 3 4 5 6 7 8 9 10
1 Index block 9: 1. 4 2. 2 3. 8 4. 6 5. 3 6. NULL 7. NULL 8. NULL 2 File1 Index Block: 9 3 4 5 6 7 8 9 10 Pros: Facilitates random access to files Cons: Too much space (for NULL pointers) may be wasted The Unix approach: provide some indirect pointers too 13 August 2019 CS2051 Lecture 14
12
Conclusion File System Interface provides a user-friendly view of the file system. File System Implementation deals with file allocation and storage management. Performance Issues use disk cache for frequently accessed blocks efficiency dependent on algorithms/types of data Recovery consistency checking (chkdsk in MS-DOS) keep backups! 13 August 2019 CS2051 Lecture 14
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.