25
25 1 Embedded Software Lab. Sungkyunkwan University Embedded Software Lab. Dongkun Shin 전공핵심실습1:운영체제론 Chapter 7. Virtual File System(VFS)

Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

25

1

Embedded Software Lab.

Sungkyunkwan University

Embedded Software Lab.

Dongkun Shin

전공핵심실습1:운영체제론Chapter 7. Virtual File System(VFS)

Page 2: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

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

Page 3: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

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

Page 4: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

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

Page 5: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

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?

Page 6: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

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

Page 7: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

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()

Page 8: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

25

8

Embedded Software Lab.

• Show mounted file systems– $ sdb root on

– $ sdb shell

– # mount

VFS in Tizen

Page 9: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

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

Page 10: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

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

Page 11: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

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

Page 12: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

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

Page 13: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

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

Page 14: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

25

14

Embedded Software Lab.

super_block: Code

* include/linux/fs.h

Page 15: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

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

Page 16: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

25

16

Embedded Software Lab.

inode: Code

* include/linux/fs.h

Page 17: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

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

Page 18: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

25

18

Embedded Software Lab.

file: Code

* include/linux/fs.h

Page 19: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

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

Page 20: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

25

20

Embedded Software Lab.

dentry: Code

* include/linux/dcache.h

Page 21: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

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

Page 22: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

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

Page 23: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

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

Page 24: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

25

24

Embedded Software Lab.

VFS System Call: read()

Check if the file is locked

Page 25: Introduction to Tizen Platform - SKKUnyx.skku.ac.kr/wp-content/uploads/2016/03/Lecture7-Week... · 2016-05-10 · inode 8 /home/ Directory file a.out 9 inode 9 inode 10 inode 11 inode

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에 업로드되는 공고문 참조

과제