第2节Linux的文件系统的结构.ppt_第1页
第2节Linux的文件系统的结构.ppt_第2页
第2节Linux的文件系统的结构.ppt_第3页
第2节Linux的文件系统的结构.ppt_第4页
第2节Linux的文件系统的结构.ppt_第5页
已阅读5页,还剩25页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Linux的文件系统,课程目标: 操作系统的运行级别 文件系统架构 设备管理,各种各样的文件系统,Linux的七个运行级别和含义 0.halt -(关机) 1.single-(单用户) 2.multiuser,without NFS (多用户) 3.Full multiuser mode(完全多用户) 4.unused 5.X11-(图形界面) 6.reboot-(重新启动),linux文件系统目录布局,To comply with FSSTND(File System STaNDard): / - first of mount point in linux /etc - keep linux

2、 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

3、 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,UN

4、IX文件系统文件类型,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 exch

5、ange data,硬链接(Hard Link),rootlocalhost link# ls -l total 1 -rw-r-r- 1 root root 667 Oct 15 13:39 a rootlocalhost link# ln a b rootlocalhost 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 rootlocalhost link# rm a rm: remove a? y rootlocalhost link#

6、 ls -l total 1 -rw-r-r- 1 root root 667 Oct 15 13:39 b,符号链接(Symbolic link),rootlocalhost symlink# ls -l total 1 -rw-r-r- 1 root root 667 Oct 15 13:39 a rootlocalhost symlink# ln -s a b rootlocalhost 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

7、b - a rootlocalhost yy# rm a rm: remove a? y rootlocalhost symlink# ls -l total 0 lrwxrwxrwx 1 root root 1 Oct 15 14:20 b - a rootlocalhost symlink# cat b cat: b: No such file or directory,VFS(Virtual FileSystem)的作用,Virtual File System,Ext2,Ext3,.,Buffer Cache,Device Driver,Process Control Subsystem

8、,System Call Interface,User Programs,Inter-process communication,Scheduler,Memory management,Hardware,基于VFS的文件访问,VFS的目录项(dentry),VFS的dentry定义在include/linux/dcache.h中 为了加快文件的查找,每一个曾被读取的目录或文件都可能在目录高速缓存(directory cache)中有一个dentry项;dentry描述了目录与文件的关系树。,VFS的目录项(dentry),struct dentry /*include/linux/dcache

9、.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 o

10、f 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

11、d_vfs_flags; void * d_fsdata;/* fs-specific data */ unsigned char d_inameDNAME_INLINE_LEN; /* small names */ ;,打开文件表,linux系统运行期间维护一张以struct file (在include/linux/fs.h 中)作为节点的双向链表(系统打开文件表)。表头由first_file给出。 struct file *first_file = NULL; /* fs/file_table.c */ 对于每个进程,struct task_struct中的files指向的files_s

12、truct结构中有一个fd指针数组,即维护一张进程打开文件表。数组元素即是指向系统打开文件表中某一节点的指针。,VFS重要数据结构,files_struct (在sched.h); file (在fs.h); dentry (在 dcache.h); superblock(在 fs.h); inode (在 fs.h),文件系统类型,static struct file_system_type *file_systems = (struct file_system_type *) NULL; struct file_system_type struct super_block *(*read_

13、super)(); /* 读出该文件系统在外存的super_block */ const char *name; /* 文件系统的类型名 */ int requires_dev; /* 支持文件系统的设备 */ struct file_system_type * next; /* 文件系统类型链表的后续指针 */ ;,文件系统注册与注销,文件系统类型的注册和注销函数 int register_filesystem(struct file_system_type * fs) int unregister_filesystem(struct file_system_type * fs),file_

14、systems,file_system_type,file_system_type,file_system_type,文件系统的安装(mount),/,bin,etc,dev,usr,Root filesystem,/usr filesystem,Complete hierarchy after mounting /usr,/,bin,man,lib,/,bin,etc,dev,usr,usr,bin,man,lib,文件系统的安装(mount),安装点dentry,已安装文件系统的描述,static LIST_HEAD(vfsmntlist); struct vfsmount struct

15、list_head mnt_hash; struct vfsmount *mnt_parent; /* fs we are mounted on */ struct dentry *mnt_mountpoint; /* dentry of mountpoint */ struct dentry *mnt_root; /* root of the mounted tree */ struct super_block *mnt_sb; /* pointer to superblock */ struct list_head mnt_mounts; /* list of children, anch

16、ored here */ struct list_head mnt_child; /* and going through their mnt_child */ atomic_t mnt_count; int mnt_flags; char *mnt_devname; /* Name of device e.g. /dev/dsk/hda1 */ struct list_head mnt_list; ;,已安装文件系统的描述,vfsmntlist,vfsmount,super_block,file_system_type,file_systems,路径查找,系统调用open、mkdir、ren

17、ame、stat等要查找路径 open_namei() path_init() path_walk() link_path_walk(); 返回时,struct nameidata中的dentry和mnt标识找到的文件或目录 struct nameidata /*include/linux/fs.h*/ struct dentry *dentry;/*找到的dentry指针*/ struct vfsmount *mnt;/*找到的文件所在文件系统*/ struct qstr last; unsigned int flags; int last_type;,ext2文件系统,支持UNIX所有标准

18、的文件系统特征,包括正文、目录、设备文件和连接文件等,这使得它很容易被UNIX程序员接受。事实上,ext2的绝大多数的数据结构和系统调用与经典的UNIX一致 能够管理海量存储介质。支持多达4TB的数据,即一个分区的容量最大可达4TB 支持长文件名,最多可达255个字符,并且可扩展到1012个字符 允许通过文件属性改变内核的行为;目录下的文件继承目录的属性 支持文件系统数据“即时同步”特性,即内存中的数据一旦改变,立即更新硬盘上的数据使之一致 实现了“快速连接”(fast symbolic links)的方式,使得连接文件只需要存放inode的空间 允许用户定制文件系统的数据单元(block)的

19、大小,可以是 1024、2048 或 4096 个字节,使之适应不同环境的要求 使用专用文件记录文件系统的状态和错误信息,供下一次系统启动时决定是否需要检查文件系统,ext2体系结构,内存中的ext2 inode,ext2_inode_info (在include/linux/ext2_fs_i.h) struct ext2_inode_info _u32 i_data15; _u32 i_flags; _u32 i_faddr; _u8 i_frag_no; _u8 i_frag_size; _u16 i_osync; _u32 i_file_acl; _u32 i_dir_acl; _u3

20、2 i_dtime; _u32 i_block_group; _u32 i_next_alloc_block; _u32 i_next_alloc_goal; _u32 i_prealloc_block; _u32 i_prealloc_count; _u32 i_dir_start_lookup; int i_new_inode:1; /* Is a freshly allocated inode */ ;,外存中的ext2 inode,struct ext2_inode(在include/linux/ext2_fs.h) 内、外存inode的读写: ext2_read_inode() ex

21、t2_update_inode(),Ext2_inode,文件读写,read()和write() int read(int fd, void *buf,size_t nbytes); int write(int fd, void *buf,size_t nbytes); read()调用generic_file_read(),再调用do_generic_file_read()读入内核缓冲区,然后调用file_read_actor()将读入内容传入用户空间。最后调用update_atime()修改inode write()调用generic_file_write()写数据入缓冲区,如果是同步写(

22、O_SYNC置位),则调用generic_osync_inode()将缓冲区中数据写入磁盘文件。 直接读写(read、write时将O_DIRECT置位) generic_file_read()先读page cache generic_file_write()先写入缓冲区 generic_file_direct_IO()直接读写(self-caching),ext3文件系统,日志文件系统(journaling file system) 利用数据库的日志技术(log, checkpoint) 3种日志方式:journal, ordered, writeback 日志记录在/.journal中(隐藏的文件) Kjournald5s Reiserfs,

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论