Linux文件管理

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

文件系统VFSVFS的作用基于VFS的文件访问VFS重要数据结构文件系统的注册与安装ext2、ext3文件系统文件操作proc文件系统CRAMFS文件系统LinuxFileSystem各种各样的文件系统WindowsFAT16,FAT32,NTFS传统UNIX:UFS(UnixFileSystem)BSD文件系统FFS(FastFileSystem)ProcFileSystem:只存在于内存中LinuxFileSystem–ext2(isfirstintroducedinkernel2.0.x)–reiserfs(isfirstintroducedinkernel2.2.x)–ext3(isfirstintroducedinkernel2.4.x,defaultinRedHatnow)–xfs(fromSGI)–Jfs(fromIBM)嵌入式小型文件系统CRAMFSJFFS2linux文件系统目录布局TocomplywithFSSTND(FileSystemSTaNDard):/-firstofmountpointinlinux/etc-keeplinuxdefaultconfiguration/boot-keepimportantlinuxbootingfiles(canbeaseparatefilesystem)/bin-Essentialcommandbinariesforbothrootandord.users/sbin-Essentialsystembinariesforadministrator/dev-keepalldevicefiles/usr-keepalluserbinaryandXlibrary/home-keepuserhomedirectory/proc-ispseudofilesystemfortrackingrunningprocessandstateoflinuxsystem/var-keepingmail,logfileandprinterspooling/lib-containsharedlibrarythatisrequiredbysystemprogram/tmp-containsystemtemporaryfile/opt-Add-onapplicationsoftwarepackagesDirectory--catalogueoffilenameNormalfile--formatofdatasourcefiletextfileSymboliclink--apointertoanotherfileSpecialfile--usefordevicecontrollerinkernelNamedpipe--communicationchannelwhichcanbeusedbyserveralprocesses(maybeirrelevant)inordertoexchangedataUNIX文件系统文件类型硬链接(HardLink)[root@localhostlink]#ls-ltotal1-rw-r--r--1rootroot667Oct1513:39a[root@localhostlink]#lnab[root@localhostlink]#ls-ltotal2-rw-r--r--2rootroot667Oct1513:39a-rw-r--r--2rootroot667Oct1513:39b[root@localhostlink]#rmarm:remove`a'?y[root@localhostlink]#ls-ltotal1-rw-r--r--1rootroot667Oct1513:39binode/root/linkab符号链接(Symboliclink)[root@localhostsymlink]#ls-ltotal1-rw-r--r--1rootroot667Oct1513:39a[root@localhostsymlink]#ln-sab[root@localhostsymlink]#ls-ltotal1-rw-r--r--1rootroot667Oct1513:39alrwxrwxrwx1rootroot1Oct1514:20b-a[root@localhostyy]#rmarm:remove`a'?y[root@localhostsymlink]#ls-ltotal0lrwxrwxrwx1rootroot1Oct1514:20b-a[root@localhostsymlink]#catbcat:b:Nosuchfileordirectoryinode/root/linkabVFS(VirtualFileSystem)的作用VirtualFileSystemExt2Ext3...BufferCacheDeviceDriverProcessControlSubsystemSystemCallInterfaceUserProgramsInter-processcommunicationSchedulerMemorymanagementHardware基于VFS的文件访问进程1进程1进程1file对象file对象file对象inode对象超级块磁盘进程1进程2进程3file对象file对象file对象超级块inode对象dentry对象dentry对象VFS的目录项(dentry)根目录子目录子目录文件子目录子目录新文件系统根d_subdirsd_subdirsd_childd_childd_childd_mountsd_coversd_parentd_parentVFS的dentry定义在include/linux/dcache.h中为了加快文件的查找,每一个曾被读取的目录或文件都可能在目录高速缓存(directorycache)中有一个dentry项;dentry描述了目录与文件的关系树。VFS的目录项(dentry)structdentry{/*include/linux/dcache.h*/atomic_td_count;unsignedintd_flags;structinode*d_inode;/*Wherethenamebelongsto-NULLisnegative*/structdentry*d_parent;/*parentdirectory*/structlist_headd_hash;/*lookuphashlist*/structlist_headd_lru;/*d_count=0LRUlist*/structlist_headd_child;/*childofparentlist*/structlist_headd_subdirs;/*ourchildren*/structlist_headd_alias;/*inodealiaslist*/intd_mounted;structqstrd_name;unsignedlongd_time;/*usedbyd_revalidate*/structdentry_operations*d_op;structsuper_block*d_sb;/*Therootofthedentrytree*/unsignedlongd_vfs_flags;void*d_fsdata;/*fs-specificdata*/unsignedchard_iname[DNAME_INLINE_LEN];/*smallnames*/};打开文件表linux系统运行期间维护一张以structfile(在include/linux/fs.h中)作为节点的双向链表(系统打开文件表)。表头由first_file给出。structfile*first_file=NULL;/*fs/file_table.c*/对于每个进程,structtask_struct中的files指向的files_struct结构中有一个fd指针数组,即维护一张进程打开文件表。数组元素即是指向系统打开文件表中某一节点的指针。VFS重要数据结构files_struct(在sched.h);file(在fs.h);dentry(在dcache.h);superblock(在fs.h);inode(在fs.h)文件系统类型staticstructfile_system_type*file_systems=(structfile_system_type*)NULL;structfile_system_type{structsuper_block*(*read_super)();/*读出该文件系统在外存的super_block*/constchar*name;/*文件系统的类型名*/intrequires_dev;/*支持文件系统的设备*/structfile_system_type*next;/*文件系统类型链表的后续指针*/};文件系统类型的注册和注销函数intregister_filesystem(structfile_system_type*fs)intunregister_filesystem(structfile_system_type*fs)文件系统注册与注销file_systemsfile_system_typefile_system_typefile_system_type文件系统的安装(mount)/binetcdevusrRootfilesystem/usrfilesystemCompletehierarchyaftermounting/usr/binmanlib/binetcdevusrusrbinmanlib文件系统的安装(mount)安装点dentryrootd_mounted!=0i_sbmnt_mountpointmnt_root下挂文件系统安装点vfsmount已安装文件系统的描述staticLIST_HEAD(vfsmntlist);structvfsmount{structlist_headmnt_hash;structvfsmount*mnt_parent;/*fswearemountedon*/structdentry*mnt_mountpoint;/*dentryofmountpoint*/structdentry*mnt_root;/*rootofthemountedtree*/structsuper_block*mnt_sb;/*pointertosuperblock*/structlist_headmnt_mounts;/*listofchildren,anchoredhere*/structlist_headmnt_child;/*andgoingthroughtheirmnt_child*/atomic_tmnt_count;intmnt_flags;char*mnt_devname;/*Nameofdevicee.g./dev/dsk/hda1*/structlist_headmnt_list;};已安装文件系统的描述mnt_sbs_typemnt_sbvfsmntlistvfsmountsuper_blockfile_system_typefile_systems系统调用open、mkdir、rename、stat等要查找路径open_namei()path_init()path_walk()link_path_walk();返回时,structnameidata中的dentry和mnt标识找到的文件或目录structnameidata{/*include/linux/fs.h*/structdentry*dentry;/*找到的dentry指针*/structvfsmount*mnt;/*找到的文件所在文件系统*/structqstrlast;unsignedintflags;intlast_type;};路径查找

1 / 30
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功