Upload
others
View
9
Download
0
Embed Size (px)
Citation preview
25
1
Embedded Software Lab.
Sungkyunkwan University
Embedded Software Lab.
Dongkun Shin
전공핵심실습1:운영체제론Chapter 7. Virtual File System(VFS)
25
2
Embedded Software Lab.
• File System
• Virtual File System(VFS)
• Common File Model
• VFS File Structures– super_block, inode, file, dentry
• VFS System Calls– open, close, read
Contents
25
3
Embedded Software Lab.
• File path inode number inode block address– Example: open a file “/home/a.out”
– Generally, the root directory’s inode number is fixed as 2 in ext
File System
inode 2root
directory i_block
name inode
bin 6dev 10lib 13home 7
/ Directory file
7 / inode per bg = bg 17 mod inode per bg = 3 enry of Inode table
inode 5 inode 6 inode 7 inode 8
/home/ Directory file
a.out 9
inode 9 inode 10 inode 11 inode 12
Success
a.out
Disk
25
4
Embedded Software Lab.
• Translation between file name & block address
• File system metadata management
• Directory structure management
• FCB (File Control Block) management– File Control Block: structure describing how to store file
information on target storage
• Security
• Recovery
File System Features
25
5
Embedded Software Lab.
• There are many file systems supported by Linux.
• Disk file systems– FAT, exFAT, NTFS, HFS, HFS+, ext2, ext3, ext4, btrfs, ZFS,
ReiserFS, UDF, …
• Flash file systems– JIFFS2, YAFFS, LogFS, F2FS, …
• Database file systems– HDFS, GoogleFS, …
• Special file systems– sysfs, devfs, procfs, tmpfs(ramdisk), …
• Common container of file systems is required.
Why Virtual File System?
25
6
Embedded Software Lab.
• sysfs– provide information
about various kernel subsystems, hardware devices and device drivers
• devfs– provide simple
interfaces to peripheral devices
• procfs– present information
about processes
Special File Systems
25
7
Embedded Software Lab.
• Common interface for accessing file systems to user applications
• Abstraction/Container of file systems
• Example: write() system call
Virtual File System (VFS)
Lower LayerFile System LayerUser Space Kernel Space
User Application
I/O System Calls VFS
ext4
f2fs
nfs
proc
Block Device
Network
write()ext4_file_write_iter()
f2fs_file_write_iter()
25
8
Embedded Software Lab.
• Show mounted file systems– $ sdb root on
– $ sdb shell
– # mount
VFS in Tizen
25
9
Embedded Software Lab.
• Linux kernel cannot hardcode a particular function to handle an operation such as open() or read() must use a pointer for each operation
• Example– open system call sys_open() file->f_op->open(…); f2fs_file_open()
or ext4_file_open()
Common File Model
25
10
Embedded Software Lab.
• VFS introduces a common file model to represent all supported filesystems
Common File Model
• Main data structures:– super_block
• information about mounted filesystem
– inode• information about a specific
file
– file• information about interaction
b/w opened file and process
– dentry• information about the linking
of a directory entry with the corresponding file
25
11
Embedded Software Lab.
super_block
task_structmm_struct
task_struct
Directory Entry Hierarchy
inodedentry
dentry
dentry
dentry
dentry
vm_area_structfile
mm_structfile
filevm_area_struct
namespace
vm_area_struct
vfsmount
vfsmount
vfsmount
super_block
super_block
block_device
address_space
inode
address_space
dentry ...
VFS Data Structures
Other file system instance
Other file system instance
A file system instance
Mount entry
Opened file
Process
Virtual memory per process
Virtual memory area
Directory entry
File metadata
Block device
Linking process & file
25
12
Embedded Software Lab.
super_block
task_structmm_struct
task_struct
Directory Entry Hierarchy
inodedentry
dentry
dentry
dentry
dentry
vm_area_structfile
mm_structfile
filevm_area_struct
namespace
vm_area_struct
vfsmount
vfsmount
vfsmount
super_block
super_block
block_device
address_space
inode
address_space
dentry ...
VFS Data Structures (Example)
inode #2131
/opt
/opt/usr
/
/
/bin
/a.txt
/bin/cp
/bin/rm
inode #2143
sh (pid 2476)
systemcallapp (pid 1091)
/ (ext4)
/opt (ext4)
/opt/usr (ext4)
/dev/mmcblk0p25
0x43fe5000~0x43ff5000
0x43fe5000~0x43ff5000
0x52cdab12~0x52ceab12
25
13
Embedded Software Lab.
• Metadata of file system instant
• Relations with:– inodes, ‘dentry’s, ‘vfsmount’s
super_block: Definition & Relations
super_blockEntry Hierarchy
inode
dentry
dentry
dentry
dentry
dentry
namespace
vfsmount
vfsmount
vfsmountsuper_block
super_block
block_device
inode
task_struct
task_struct
file
file
file
25
14
Embedded Software Lab.
super_block: Code
* include/linux/fs.h
25
15
Embedded Software Lab.
• File’s metadata for VFS
• Relations with:– super_block
– dentry
– address_space
inode: Definition & Relations
super_blockEntry Hierarchy
inode
dentry
dentry
dentry
dentry
dentry
address_space
inode
address_space
25
16
Embedded Software Lab.
inode: Code
* include/linux/fs.h
25
17
Embedded Software Lab.
• File opened by a process
• Relations with:– super_block
– address_space
– task_struct, files_struct, fdtable(Referenced)
file: Definition & Relations
super_block
task_struct
mm_struct
inodedentry
vm_area_structfile
address_space
files_struct
fdtable
25
18
Embedded Software Lab.
file: Code
* include/linux/fs.h
25
19
Embedded Software Lab.
• File/directory’s entry point
• Relations with:– super_block
– inode
– child dentry
dentry: Definition & Relations
super_blockEntry Hierarchy
inode
dentry
dentry
dentry
address_space
inode
address_space
root dentry
dentry
dentry
25
20
Embedded Software Lab.
dentry: Code
* include/linux/dcache.h
25
21
Embedded Software Lab.
VFS System Call: open()
fs/open.cSYSCALL_DEFINE3(open, const char __user *, filename, int, flags, umode_t, mode)
do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
Set open flag with POSIX parameter(ex. O_RDONLY, O_WRONLY, …)
Convert string to struct filename
Invoke ‘__alloc_fd()’ to Allocate a File Descriptor
Update file descriptor table
Return file descriptor of opened file
25
22
Embedded Software Lab.
VFS System Call: close()
/fs/open.cSYSCALL_DEFINE1(close, unsigned int, fd)
int __close_fd(struct files_struct *files, unsigned fd)
int filp_close(struct file *filp, fl_owner_t id)
If flush method exists,Invoke it
Remove file lock
Free file object
25
23
Embedded Software Lab.
VFS System Call: read()
SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
ssize_t __vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)
Invoke filef_opread() or filef_opread_iter()
fs/read_write.c
25
24
Embedded Software Lab.
VFS System Call: read()
Check if the file is locked
25
25
Embedded Software Lab.
• VFS의 자료 구조(구조체)들의 소스 코드를 분석하는Report 작성– 조사 대상 (코드 위치: include/linux/dcache.h, include/linux/fs.h)
• super_block, inode, file, dentry
• super_operations, inode_operations, file_operations, dentry_operations
– 각 구조체의 멤버 변수, 멤버 함수의 역할 분석
– 코드의 모든 line 분석
• 코드 분석 시 막히는 사항은 조교에게 문의– [email protected]
• 제출 기한: 5월 16일 (월) 23:59까지– 자세한 사항은 i-campus에 업로드되는 공고문 참조
과제