符号链接( 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 */ };