Laboratory 5: Extendable Files
一:Objectives(实验目标)
The purpose of this lab session is to help you start to work on extending the Nachos file system, the
programming task of Assignment 3.
The work required in this laboratory session itself is part of Assignment 3.
The Nachos file system is a simple file system with many restrictions. One of them is that the size
of the file is not extendable: once you specify the size of a file upon its creation, the size of the file
is fixed throughout its lifetime. In this laboratory session, you are going to extend the Nachos file
system to allow the size of files to be extended. In particular, we want the new Nachos file system
to have the following features:
_ When a file is created, its initial size can be set to 0.
_ The size of a file can be increased if more data are written to the file.
For example, if the initial size of a file is 100 bytes and a write operation for 100 bytes data from the
position 50 (the first byte is at position 0) will extend the size of the file to 150 bytes. The situation
is illustrated in Figure 10.1, in which (a) represents the initial size (100 bytes) of the file. The light
shadow represents the current contents of the file. (b) represents the new 100 bytes of data to be
written from position 50. (c) shows the extended size of the file with dark shadow representing the
new data.
The current Nachos file system does not allow the file size to be extended like this. Your task is to
design and implement the extension of the Nachos file system to have these new features.
二:实验环境
After you finish the analysis, you can start to design and implement the changes to the existing
Nachos file system. Your working directory is ../lab5/. There is one directory test in ../lab5
which contains the test files. You need to set up the arch subdirectory hierarchy and your new
makefiles in ../lab5. You also have to make a decision as to which files in ../filesys/ need to
be copied to ../lab5 in order to modify them.
The two files main.cc and fstest.cc in ../lab5/ are new and include many new file system
commands to test the new features required. We will discuss these new commands in Section 10.4.
main.cc is complete and you should not change it. fstest.cc is almost complete except that you
need to uncomment four lines in it. In both functions Append(...) and NAppend(...), you can
see the following three lines:
// Write the inode back to the disk, because we have changed it
// openFile->WriteBack();
// printf("inodes have been written back\n");
You need to uncomment the last two lines after you add Writeback() function to class OpenFile.
Why do you need this function for OpenFile? Think about it.
Use the following guidelines for the implementation and coding.
三:关键代码注释:
Read files main.cc and fstest.cc in ../lab5/ and make sure that you understand how these
new commands are implemented.
When testing the new Nachos file system, start with a fresh DISK by removing the old DISK and
executing nachos -f. Then execute the following commands in the order:
nachos -cp test/small small
nachos -ap test/small small
nachos -cp test/empty empty
nachos -ap test/medium emtpy
Your file system dump with nachos -D at this point should be like this:
Bit map file header:
FileHeader contents. File size: 128. File blocks:
2
File contents:
\ff\7\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
Directory file header:
FileHeader contents. File size: 200. File blocks:
3 4
File contents:
\1\12\11@\5\0\0\0small\0\0\0\0G\5\8\1H\5\8\8\0\0\0empty\0\0\0\0\0\0\0\0G
\5\8\0\0\0\0\0\0\0\00\0\0\0\e0\12\11@\0\12\11@\10G\5\8X\13\0\0\d0\15\11@
\18\0\0\0\0\12\11@\c8\12\11@\80G\5\8\18\0\0\0‘\0\0\0\0\0\0\0\0\0\0\0\2\0
\0\0\a0F\5\8\0\0\0\0\0\0\0\0\18\0\0\0
\0\0\0\0\1\0\0\0\a8D\5\8\0\11\0\0\c8\15\11@H\0\0\0\f8\12\11@\f8\12\11@\0F
\5\8\0\0\0\0\0\0\0\00\0\0\0\e0\12\11@\0\12\11@\90D\5\8\c8\15\11@HH\5\8\18
\0\0\0
Bitmap set:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
Directory contents:
Name: small, Sector: 5
FileHeader contents. File size: 168. File blocks:
6 7
File contents:
small file small file small file\asmall file small file small
file\a***end of file***\asmall file small file small file\asm
all file small file small file\a***end of file***\a
Name: empty, Sector: 8
FileHeader contents. File size: 162. File blocks:
9 10
File contents:
medium file medium file medium file\amedium file medium file med
ium file\amedium file medium file medium file\amedium file medi
um file medium file\a***end of file***\a
No threads ready or runnable, and no pending interrupts.
Assuming the program completed.
Machine halting!
Ticks: total 8490, idle 8000, system 490, user 0
Disk I/O: reads 16, writes 0
Console I/O: reads 0, writes 0
Paging: faults 0
Network I/O: packets received 0, sent 0
Cleaning up...
四:调试记录:
记录如上.
五:运行结果分析:
本实验通过在fstest.cc中增加一个append方法,在append方法中定义了文件追加命令,定义了-ap方法的实现,这样就可以实现文件的追加,在测试过程中,可以明显的看到在nachos文件的末尾增加了你要增加的内容,主要在实现此方法的过程中遇到了程序的bug,使我知道了调试的过程,解决问题的过程。