Reading the file readfd buffer size Note fd is maintained in per process open

Reading the file readfd buffer size note fd is

This preview shows page 47 - 60 out of 60 pages.

Reading the file read(fd, buffer, size) Note fd is maintained in per-process open-file table Table translates fd -> inumber of file 47
Image of page 47
File-open table per process File descriptor File name Inumber Position offset 3 /foo/bar 32382 0 4 /foo/more 48482 512 48
Image of page 48
Reading the file read(fd, buffer, size) 1. Consult bar's inode to locate its 1 st block 2. Read the block 3. Update inode with newest file access time 4. Update open-file table with new offset 5. Continue steps 2, 3, 4 until done 6. Deallocate file descriptor 49
Image of page 49
Cost for reading a block 3 I/O's: read inode, read data block, write inode 50 2
Image of page 50
Open for write int fd = open("/foo/bar", O_WRONLY) Assume bar is a new file under foo (note the difference from reading chapter!) 51
Image of page 51
Open for write int fd = open("/foo/bar", O_WRONLY) 1. Read '/' inode & content obtain foo's inumber 2. Read '/foo' inode & content check if bar exists 52
Image of page 52
Open for write 3. Read imap, to find a free inode for bar 4. Update imap, setting 1 for allocated inode 5. Write bar's inode 53
Image of page 53
Open for write 6. Update foo's content block Adding an entry for bar 7. Update foo's inode Update its modification time 54
Image of page 54
Cost for "open for write" int fd = open("/foo/bar", O_WRONLY) Need 9 I/O's 55 data bitmap inode bitmap root inode foo inode bar inode root data foo data bar data[0] bar data[1] bar data[2] read read read read read write write write write create()
Image of page 55
Writing the file: /foo/bar 1. Read inode of bar (by looking up its inumber in the file-open table) 2. Allocate new data block Read and write bmap 3. Write to data block of bar 4. Update bar inode new modified time, add pointer to block 56
Image of page 56
Cost of writing /foo/bar 5 I/O's for write a block 57 data bitmap inode bitmap root inode foo inode bar inode root data foo data bar data[0] bar data[1] bar data[2] read read read read read write write write write read read write write write create() write()
Image of page 57
Caching for read First read may be slow But subsequent ones will speed up Good idea to cache popular blocks e.g., determined via LRU strategy 58
Image of page 58
Buffering for delayed write Improve write performance via: Batching (e.g., two updates to the same imap) Scheduling (reordering for better performance) Avoiding writes (if file created, then quickly deleted) Problem: update may be lost when system crashes 59
Image of page 59
Example file systems NTFS New technology file system, Microsoft proprietary FAT File allocation table FAT 16, 32, … 32 bits = # of sectors a file can occupy 512B/sector => 2TB limit on file size 4KB/sector => 16TB limit Ext4 fourth extended file system, common in Linux 60
Image of page 60

You've reached the end of your free preview.

Want to read all 60 pages?

  • Fall '14

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes