Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 12: File-System Implementation CSS503 Systems Programming

Similar presentations


Presentation on theme: "Chapter 12: File-System Implementation CSS503 Systems Programming"— Presentation transcript:

1 Chapter 12: File-System Implementation CSS503 Systems Programming
Prof. Munehiro Fukuda Computing & Software Systems University of Washington Bothell CSS503 Chapter 12: File-System Implementation

2 Chapter 12: File-System Implementation
File System Layers Applications Access files through open, read, write, lseek, and close Translate a file name into a file number an a file handle Mange directory Protect files Manage each file in an FCB: file control block (inode in Unix, master file table entry in NTFS) Find physical block# through FCB Mange free free blocks Translate “retrieve block #x” in drive X, cylinder Y, track 2, and sector 10 Buffer/cash data from disk to I/O buffers. Access disks with drive X, cylinder Y, track 2, and sector 10 Logical file system File-organization module Basic file system I/O control Devices CSS503 Chapter 12: File-System Implementation

3 Disk Structure and Directories
Sector 0 Partition table <bootable/non-bootable, sectors, cylinders> Layout of the file system: file system size, #free blocks File control blocks (inodes) Files and directories: <inode, filename> <123, “.”> <567, “data.txt”> MBR: Master Boot Record Partition Table OS Boot Block Super Block File Space Management inodes Data Blocks dir file Another Partition CSS503 Chapter 12: File-System Implementation

4 A Typical File Control Block
Unix: iNode NTFS: Master file table entry File permission File dates (create, access, write) File owner, group, access contrl list File size File data block or pointers to file data blocks CSS503 Chapter 12: File-System Implementation 3

5 Contiguous Allocation
directory Merits Good performance (minimal seek time) Example IBM VM/CMS Problems External fragmentation Determining the file space upon its creation (Can we predict the size before a file is written?) File Start Length count 2 tr 14 3 mail 19 6 list 28 f 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 CSS503 Chapter 12: File-System Implementation 4

6 Chapter 12: File-System Implementation
Linked Allocation Merits Need only starting block No external fragmentation Problems Sequential access Link information occupying a portion of block File not recovered if its link is broken CSS503 Chapter 12: File-System Implementation

7 File Allocation Table (FAT)
test 217 name start block directory entry FAT has an entry for each disk block. FAT entries rather than blocks themselves are linked. Example: MS-DOS and OS/2 Merit: Save disk block space Faster random accesses Demerit: A significant number of disk head seeks 339 618 EOF 217 #blocks -1 FAT 217 339 618 CSS503 Chapter 12: File-System Implementation

8 File Allocation Table (FAT)
FAT entry size: 12bits #FAT entries: 4K Disk block (cluster) size: 32K (depends on each system) Total disk size: 128M FAT16 FAT entry size: 16bits #FAT entries: 64K Disk block size: 32K Total disk size: 2G FAT32 FAT entry size: 32bits, of which 28bits are used to hold blocks #FAT entries: 256M Total disk size: 8T, (but limited to 2T due to the use of sector counts with the 32bit entry.) CSS503 Chapter 12: File-System Implementation

9 Chapter 12: File-System Implementation
Indexed Allocation Similar to the paging scheme Merit: Directory access Demerits: Internal fragmentation Uncertainty in the index block size Too small: cannot hold a large file Too large: waste disk space CSS503 Chapter 12: File-System Implementation

10 NTFS MFT (Master File Table):
An array of records, each holding the attributes for a different file Sequence File Number 63 47 File reference MFT File record: name, security, and data For consistency check MFT entry - 1 Run(extent) Run(extent) Disk Cluster numbers Cluster numbers CSS503 Chapter 12: File-System Implementation

11 NTFS Continued Directory:
Includes all the file references belonging to the directory in its runs MFT Directory “\” File record: name, security, and data Run(extent) Run(extent) Cluster numbers Cluster numbers file1 file2 file3 file4 file5 file6 file7 file8 CSS503 Chapter 12: File-System Implementation

12 Linked Scheme in Index Allocation
Advantage: Adjustable to any size of files Disadvantages: Slower random accesses for larger files 4 5 6 . 28 27 29 30 CSS503 Chapter 12: File-System Implementation

13 Multilevel Index in Indexed Allocation
outer-index Advantage: Adjustable to any size of files Disadvantages: Multiple table accesses index table file CSS503 Chapter 12: File-System Implementation

14 Combined Scheme: UNIX (4K bytes per block)
Inode File information The first 12 pointers point directly to data blocks The 13th pointer points to an index block The 14th pointer points to a block containing the addresses of index blocks The 15th pointer points to a triple index block. CSS503 Chapter 12: File-System Implementation

15 Unix File System Structure
Process int fd = open(“fileA”, flags); read(fd, …); stdin stdout stderr 1 2 3 User file Descriptor table PCB Inode: length count 1 direct[12] indirect[3] struct file: count 1 inode Disk File Structure Table Inode table CSS503 Chapter 12: File-System Implementation

16 Chapter 12: File-System Implementation
Free Space Management Bit vector (n blocks) Linked free space list Easy to find contiguous space Pros No waste of space Waste of memory space Cons Difficult to find contiguous space 1 2 n-1 Free-space list head 1 2 3 4 5 6 7 0  block[i] free 1  block[i] occupied 8 9 10 11 bit[i] =  12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 CSS503 Chapter 12: File-System Implementation

17 Disk Cache Utilizing paging Double-caching problem
Memory-Mapped I/O I/O Using read( ) and write( ) Page Cache Utilizing paging File System Double-caching problem Buffer Cache Improving performance bread(dev, blkno, size), bwrite( bufp) Block I/O Routine Disks CSS503 Chapter 12: File-System Implementation 16

18 Page versus Buffer Cache
Regular file I/O with read( ) and write( ) A unified buffer cache uses the same page cache to cache both memory-mapped pages and ordinary file system I/O to avoid double caching Memory-Mapped I/O File System File Meta Data: inodes, dentries (directories) Page Cache inode->i_pages page 0 page 1 page n in memory Buffer Cache buffer hdr page dscptr physical page Buffer Page buffer hdr page dscptr physical page Buffer Page bread(dev, blkno, size), bwrite(bufp) block_read_full_page( page, get_block( ) ) Block I/O Routine Disks CSS503 Chapter 12: File-System Implementation 17

19 Programming Assignment 3 Standard I/O Library
Standard I/O Library itself has a buffer to reduce # read and write system calls. #include <stdio.h> Int main( ) { FILE *f = fopen( “myFile”, “r” ); char buf[10]; fgets( buf, sizeof( buf ), f ); printf( “%s¥n”, buf ); return 0; } user mode Standard C Library stdio buffer System Call Interface: sd = open( “myFile”, O_RDONLY ), read( fd, buf, sizeof( buf ), write( 1, buf, sizeof( buf ) ) kernel mode CSS503 Chapter 12: File-System Implementation

20 Programming Assignment 3 Standard I/O Library
Since Unix does not differentiate between text and binary, ‘b’ has no effect. fopen type Unix open mode r or rb O_RDONLY w or wb O_WRONLY | O_CREAT | O_TRUNC a or ab O_WRONLY | O_CREAT | O_APPEND r+ or rb+ or r+b O_RDWR w+ or wb+ or w+b O_RDWR | O_CREAT | O_TRUNC a+ or ab+ or a+b O_RDWR | O_CREAT | O_APPEND CSS503 Chapter 12: File-System Implementation

21 Chapter 12: File-System Implementation
Discussions In which table should we implement the file seek pointer, a user file descriptor table, a file structure table, or an inode table? Why? Consider the reason as focusing on the situation where a parent and a child process shares the same file at the same time when another independent process also reads the same file. What is the similarity and difference in file allocation between Unix and Windows NTFS CSS503 Chapter 12: File-System Implementation


Download ppt "Chapter 12: File-System Implementation CSS503 Systems Programming"

Similar presentations


Ads by Google