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 51 - 63 out of 63 pages.

Reading the file read(fd, buffer, size) Note fd is maintained in per-process open-file table Table translates fd -> inumber of file 51
Image of page 51
Reading the file read(fd, buffer, size) 1. Consult bar's inode to locate a block 2. Read the block 3. Update inode with newest file access time 4. Update open-file table with new offset 5. Repeat above steps until done (with reading data of given size) 52
Image of page 52
Cost for reading a block 3 I/O's: read inode, read data block, write inode 53 2
Image of page 53
Open for write int fd = open("/foo/bar", O_WRONLY) Or int fd = create(("/foo/bar") Assume bar is a new file under foo (note the difference from reading chapter!) 54
Image of page 54
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 55
Image of page 55
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 56
Image of page 56
Open for write 6. Update foo's content block Adding an entry for bar 7. Update foo's inode Update its modification time 57
Image of page 57
Cost for "open for write" int fd = open("/foo/bar", O_WRONLY) Need 9 I/O's 58 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 58
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 modification time, add pointer to block 59
Image of page 59
Cost of writing /foo/bar 5 I/O's for write a block 60 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 60
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 61
Image of page 61
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 62
Image of page 62
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 63
Image of page 63

You've reached the end of your free preview.

Want to read all 63 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