Homework: Files and Disk I/O

Read: readi, writei, fileread, filewrite, create, and dirlink, and code related to these calls in fs.c, bio.c, ide.c, file.c, and sysfile.c. For now you can ignore log.c (except for the modification explained below); whenever you see "log_write" you should pretend that log_write just calls bwrite with the same arguments.

Hand-In Procedure

You are to turn in this homework during lecture. Please write up your answers to the exercises below and hand them in to a 6.828 staff member at the beginning of lecture.

File and Disk I/O

Insert a print statement in log_write (in log.c) so that you get a print every time a block is written to disk:
  cprintf("log_write sector %d\n", b->sector);
Build and boot a new kernel and run these three commands at the shell:
  echo > a
  echo x > a
  rm a
  mkdir d
(Try rm d if you are curious; it should look much the same as rm a.)

You should see a sequence of log_write prints after running each command.

Submit: Record the list and annotate it with the calling function and what block is being written (for example, "file's i-node block", "file's data block", &c).

Hint: an easy way to get the name of the calling function is to add a string argument to log_write, edit all the calls to log_write to pass the name of the calling function, and just print it. You should be able to reason about what kind of block is being written just from the calling function.

You need not write the following up, but try to understand why each write is happening. This will help your understanding of the file system layout and the code.