您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 冶金工业 > 第5章 文件管理 网络操作系统
网络操作系统课件设计人:赵艳红第一讲:操作系统概述教师:计算机操作系统课程组E-mail:zhao.yanhong@163.com(赵艳红)wxzx@yahoo.cn(沈峰)第五讲:文件管理Page1Contents与进程相关的文件4虚拟文件系统1通用文件模型2VFS数据结构35VFS的系统调用6特殊文件系统Page2文件管理器设备驱动磁盘设备API文件API传统文件系统文件管理器设备驱动磁盘POSIX文件APIPOSIX文件APILinux文件系统设备独立转换器Page35.1虚拟文件系统•内核软件层,在内核中提供一个文件系统框架(接口函数集、管理用的数据结构、各种缓存机制)。•为各种文件系统提供通用接口。Page4Linux文件管理系统调用接口VFS开关Ext2文件系统VFAT文件系统NFS文件系统Proc文件系统Page5虚拟文件系统(续)支持的文件系统可分为三类:基于磁盘的文件系统•e.gVFAT、NTFS、ISO9660CDROM…网络文件系统•e.gNFS、Coda…特殊文件系统•不管理磁盘空间,e.g/proc所有的文件系统都可以安装到根系统的子目录中。Page65.2通用文件模型用于表示所有支持的文件系统,由以下对象类型组成:•超级块对象:存放已安装文件系统信息。•索引节点对象:存放文件信息,每个索引节点对象的索引节点号唯一地标识了文件系统中的文件。•文件对象:存放打开文件与进程间交互的信息。•目录项对象:存放目录项与文件进行链接的信息。同时VFS还使用了磁盘高速缓存(软件机制),将常用的目录项对象放在目录项高速缓存中。Page7通用文件模型(续)这个模型是对要支持的文件系统的一种抽象,对于UNIX系列的,直接就可以很好地支持;对于没有目录文件的文件系统,比如FAT系列,Linux需要能够快速建立对应于目录的文件。可以将VFS看成一种通用文件系统,它位于应用程序和具体文件系统之间,提供了一层通用的接口,它在必要时依赖具体的文件系统。Page8通用文件模型(续)Page9Page105.3VFS数据结构描述各对象的数据结构:•超级块对象super_block•索引节点对象inode•文件对象file•目录项对象dentryPage115.3.1超级块对象超级块对象:structsuper_block{structlist_heads_list;/*指向超级块表的指针*/kdev_ts_dev;/*设备标识符*/unsignedlongs_blocksize;/*以字节为单位的块大小*/unsignedchars_blocksize_bits;/*以位为单位的块大小*/unsignedchars_dirt;/*修改(脏)标志*/unsignedlonglongs_maxbytes;/*文件大小的上限*/structfile_system_type*s_type;/*文件系统类型*/structsuper_operations*s_op;/*超级块方法*/structdquot_operations*dq_op;/*磁盘限额方法*/...structlist_heads_files/*分配给超级块的文件对象链表*/};•所有超级块对象由循环双链表组成,首元素s_list。•超级块操作在s_op中。Page12超级块对象(续)structsuper_operations{void(*read_inode)(structinode*);void(*read_inode2)(structinode*,void*);void(*dirty_inode)(structinode*);void(*write_inode)(structinode*,int);void(*put_inode)(structinode*);void(*delete_inode)(structinode*);void(*put_super)(structsuper_block*);void(*write_super)(structsuper_block*);void(*write_super_lockfs)(structsuper_block*);void(*unlockfs)(structsuper_block*);Page13超级块对象(续)int(*statfs)(structsuper_block*,structstatfs*);int(*remount_fs)(structsuper_block*,int*,char*);void(*clear_inode)(structinode*);void(*umount_begin)(structsuper_block*);structdentry*(*fh_to_dentry)(structsuper_block*sb,__u32*fh,intlen,intfhtype,intparent);int(*dentry_to_fh)(structdentry*,__u32*fh,int*lenp,intneed_parent);int(*show_options)(structseq_file*,structvfsmount*);};主要的操作对象:i节点、超级块、文件系统。Page145.3.2索引节点对象structinode{structlist_headi_hash;/*哈希表*/structlist_headi_list;/*索引节链表*/structlist_headi_dentry;/*目录项链表*/...unsignedlongi_ino;/*索引节点号*/atomic_ti_count;/*引用计数器*/…unsignedlongi_nrpages/*包含文件数据的页数*/...structinode_operations*i_op;/*索引节点的操作*/wait_queue_head_ti_wait;/*索引节点等待队列*/structfile_lock*i_flock;/*指向文件锁链表的指针*/Page15structaddress_space*i_mapping;/*共享内存中使用的address_space指针*/structaddress_spacei_data;/*块设备的address_space对象*/...structpipe_inode_info*i_pipe;...structblock_device*i_bdev;/*指向块设备驱动程序*/structchar_device*i_cdev;/*指向字符设备驱动程序*/...unsignedchari_sock;/*文件是否是套接字*/…};Page16索引节点对象(续)分为三类,每一类均组织成双向循环链表,由inode.i_list连接:•未使用的索引节点•正在使用的索引节点•脏索引节点索引节点对象组织成inode_hashtable散列表,冲突的节点组成链表,由inode.i_hash连接。Page17索引节点对象(续)structinode_operations{int(*create)(structinode*,structdentry*,int);structdentry*(*lookup)(structinode*,structdentry*);int(*link)(structdentry*,structinode*,structdentry*);int(*unlink)(structinode*,structdentry*);int(*symlink)(structinode*,structdentry*,constchar*);int(*mkdir)(structinode*,structdentry*,int);int(*rmdir)(structinode*,structdentry*);int(*mknod)(structinode*,structdentry*,int,int);int(*rename)(structinode*,structdentry*,structinode*,structdentry*);int(*readlink)(structdentry*,char*,int);int(*follow_link)(structdentry*,structnameidata*);void(*truncate)(structinode*);Page18int(*permission)(structinode*,int);int(*revalidate)(structdentry*);int(*setattr)(structdentry*,structiattr*);int(*getattr)(structdentry*,structiattr*);int(*setxattr)(structdentry*,constchar*,void*,size_t,int);ssize_t(*getxattr)(structdentry*,constchar*,void*,size_t);ssize_t(*listxattr)(structdentry*,char*,size_t);int(*removexattr)(structdentry*,constchar*);};目录项对象相关的文件的索引节点的创建、查找、修改、删除。Page195.3.3文件对象文件对象在磁盘上没有映像,在文件被打开时创建。文件对象也分为三类,每类是双向循环链表,由file.f_list连接:•未使用的文件对象,首元素free_list。•还未分配给超级块的在使用的文件对象,首元素anon_list。•分配给超级块的在使用的文件对象,首元素为super_block.s_files。Page20文件对象(续)structfile{structlist_headf_list;/*文件对象链表*/structdentry*f_dentry;/*相关目录项对象*/structvfsmount*f_vfsmnt;/*相关的安装文件系统*/structfile_operations*f_op;/*文件操作表*/atomic_tf_count;/*文件对象的引用计数*/...loff_tf_pos;/*文件当前的位移量(文件指针)*/...void*private_data;/*tty设备hook*/...structkiobuf*f_iobuf;/*Descriptorfordirectaccessbuffer*/longf_iobuf_lock;/*LockfordirectI/Otransfer*/};Page21文件对象(续)structfile_operations{structmodule*owner;loff_t(*llseek)(structfile*,loff_t,int);ssize_t(*read)(structfile*,char*,size_t,loff_t*);ssize_t(*write)(structfile*,constchar*,size_t,loff_t*);int(*readdir)(structfile*,void*,filldir_t);unsignedint(*poll)(structfile*,structpoll_table_struct*);int(*ioctl)(structinode*,structfile*,unsignedint,unsignedlong);/*Sendsacommandtoanunderlyinghardwaredevice*/int(*mmap)(structfile*,structvm_area_struct*);int(*open)(structinode*,structfile*);Page22int(*flush)(structfile*);int(*release)(structinode*,
本文标题:第5章 文件管理 网络操作系统
链接地址:https://www.777doc.com/doc-3787701 .html