Lecturer: Hao-Hua Chu TA: Wen-Chang HSU

advertisement
Lecturer: Hao-Hua Chu
TA: Wen-Chang HSU


Read and understand the nachos file system
Enhance file system in Nachos
 Relax maximum size of a file .
▪ Nachos file system can not hold a single file more than
4KB
▪ You need to increase the limit up to 32 Kbyte.
 Let Nachos has hierarchal directory structure
▪ Nachos has only one root directory
▪ Have Nachos handle subdirectory.
2



How to use Nachos File system.
C++ files that represent file system
The clue of how to extend file size limit.
 Modify the FileHeader class ( i-node ).

How to add subdirectory
 Modify the File System

Test case.
3


There are two mode of nachos file system
1. STUB system ( we use it before).
 Nachos file system operations are forward to host
file system.

2. Native file system
 Nachos simulate a disk with a huge file.
 Nachos implement the detail of every file
operation.
4

Modify Makefile , remove the
-DFILESYS_STUB

Make clean and rebuild nachos.

You can use Nachos with native file system
now!
5

Nachos -f
 format and make a disk.

Nachos –cp source destination
 Copy unix file into nachos disk.

Read trheads/main.cc , you know all the file
system operations in nachos.
6

filesys.cc/h
 It contains top-level file system functions.

Directory.cc/h
 Contains the structure of one directory.

openfile.cc / h
 Like a file descriptor (fd) .

filehdr.cc/h ( i node )
 It contains pointes to data sectors on disk.

Synchdisk.cc / h
 Operation on disks
7
Syndisk:
Disk is look like a huge array. Access each element by
sectorNumber.
each sector size is 128 byte.
0
1
2
8
9
15
50
8
FileHeader. Store on one sector. And has pointers
point to data sector.
0
1
2
8
9
15
50
9
OpenFile : it is a wrapper of
Fileheader. Perform r/w
access of a single file by
OpenFile. Act like a fd.
0
1
2
FileHeader.
8
9
15
50
10
FileSystem:
Provide functionality to manage files.
Free map :Store a bitmap. To record which sector is free
Directory :Stores name and position of every file.
0
1
inode
2
8
9
15
50
11

Why maximum size of a file is limited?
 The size of file header (i-node) is corresponding to
the size of one sector.
 The maximum size of a file is limited by the
number of pointers that will fit in one disk sector.
FileHeader.
12
#define NumDirect ((SectorSize - 2 * sizeof(int)) / sizeof(int))
#define MaxFileSize (NumDirect * SectorSize)
class FileHeader {
you need read the comment of every public methods carefully.
private:
int numBytes;
// sizeof( int)
int numSectors;
// sizeof(int)
int dataSectors[NumDirect];
}
13

A FileHeader can be initialized by
 (1) Allocate : allocate free sector and create a new
file fileheader
 (2)FetchFrom : the fileheader is already exists on
disk, so the method just read the file header
structure.

ByteToSector.
 Return the sector where a given byte is on.
14





Add some indirect blocks in FileHeader.
You can’t change the size of a sector.
In Allocate and Deallocate, you'll need to
determine if you need to use indirect blocks
or not base on file size.
In FetchFrom and WriteBack, you'll also need
to determine whether indirect blocks are
needed.
Plan carefully!
15

Nachos has only a root directory.

modify file fileSystem and Directory to
support subdirectory.

Separator is the usual UNIX directory
separator /
16


TA will put file up to 32k into your file system.
Bonus:
 If you can handle file up to 4MB.
 Disk created by nachos is just 128 KB ,You need to
check how to correctly enlarge the simulated disk.
17

TA will test your implementation by copying ,listing , dumping and
executing file in your file system.

Nachos -r path_to_dir
// 刪除檔案

nachos -l path_to_dir
// 列出某個資料夾的內容。

nachos -p path_to_file
// 看檔案內容

nachos -cp UnixFIle path_to_dir
// 拷貝資料

nachos -mkdir path_to_dir
//創建新的資料夾。

nachos -E path_to_file UnixFile
// 匯出檔案到 unix

除了 mkdir , -E 其他的參數nachos 本來就有提供相似的的功能,。
18

Each directory name in less than 9 character

TA won’t test strange file name.

You need to correctly support multiple level
subdirectory.
19

Submit source code and report.

Make clean first. Don’t send the simulated disk!

The file you need to send:
1.
2.
A report in .pdf or .doc
code directory in nachos ,

指令範例(在NachOS-4.0目錄下執行):
"tar zcvf os_hw5_b91902090.tar.gz code report.pdf"

壓縮檔範例:
http://www.csie.ntu.edu.tw/~artoo/os_hw5_b91902090.tar.gz
20

Due at 1/5 24:00 !!
21

Deadline: 10/6 24:00
 Delayed submission would have penalty!

DO NOT COPY!!
Protect your code well!!
22
Download