1 / 21

Chapter 12: File-System Implementation CSS503 Systems Programming

Chapter 12: File-System Implementation CSS503 Systems Programming. Prof. Munehiro Fukuda Computing & Software Systems University of Washington Bothell. File System Layers. Applications. Access files through open, read, write, lseek, and close

maryjtaylor
Download Presentation

Chapter 12: File-System Implementation CSS503 Systems Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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 Chapter 12: File-System Implementation

  3. Disk Structure and Directories MBR: Master Boot Record • 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”> Partition Table OS Boot Block Super Block File Space Management inodes Data Blocks dir file Another Partition Chapter 12: File-System Implementation

  4. A Typical File Control Block • Unix: iNode • NTFS: Master file table entry Chapter 12: File-System Implementation

  5. Contiguous Allocation 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?) directory 0 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 Chapter 12: File-System Implementation 4

  6. 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 Chapter 12: File-System Implementation

  7. File Allocation Table (FAT) 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 directory entry name start block 0 test 217 217 618 339 EOF 217 339 618 339 618 #blocks -1 FAT Chapter 12: File-System Implementation

  8. File Allocation Table (FAT) FAT12 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 Disk block size: 32K Total disk size: 8T, (but limited to 2T due to the use of sector counts with the 32bit entry.) Chapter 12: File-System Implementation

  9. 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 Chapter 12: File-System Implementation

  10. NTFS MFT (Master File Table): An array of records, each holding the attributes for a different file File reference 63 47 0 Sequence File Number MFT File record: name, security, and data For consistency check MFT entry - 1 Run(extent) Run(extent) Disk Cluster numbers Cluster numbers 505 506 507 508 86 87 88 89 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 file5 file6 file7 file8 file1 file2 file3 file4 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 Chapter 12: File-System Implementation

  13. Multilevel Index in Indexed Allocation  outer-index • Advantage: • Adjustable to any size of files • Disadvantages: • Multiple table accesses file index table 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. Chapter 12: File-System Implementation

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

  16. Free Space Management Bit vector (n blocks) • Linked free space list 0 1 2 n-1 Free-space list head 0 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 Chapter 12: File-System Implementation

  17. Disk Cache 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 Chapter 12: File-System Implementation

  18. Page versus Buffer Cache 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 Buffer Page Buffer Page page dscptr page dscptr physical page physical page hdr hdr buffer buffer hdr hdr buffer buffer hdr hdr buffer buffer hdr hdr buffer buffer Regular file I/O with read( ) and write( ) 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 bread(dev, blkno, size), bwrite(bufp) block_read_full_page( page, get_block( ) ) Block I/O Routine Disks Chapter 12: File-System Implementation

  19. Programming Assignment 3Standard 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 Chapter 12: File-System Implementation

  20. Programming Assignment 3Standard I/O Library • Since Unix does not differentiate between text and binary, ‘b’ has no effect. Chapter 12: File-System Implementation

  21. 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 Chapter 12: File-System Implementation

More Related