SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
A journey of file system
on JOS
Name :wayling
Date: 2012/09/11
Who am I?
●JuluOSDev 星系001
● virtual file system (2011-12-20 )
● http://www.juluos.org/home/files
● 出沒於TOSSUG & H4
●waylingII@gmail.com
wayling
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 Morris
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
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
The File System
●File system是memory跟disk操作結合
而成的,意及我們在存取檔案時,memory
跟disk都需要有對應的struct來存放表示。
●static + dynamic組成file system
● Static : 格式化硬碟成特有檔案系統格式 ex:
ext2、ext3。
● Dynamic :runtime時作業系統保存對應的資料
結構,藉此操作disk,提供檔案操作給使用者。
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 。
JOS file system item(2/2)
●File Meta-data
● 保存”檔案”的必要資訊,檔名、大小、 以及
block pointer(direct/indirect) 。
●Directories versus Regular Files
● Directories主要保存多個file struct 。
● Regular Files保存data block 。
JOS file system struct overview
File/Directory struct level
Block struct level
Disk struct (sector) level
User access
File/directory
data blocks
Free Block
Bitmap
Spuerblock
BootSector Block 0
Block 1
Block 2
Totaldisksize:NBlocks
Bitmapsize:
EnoughblocktoholdNbits
Block N -1
Block struct level
struct File
(256 bytes)
Name : “foo”
Size : 54321
Direct block pointers:
(10)
Indirect block pointer :
Indirect block
(4096 bytes)
(1024)
Block 0
Block 1
Block 2
Block 3
Block 4
Block 5
Block 6
Block 9
Block 10
Block 11
Block 12
…..
File data blocks
(4096 bytes each)
File/Directory struct level
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 ,基本檔案操作。
Format a file system (1/2)
#fsformat fs.img 1024 init newmotd motd
struct File
struct File
struct File
struct File
struct File
/
init
newmode
mode
init
dir
reg
reg
reg
reg
data block
data block
……
=>請參閱source code
struct File
Name : “/”
Size : 54321
Direct block pointers:
11
12
13
14
struct File
struct File
Name : “init”
Size : 54321
Name : “newmode”
Size : 54321
struct File
Name : “init”
Size : 54321
21
22
23
35
36
37
38
52
53
54
55
Format a file system (2/2)
#fs.img (block view)
使用block bitmap紀錄block
分配狀況(不一定連續分配) 。
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
JOS’s file overview
●Server
● server.c
● Server 端主體,處理clinet請求。(JOS定義八種檔案操作請求)
● FSREQ_OPEN, 、FSREQ_SET_SIZE 、 FSREQ_READ
● FSREQ_WRITE 、 FSREQ_STAT 、 FSREQ_FLUSH
● FSREQ_REMOVE 、 FSREQ_SYNC
● fs.c
● File system主體,處理block、File操作。
● bc.c
● Block cache,類似copy on write 的機制。
●Client
● file.c
● Client端主要函式,對server發起IPC操作。
● fd.c
● file description (fd)是server跟client間的橋樑。
Client/Server file system access
●JOS使用IPC機制實作client/server架構的file
system service。
●File system Server (FSServ) :
● 作為user space porcess,提供檔案操作服務, 藉由IPC
提供其他process所需之請求。
●Client :
● 透過FSServ來存取檔案。
●FSServ 特徵:
● Process id 1。
● Block cache。
● 回應client的IPC request。
FSServ Block cache
3GB
0x10000000
0xD000000
FSServ address space
1
2
1.申請實體記憶體page。
2.讀取block大小到記憶體中。
(4096byte = 512 byte *8)
JOS IPC (Inter-process
communication ) (1/2)
●void ipc_send(envid_t to_env, uint32_t val,
void *pg, int perm)
→static int sys_ipc_try_send(envid_t envid,
uint32_t value, void *srcva, unsigned perm)
對某個process傳送資料(32bit) ,也可
指定一個地址(小於UTOP) ,跟對方
process共享該page。
=>請參閱source code (ipc.c &
JOS IPC (Inter-process
communication ) (2/2)
●int32_t ipc_recv(envid_t *from_env_store,
void *pg, int *perm_store)
→static int sys_ipc_recv(void *dstva)
=>請參閱source code (ipc.c &
Blocking自己等待對方把資料傳送完
畢。可指定地址(小於UTOP) ,決定要跟
傳送者共享page的位置。
Client (fs.c)
// Send an inter-environment request to the file server, and wait for
// a reply.
static int fsipc(unsigned type, void *dstva)
{
if (debug)
{
…….
}
ipc_send(envs[1].env_id, type, &fsipcbuf, PTE_P | PTE_W | PTE_U);
return ipc_recv(NULL, dstva, NULL);
}
封裝IPC成一個fsipc給client使用。
IPC訊息格式定義於 fs.h。
=>請參閱source code (file.c &
FSServ (serv.c)
●初始OpenFile table。 //用於管理FSServ所開啟的檔案。
●struct OpenFile opentab[MAXOPEN] = {
{ 0, 0, 1, 0 }
};
●struct OpenFile {
uint32_t o_fileid;
struct File *o_file;
int o_mode;
struct Fd *o_fd;
};
=>請參閱source code (serv.
FSServ Client
fd
File
fd
FSREQ_OPEN
ipc_send
ipc_send
ipc_recv ipc_recv
1
1
2
3
3
0xD0000000
0xD0000000
0x0ffff000
1.Client傳送一個IPC request 讓FSServ接收,
request中夾帶路徑,並申請fd待,FSServ回
應fd page,用以共享page。
2.FSServ依路徑開啟File struct。
3.回應Client,並把開啟的fd address map到
clinet的fd上。
共享page
=>請參閱source code (serv.
FSServ Client
fd
File
FSREQ_WRITE
ipc_send
ipc_sendipc_recv ipc_recv
1
1
2
3 3
0xD0000000
0x0ffff000
1.Client傳送一個IPC request讓FSServ接收,
request中夾帶file id及將寫入的資料buffer。
2.將資料buffer寫入檔案的block中。
3.回應Client,將file pointer位址返回。
=>請參閱source code (serv.
fd
JOS file system RPC
●RPC base on IPC (ex : call file system server read
a file)
read( )
lib/fd.c
devfile_read ( )
lib/file.c
fsipc ( )
lib/file.c
ipc_send ( )
file_read ( )
fs/fs.c
serve_read ( )
fs/serv.c
serve ( )
fs/serv.c
ipc_recv( )
RPC mechanism
JOS IPC
Regular env FSServ env
Q&A
Reference
●[mit 6.828 lab 5]
http://pdos.csail.mit.edu/6.
828/2011/labs/lab5/

Weitere ähnliche Inhalte

Was ist angesagt?

Linux 的檔案系統格式介紹
Linux 的檔案系統格式介紹Linux 的檔案系統格式介紹
Linux 的檔案系統格式介紹Ma Yu-Hui
 
Virtual file system (VFS)
Virtual file system (VFS)Virtual file system (VFS)
Virtual file system (VFS)Waylin Ch
 
深入学习Mongo db
深入学习Mongo db深入学习Mongo db
深入学习Mongo dbLucien Li
 
4, files & folders
4, files & folders4, files & folders
4, files & foldersted-xu
 
云存储系统设计
云存储系统设计云存储系统设计
云存储系统设计drewz lin
 

Was ist angesagt? (6)

Linux 的檔案系統格式介紹
Linux 的檔案系統格式介紹Linux 的檔案系統格式介紹
Linux 的檔案系統格式介紹
 
Virtual file system (VFS)
Virtual file system (VFS)Virtual file system (VFS)
Virtual file system (VFS)
 
深入学习Mongo db
深入学习Mongo db深入学习Mongo db
深入学习Mongo db
 
Ubuntu
UbuntuUbuntu
Ubuntu
 
4, files & folders
4, files & folders4, files & folders
4, files & folders
 
云存储系统设计
云存储系统设计云存储系统设计
云存储系统设计
 

Ähnlich wie 0911 juluosdev a_journey_of_filesystem_on_jos

Device Driver - Chapter 3字元驅動程式
Device Driver - Chapter 3字元驅動程式Device Driver - Chapter 3字元驅動程式
Device Driver - Chapter 3字元驅動程式ZongYing Lyu
 
Mysql体系结构及原理(innodb)公开版
Mysql体系结构及原理(innodb)公开版Mysql体系结构及原理(innodb)公开版
Mysql体系结构及原理(innodb)公开版longxibendi
 
Big Java, Big Data
Big Java, Big DataBig Java, Big Data
Big Java, Big DataKuo-Chun Su
 
第11讲 管理Cisco互联网络
第11讲 管理Cisco互联网络第11讲 管理Cisco互联网络
第11讲 管理Cisco互联网络F.l. Yu
 
intro syslog syslogng
intro syslog syslogngintro syslog syslogng
intro syslog syslogngjuruntang
 
Syslog Ng
Syslog NgSyslog Ng
Syslog Ngflytod
 
syslog&syslog-ng
syslog&syslog-ngsyslog&syslog-ng
syslog&syslog-ngjurntang
 
Clonezilla tutorial.v7
Clonezilla tutorial.v7Clonezilla tutorial.v7
Clonezilla tutorial.v7hs1250
 
MySQL新技术探索与实践
MySQL新技术探索与实践MySQL新技术探索与实践
MySQL新技术探索与实践Lixun Peng
 
Ext4 Bigalloc report public
Ext4 Bigalloc report publicExt4 Bigalloc report public
Ext4 Bigalloc report publicHao(Robin) Dong
 
Shadow_Hunter Rootkit windows7 xcon2011 Scott
Shadow_Hunter Rootkit windows7 xcon2011 Scott Shadow_Hunter Rootkit windows7 xcon2011 Scott
Shadow_Hunter Rootkit windows7 xcon2011 Scott Sc0tt
 
20030623 linuxbasic and-security
20030623 linuxbasic and-security20030623 linuxbasic and-security
20030623 linuxbasic and-security建融 黃
 
「電腦硬體」教學示例與研討
「電腦硬體」教學示例與研討「電腦硬體」教學示例與研討
「電腦硬體」教學示例與研討David Tang
 
Oda安装 恢复步骤
Oda安装 恢复步骤Oda安装 恢复步骤
Oda安装 恢复步骤n-lauren
 
Mr&ueh数据库方面
Mr&ueh数据库方面Mr&ueh数据库方面
Mr&ueh数据库方面Tianwei Liu
 
使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡Cary Yang
 

Ähnlich wie 0911 juluosdev a_journey_of_filesystem_on_jos (20)

Tcfsh bootcamp day2
 Tcfsh bootcamp day2 Tcfsh bootcamp day2
Tcfsh bootcamp day2
 
Develop Your Own Operating System
Develop Your Own Operating SystemDevelop Your Own Operating System
Develop Your Own Operating System
 
Device Driver - Chapter 3字元驅動程式
Device Driver - Chapter 3字元驅動程式Device Driver - Chapter 3字元驅動程式
Device Driver - Chapter 3字元驅動程式
 
Mysql体系结构及原理(innodb)公开版
Mysql体系结构及原理(innodb)公开版Mysql体系结构及原理(innodb)公开版
Mysql体系结构及原理(innodb)公开版
 
Sth About SSD
Sth About SSDSth About SSD
Sth About SSD
 
Big Java, Big Data
Big Java, Big DataBig Java, Big Data
Big Java, Big Data
 
第11讲 管理Cisco互联网络
第11讲 管理Cisco互联网络第11讲 管理Cisco互联网络
第11讲 管理Cisco互联网络
 
intro syslog syslogng
intro syslog syslogngintro syslog syslogng
intro syslog syslogng
 
Syslog Ng
Syslog NgSyslog Ng
Syslog Ng
 
syslog&syslog-ng
syslog&syslog-ngsyslog&syslog-ng
syslog&syslog-ng
 
Clonezilla tutorial.v7
Clonezilla tutorial.v7Clonezilla tutorial.v7
Clonezilla tutorial.v7
 
IoTDB Ops
IoTDB OpsIoTDB Ops
IoTDB Ops
 
MySQL新技术探索与实践
MySQL新技术探索与实践MySQL新技术探索与实践
MySQL新技术探索与实践
 
Ext4 Bigalloc report public
Ext4 Bigalloc report publicExt4 Bigalloc report public
Ext4 Bigalloc report public
 
Shadow_Hunter Rootkit windows7 xcon2011 Scott
Shadow_Hunter Rootkit windows7 xcon2011 Scott Shadow_Hunter Rootkit windows7 xcon2011 Scott
Shadow_Hunter Rootkit windows7 xcon2011 Scott
 
20030623 linuxbasic and-security
20030623 linuxbasic and-security20030623 linuxbasic and-security
20030623 linuxbasic and-security
 
「電腦硬體」教學示例與研討
「電腦硬體」教學示例與研討「電腦硬體」教學示例與研討
「電腦硬體」教學示例與研討
 
Oda安装 恢复步骤
Oda安装 恢复步骤Oda安装 恢复步骤
Oda安装 恢复步骤
 
Mr&ueh数据库方面
Mr&ueh数据库方面Mr&ueh数据库方面
Mr&ueh数据库方面
 
使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡
 

0911 juluosdev a_journey_of_filesystem_on_jos

  • 1. A journey of file system on JOS Name :wayling Date: 2012/09/11
  • 2. Who am I? ●JuluOSDev 星系001 ● virtual file system (2011-12-20 ) ● http://www.juluos.org/home/files ● 出沒於TOSSUG & H4 ●waylingII@gmail.com wayling
  • 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 Morris
  • 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
  • 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
  • 6. The File System ●File system是memory跟disk操作結合 而成的,意及我們在存取檔案時,memory 跟disk都需要有對應的struct來存放表示。 ●static + dynamic組成file system ● Static : 格式化硬碟成特有檔案系統格式 ex: ext2、ext3。 ● Dynamic :runtime時作業系統保存對應的資料 結構,藉此操作disk,提供檔案操作給使用者。
  • 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 。
  • 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 。
  • 9. JOS file system struct overview File/Directory struct level Block struct level Disk struct (sector) level User access
  • 10. File/directory data blocks Free Block Bitmap Spuerblock BootSector Block 0 Block 1 Block 2 Totaldisksize:NBlocks Bitmapsize: EnoughblocktoholdNbits Block N -1 Block struct level
  • 11. struct File (256 bytes) Name : “foo” Size : 54321 Direct block pointers: (10) Indirect block pointer : Indirect block (4096 bytes) (1024) Block 0 Block 1 Block 2 Block 3 Block 4 Block 5 Block 6 Block 9 Block 10 Block 11 Block 12 ….. File data blocks (4096 bytes each) File/Directory struct level
  • 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 ,基本檔案操作。
  • 13. Format a file system (1/2) #fsformat fs.img 1024 init newmotd motd struct File struct File struct File struct File struct File / init newmode mode init dir reg reg reg reg data block data block …… =>請參閱source code
  • 14. struct File Name : “/” Size : 54321 Direct block pointers: 11 12 13 14 struct File struct File Name : “init” Size : 54321 Name : “newmode” Size : 54321 struct File Name : “init” Size : 54321 21 22 23 35 36 37 38 52 53 54 55 Format a file system (2/2) #fs.img (block view) 使用block bitmap紀錄block 分配狀況(不一定連續分配) 。
  • 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
  • 16. JOS’s file overview ●Server ● server.c ● Server 端主體,處理clinet請求。(JOS定義八種檔案操作請求) ● FSREQ_OPEN, 、FSREQ_SET_SIZE 、 FSREQ_READ ● FSREQ_WRITE 、 FSREQ_STAT 、 FSREQ_FLUSH ● FSREQ_REMOVE 、 FSREQ_SYNC ● fs.c ● File system主體,處理block、File操作。 ● bc.c ● Block cache,類似copy on write 的機制。 ●Client ● file.c ● Client端主要函式,對server發起IPC操作。 ● fd.c ● file description (fd)是server跟client間的橋樑。
  • 17. Client/Server file system access ●JOS使用IPC機制實作client/server架構的file system service。 ●File system Server (FSServ) : ● 作為user space porcess,提供檔案操作服務, 藉由IPC 提供其他process所需之請求。 ●Client : ● 透過FSServ來存取檔案。 ●FSServ 特徵: ● Process id 1。 ● Block cache。 ● 回應client的IPC request。
  • 18. FSServ Block cache 3GB 0x10000000 0xD000000 FSServ address space 1 2 1.申請實體記憶體page。 2.讀取block大小到記憶體中。 (4096byte = 512 byte *8)
  • 19. JOS IPC (Inter-process communication ) (1/2) ●void ipc_send(envid_t to_env, uint32_t val, void *pg, int perm) →static int sys_ipc_try_send(envid_t envid, uint32_t value, void *srcva, unsigned perm) 對某個process傳送資料(32bit) ,也可 指定一個地址(小於UTOP) ,跟對方 process共享該page。 =>請參閱source code (ipc.c &
  • 20. JOS IPC (Inter-process communication ) (2/2) ●int32_t ipc_recv(envid_t *from_env_store, void *pg, int *perm_store) →static int sys_ipc_recv(void *dstva) =>請參閱source code (ipc.c & Blocking自己等待對方把資料傳送完 畢。可指定地址(小於UTOP) ,決定要跟 傳送者共享page的位置。
  • 21. Client (fs.c) // Send an inter-environment request to the file server, and wait for // a reply. static int fsipc(unsigned type, void *dstva) { if (debug) { ……. } ipc_send(envs[1].env_id, type, &fsipcbuf, PTE_P | PTE_W | PTE_U); return ipc_recv(NULL, dstva, NULL); } 封裝IPC成一個fsipc給client使用。 IPC訊息格式定義於 fs.h。 =>請參閱source code (file.c &
  • 22. FSServ (serv.c) ●初始OpenFile table。 //用於管理FSServ所開啟的檔案。 ●struct OpenFile opentab[MAXOPEN] = { { 0, 0, 1, 0 } }; ●struct OpenFile { uint32_t o_fileid; struct File *o_file; int o_mode; struct Fd *o_fd; }; =>請參閱source code (serv.
  • 23. FSServ Client fd File fd FSREQ_OPEN ipc_send ipc_send ipc_recv ipc_recv 1 1 2 3 3 0xD0000000 0xD0000000 0x0ffff000 1.Client傳送一個IPC request 讓FSServ接收, request中夾帶路徑,並申請fd待,FSServ回 應fd page,用以共享page。 2.FSServ依路徑開啟File struct。 3.回應Client,並把開啟的fd address map到 clinet的fd上。 共享page =>請參閱source code (serv.
  • 24. FSServ Client fd File FSREQ_WRITE ipc_send ipc_sendipc_recv ipc_recv 1 1 2 3 3 0xD0000000 0x0ffff000 1.Client傳送一個IPC request讓FSServ接收, request中夾帶file id及將寫入的資料buffer。 2.將資料buffer寫入檔案的block中。 3.回應Client,將file pointer位址返回。 =>請參閱source code (serv. fd
  • 25. JOS file system RPC ●RPC base on IPC (ex : call file system server read a file) read( ) lib/fd.c devfile_read ( ) lib/file.c fsipc ( ) lib/file.c ipc_send ( ) file_read ( ) fs/fs.c serve_read ( ) fs/serv.c serve ( ) fs/serv.c ipc_recv( ) RPC mechanism JOS IPC Regular env FSServ env
  • 26. Q&A
  • 27. Reference ●[mit 6.828 lab 5] http://pdos.csail.mit.edu/6. 828/2011/labs/lab5/