1. A journey of file system
on JOS
Name :wayling
Date: 2012/09/11
1
2. Who am I?
wayling
• JuluOSDev 星系 001
– virtual file system (2011-12-20 )
• http://www.juluos.org/home/files
• 出沒於 TOSSUG & H4
• waylingII@gmail.com
2
3. Introduction JOS
• MIT 6.828 Operating System Engineering
• JOS 是一個有基本雛形的作業系統,擁有傳統 unix-like
functiom(fork, exec…) ,但是實作方式是 exokernel
style( 實作的 unix-like functiom 大部份皆為 user level 的
函式,不實作於 kernel level) 。
• 主要部份 :
– Booting
– Memory management
– User-level environments
– Preemptive multitasking
– File system and spawn
– A shell Lectures:
Frans Kaashoek
Robert Morris3
4. JOS File System
• Part1 : File system struct
– In-memory and On-disk struct
• Part 2: Client/Server file system access
– Remote procedure call (RPC) base on IPC +
process
4
5. JOS File System
• Part1 : File system struct
– In-memory and On-disk struct
• Part 2: Client/Server File System Access
– remote procedure call (RPC) base on IPC +
process
5
6. The File System
• File system 是 memory 跟 disk 操作結合
而成的,意及我們在存取檔案時, memory
跟 disk 都需要有對應的 struct 來存放表示
。
• static + dynamic 組成 file system
– Static : 格式化硬碟成特有檔案系統格式 ex :
ext2 、 ext3 。
– Dynamic : runtime 時作業系統保存對應的資
料結構,藉此操作 disk ,提供檔案操作給使用
者。
6
7. JOS file system item(1/2)
• Sectors and Blocks
– Sector :Disk 實體磁區 (512 B) 。
– Block : file system 存取單位 (4KB) 。
• Superblocks (disk & memory)
– 保存 block size 、 disk size 、 以及其他
meta-data 用於尋找到 root directory 。
• Block Bitmap (disk & memory)
– 管理 free disk blocks 。
7
8. JOS file system item(2/2)
• File Meta-data
– 保存”檔案”的必要資訊,檔名、大小、 以及
block pointer(direct/indirect) 。
• Directories versus Regular Files
– Directories 主要保存多個 file struct 。
– Regular Files 保存 data block 。
8
9. JOS file system struct overview
User access
File/Directory struct level
Block struct level
Disk struct (sector) level
9
10. Block N -1
File/directory
data blocks
t b
siN
l B
skc oN
Free Block
Bitmap
: ez s pa m B
ti
Block 2
: ez s ks dl a o T
h o k c o b hguon E
i
t
Spuerblock Block 1
i i
BootSector Block 0
l
10
Block struct level
t
12. JOS file system
• Disk access
– user-level file system - IDE disk driver 實做於 user
space 。
– polling vs interrupt-driven 。
• The Block Cache
– 運用虛擬記憶體的特性,當程式存取檔案時轉換為對
其地址空間做存取 (0x10000000 - 0xD000000 ,
3GB) 。
• File operations
– Open/Read/Write ,基本檔案操作。
12
13. Format a file system (1/2)
#fsformat fs.img 1024 init newmotd motd
struct File struct File
/ init
dir reg
struct File data block
data block
struct File
init
struct File mode
reg
newmode reg ……
reg
13
=> 請參閱 source code (fsformat.c)
14. Format a file system (2/2)
#fs.img (block view)
struct
struct File File
Name : “init”
21
Name : “/” Size : 54321 22
11
Size : 54321 12 23
Direct block pointers: 13 struct File
14
struct File Name : “newmode”
Size : 54321
Name : “init”
Size : 54321
35
36
52 37
53
使用 block bitmap 紀錄 block 38
。
54
分配狀況 ( 不一定連續分配 ) 14
55
15. JOS file system service
• Part1 : File system struct
– In-memory and On-disk struct
• Part 2: Client/Server file system access
– remote procedure call (RPC) base on IPC +
process
15