Linux File System LiShien Chen Outline Linux File

  • Slides: 19
Download presentation
Linux File System Li-Shien Chen

Linux File System Li-Shien Chen

Outline • Linux File System Concepts • Trace Code

Outline • Linux File System Concepts • Trace Code

Linux File System Architecture • 真正的檔案系統 – 如Ext 2, Proc, FAT…等等 • Cache –

Linux File System Architecture • 真正的檔案系統 – 如Ext 2, Proc, FAT…等等 • Cache – 加快讀取檔案系統的速度 • Virtual File System Switch(VFS) – Kernel與真正檔案系統的介面

Linux File System 架構

Linux File System 架構

VFS Superblock • Super_block結構 kdev_t unsigned long unsigned char struct inode s_dev; s_blocksize_bits; s_rd_only;

VFS Superblock • Super_block結構 kdev_t unsigned long unsigned char struct inode s_dev; s_blocksize_bits; s_rd_only; *s_convered; *s_mounted;

VFS Superblock struct unsigned struct union{ struct }u; file_system_type *type; long s_magic; super_operations *s_op

VFS Superblock struct unsigned struct union{ struct }u; file_system_type *type; long s_magic; super_operations *s_op ext 2_sb_info nfs_sb_info …………. ext 2_sb; nfs_sb;

VFS inode • inode結構 kdev_t unsigned long umode_t uid_t unsigned long unsigned short i_dev;

VFS inode • inode結構 kdev_t unsigned long umode_t uid_t unsigned long unsigned short i_dev; i_ino; i_mode; i_uid; i_blksize; i_count;

VFS inode unsigned char i_lock; unsigned char i_dirt; struct inode_operations *i_op union{ struct ext

VFS inode unsigned char i_lock; unsigned char i_dirt; struct inode_operations *i_op union{ struct ext 2_inode_info ext 2_i; struct nfs_inode_info nfs_i; …………. }u;

Trace Code • Registering the File Systems – 當檔案系統像VFS註冊後,核心就能管理該 類型的檔案系統 • Mounting Root File

Trace Code • Registering the File Systems – 當檔案系統像VFS註冊後,核心就能管理該 類型的檔案系統 • Mounting Root File System • Mounting File System – 把含有該檔案的檔案系統掛上便可存取檔案 • Opening the File • Writing the File

Registering the File Systems • 將每個類別為file_system_type的結構填好,並 加到一個單連結串列 struct file_system_type { struct super_block *(*read_super)(); const

Registering the File Systems • 將每個類別為file_system_type的結構填好,並 加到一個單連結串列 struct file_system_type { struct super_block *(*read_super)(); const char *name; int requires_dev; struct file_system_type *next; }; • Trace code : init_name_fs() calls register_file_system()

Registered File Systems

Registered File Systems

Mounting Root File System • 利用該檔案系統實作的read_super() 來填好其super_block結構 • Trace code : 1. mount_root() calls

Mounting Root File System • 利用該檔案系統實作的read_super() 來填好其super_block結構 • Trace code : 1. mount_root() calls do_mount_root() 2. do_mount_root() calls read_super() 3. read_super() calls ext 2_read_super() 4. ext 2_read_super() returns the superblock

A Mounted Root File System

A Mounted Root File System

Mounting File System • 與Mounting Root File System 相似 • Trace code : –

Mounting File System • 與Mounting Root File System 相似 • Trace code : – sys_mount() implements mount system call 1. sys_mount() calls do_mount() 2. do_mount() calls read_super() 3. read_super() calls ext 2_read_super() 4. ext 2_read_super() returns the superblock

Opening the File • Trace Code – sys_open implements open() system call – sys_open()

Opening the File • Trace Code – sys_open implements open() system call – sys_open() calls do_open()

Writing the File • Opening the file • Trace code – sys_write() implements write()

Writing the File • Opening the file • Trace code – sys_write() implements write() system call – sys_write() calls ext 2_file_write()