Linux File System Li-Shien Chen
基本概念
檔案屬性
Inode
Link 何謂連結? 將檔案取另一個名字 Hardlink ln /a/os1.txt /b/os2.txt
Hard Link
Hard Link 缺點 不許應用在目錄上 會造成循環連結 不能跨檔案系統 會使得Inode number不唯一
Symbolic Link Ln –s /a/os1.txt /b/os2.txt 與Hard Link的不同 有自己的Inode節點
Symbolic Link
傳統Unix系統 支援某一種特定檔案系統 無法存取其他的檔案系統 如何同時支援多個檔案系統
傳統Unix系統缺點
方案一
方案一的問題 Kernel與檔案系統相依程度太高 造成應用程式的負擔 方案二 :為kernel與檔案系統提供一個標 準的連結介面
方案二
Linux File System 真正的檔案系統 Cache Virtual File System Switch(VFS) 如Ext2,FAT…等等 Cache 加快讀取檔案系統的速度 Virtual File System Switch(VFS) Kernel與真正檔案系統的介面
Linux File System 架構
The Buffer Cache
The States of the Cache Locked Dirty Buffers that are locked, waiting to be written Dirty Dirty buffers. These contain new, valid data, and will be written but so far have not been scheduled to write
The States of the Cache Share Unshared Shared buffers Buffers that were once shared but which are now not shared
檔案系統的表示 Disk and Patition Layout 在Linux裡, 檔案放的位置是以一個partition為單位的 在VFS裡, 每一個檔案系統是由其superblock來表示的
VFS Superblock Super_block結構 struct list_heads s_list; kdev_t s_dev; unsigned long s_blocksize; unsigned char s_blocksize_bits; unsigned char s_rd_only; unsigned char s_dirt;
VFS Superblock struct file_system_type *type; unsigned long s_flags; unsigned long s_magic; struct dentry *s_root; struct super_operations *s_op
檔案的表示 使用者觀點: 絕對路徑 如 usr/src/linux/fs/file.c VFS:以vfs inode(vnode)來表示
VFS inode Device Inode Number Mode User id times block size inode operations a pointer to a block of routine addresses count lock dirty file system specific
Registering the File Systems Build Linux kernel : supported file systems Build file systems as module
掛上檔案系統 利用 mount 或 mount_root() 利用read_super()來初始superblock $mount -t ext2 /dev/hda3 /mnt
Example
Mounting a File System $mount -t iso9600 -o ro /dev/cdrom /mnt/cdrom Search for the file system types( iso9600) Allocate a VFS superblock and pass it the mount information to the superblock read routine
A Mounted File System
Unmount a File System Check whether someone is using the FS Check if the File System is dirty write back Return VFS superblock to kernel’s pool vfsmount is unlinked from vfsmntlist
Reference The Linux Kernel Linux 核心研究篇 http://www.linpus.com.tw http://cat.ice.ntnu.edu.tw