This is not the current version of the class.

Lecture 12

(Notes by Thomas Lively)

Front matter

Pset 3 is out

Goal: Implement file descriptors on top of basic read/write syscalls

Take a look at Linux's file operations (there are a log of them) xv6 has only read and write (only supports one FS)

Eddie's solutions are cumulatively 950 lines for reference

waiter::block_until

waiter::block_until parameterized with type of predicate F.

Locking in FS

Possible situation

T1        T2
read(0)
(blocks)
          close(0)

OK: read returns EBADF OK: read blocks until data returns BAD: close blocks forever BAD: read accesses freed kernel memory

How to avoid badness

Steps to do something with file

  1. lock file descriptor table
  2. find file
  3. lock file (noirq)
  4. unlock file descriptor table
  5. increment file refcount
  6. unlock file
  7. block with continuing existence of file guaranteed
  8. lock file
  9. decrement file refcount
  10. unlock file
  11. maybe free file

Refcount cannot start at 0, since file descriptor table already has reference

Refcount is like a lock—a shared lock on existence!

Virtual methods

Eddie explains how virtual methods work

this_cpu and current

Why does this_cpu need disabled interrupts while current (proc) does not?