Linux File System 文件系统 VFS VFS的作用 基于ⅤFS的文件访问 VFS重要数据结构 文件系统的注册与安装 ext2、ext3文件系统 文件操作 proc文件系统 CRAMFS文件系统
1 Linux File System • 文件系统 • VFS VFS的作用 基于VFS的文件访问 VFS重要数据结构 • 文件系统的注册与安装 • ext2、ext3文件系统 • 文件操作 • proc文件系统 • CRAMFS文件系统
各种各样的文件系统 o Windows Fat16Fat32. NTFS o传统UNIX:UFS( Unix File System) OBSD文件系统FFS( Fast File system) o Proc File system:只存在于内存中 o Linux File system ext2( is first introduced in kernel 2.0.x reiserfs( is first introduced in kernel 2.2. x) ext3( is first introduced in kernel 2. 4.x, default in RedHat now) xfs (from SGI) Jfs (from IBM) o嵌入式小型文件系统 O CRAMFS O JFFS2
2 各种各样的文件系统 Windows FAT16,FAT32, NTFS 传统UNIX: UFS (Unix File System) BSD文件系统FFS(Fast File System) Proc File System:只存在于内存中 Linux File System – ext2 ( is first introduced in kernel 2.0.x ) – reiserfs ( is first introduced in kernel 2.2.x ) – ext3 ( is first introduced in kernel 2.4.x ,default in RedHat now) – xfs (from SGI ) – Jfs (from IBM ) 嵌入式小型文件系统 CRAMFS JFFS2
inux文件系统目录布局 To comply with FSStND(File System STaNDard first of mount point in linux lete -keep linux default configuration /boot -keep important linux booting files(can be a separate file system) /bin -Essential command binaries for both root and ord. users /sbin -Essential system binaries for administrator /dev -keep all device files /usr -keep all user binary and X library /home -keep user home directory /proc pseudo file system for tracking running process and state of linux system /var -keeping mail, log file and printer spooling /ib -contain shared library that is required by system program /tmp -contain system temporary file /opt -Add-on application software packages
3 linux文件系统目录布局 To comply with FSSTND(File System STaNDard): / - first of mount point in linux /etc - keep linux default configuration /boot - keep important linux booting files(can be a separate file system) /bin - Essential command binaries for both root and ord. users /sbin - Essential system binaries for administrator /dev - keep all device files /usr - keep all user binary and X library /home - keep user home directory /proc - is pseudo file system for tracking running process and state of linux system /var - keeping mail, log file and printer spooling /lib - contain shared library that is required by system program /tmp - contain system temporary file /opt - Add-on application software packages
UNIX文件系统文件类型 Directory -- catalogue of file name Normal file --> format of data source file text file Symbolic link--> a pointer to another file Special file --> use for device controller in kernel Named pipe--> communication channel which can be used by serveral processes(may be irrelevant) in order to exchange data
4 UNIX文件系统文件类型 • Directory --> catalogue of file name • Normal file --> format of data –source file –text file • Symbolic link --> a pointer to another file • Special file --> use for device controller in kernel • Named pipe --> communication channel which can be used by serveral processes(may be irrelevant) in order to exchange data
硬链接( Hard link) [root@localhost link]# Is-1 total 1 -rW-r--r--1 root root 6670ct1513:39a [@localhost link]# ln a b [root@localhost link]# Is-1 total 2 2 root 667oct1513:39 root root 6670ct1513:39b [root@localhost link]# rm a rm: remove a?y [root@localhost link]# Is-1 total 1 1 root root 667oct1513:39b Inode /root/link L匚b了 5
5 硬链接(Hard Link) [root@localhost link]# ls -l total 1 -rw-r--r-- 1 root root 667 Oct 15 13:39 a [root@localhost link]# ln a b [root@localhost link]# ls -l total 2 -rw-r--r-- 2 root root 667 Oct 15 13:39 a -rw-r--r-- 2 root root 667 Oct 15 13:39 b [root@localhost link]# rm a rm: remove `a'? y [root@localhost link]# ls -l total 1 -rw-r--r-- 1 root root 667 Oct 15 13:39 b inode /root/link a b
符号链接( Symbolic link) [root@localhost symlink]# Is -1 total 1 rw-r--r 1 root root 667oct1513:39a [root@localhost symlink]# In -s a b [root@localhost symlink]# Is total 1 root root 667oct1513:39 lrwxrwxrwx root ot 1oct1514:20b->a [root@localhost yy] rm a rm: remove a?y [root@localhost symlink]# Is -1 total 0 lrwxrwxrwx 1 root root 1oct1514:20 [rootglocalhost symlink]# cat b cat: b: No such file or directory Inode /root/link 6
6 符号链接(Symbolic link) [root@localhost symlink]# ls -l total 1 -rw-r--r-- 1 root root 667 Oct 15 13:39 a [root@localhost symlink]# ln -s a b [root@localhost symlink]# ls -l total 1 -rw-r--r-- 1 root root 667 Oct 15 13:39 a lrwxrwxrwx 1 root root 1 Oct 15 14:20 b -> a [root@localhost yy]# rm a rm: remove `a'? y [root@localhost symlink]# ls -l total 0 lrwxrwxrwx 1 root root 1 Oct 15 14:20 b -> a [root@localhost symlink]# cat b cat: b: No such file or directory inode /root/link a b
VFS( Virtua1 FileSystem)的作用 User Programs System Call Interface Virtual File System Process control Ext2 Ext3 Subsystem Scheduler Memory Buffer Cache management De Dr Hardware 7
7 VFS(Virtual FileSystem)的作用 Virtual File System Ext2 Ext3 ... Buffer Cache Device Driver Process Control Subsystem System Call Interface User Programs Inter-process communication Scheduler Memory management Hardware
基于VFS的文件访问 磁盘 超级块 node对象 进程1 fe象 dentry dent 进程2 file对象 对象 对象 进程3 fe对象 8
8 基于VFS的文件访问 进程1 进程1 进程1 file对象 file对象 file对象 超级块 inode对象 磁盘 进程1 进程2 进程3 file对象 file对象 file对象 超级块 inode对象 dentry 对象 dentry 对象
VFS的目录项( dentry) 根目录 d parent d subdirs d child d child 子目录 子目录 子目录 parent d subdirs d mounts d covers 子目录 文件 新文件系统根 d child VFS的 dentry定义在 include/ linux/dcache. h中 为了加快文件的查找,每一个曾被读取的目录或文件都可 能在目录高速缓存( directory cache)中有一个 dentry项; dentry描述了目录与文件的关系树。 9
9 根目录 子目录 子目录 子目录 文件 子目录 新文件系统根 d_subdirs d_subdirs d_child d_child d_child d_mounts d_covers d_parent d_parent VFS的目录项(dentry) VFS的dentry定义在include/linux/dcache.h中 为了加快文件的查找,每一个曾被读取的目录或文件都可 能在目录高速缓存(directory cache)中有一个dentry项; dentry描述了目录与文件的关系树
VFS的目录项( dentry) struct dentry i /*include/linux/dcache. h*/ atomic t d count unsigned int d flags struct inode d inode; /* Where the name belongs to- nULL is negative * struct dentry *d parent; parent directory struct list head d hash /*lookup hash list * struct list head d lru d count =oLRU list * struct list head d child r child of parent list * struct list head d subdirs. *our children struct list head d alias / inode alias list * nt d mounted struct gstr d name unsigned long d time / used by d revalidate struct dentry operations *d struct super block * d sb; / The root of the dentry tree *, unsigned long d vfs flags void d fsdata /*fs-specific data*/ unsigned char d iname [DNAME INLINE LEn]; small names * 10
10 VFS的目录项(dentry) struct dentry { /*include/linux/dcache.h*/ atomic_t d_count; unsigned int d_flags; struct inode * d_inode; /* Where the name belongs to - NULL is negative */ struct dentry * d_parent; /* parent directory */ struct list_head d_hash; /* lookup hash list */ struct list_head d_lru; /* d_count = 0 LRU list */ struct list_head d_child; /* child of parent list */ struct list_head d_subdirs; /* our children */ struct list_head d_alias; /* inode alias list */ int d_mounted; struct qstr d_name; unsigned long d_time; /* used by d_revalidate */ struct dentry_operations *d_op; struct super_block * d_sb; /* The root of the dentry tree */ unsigned long d_vfs_flags; void * d_fsdata; /* fs-specific data */ unsigned char d_iname[DNAME_INLINE_LEN]; /* small names */ };