Linux二级文件系统.doc_第1页
Linux二级文件系统.doc_第2页
Linux二级文件系统.doc_第3页
Linux二级文件系统.doc_第4页
Linux二级文件系统.doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

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

文档简介

文件系统的设计及实现内容要求:为Linux系统设计一个简单的二级文件系统。要求做到以下几点:1可以实现下列几条命令:login用户登录dir列目录create创建文件delete删除文件open打开文件close关闭文件read读文件write写文件2列目录时要列出文件名,物理地址,保护码和文件长度。3源文件可以进行读写保护。程序设计1设计思想:采用两级目录,其中第一级对应于用户账号,第二级对应于用户账号下的文件。2主要数据结构:(1) i节点struct inode struct inode *i_forw;struct inode *i_back;char i_flag;unsigned int i_ino;unsigned int i_count;unsigned short di_number;unsigned short di_mode;unsigned short di_uid;unsigned short di_gid;unsigned int di_addr NADDR;(2) 磁盘i节点struct dinodeunsigned short di_number;unsigned short di_mode;unsigned short di_uid;unsigned short di_gid;unsigned long di_size;unsigned int di_addr NADDR;(3) 目录项结构struct directchar d_name DIRSIZ;unsigned int d_ino;(4) 超级块struct filsysunsigned short s_isize;unsigned long s_fsize;unsigned int s_nfree;unsigned short s_pfree;unsigned int s_freeNICFREE;unsigned int s_ninode;unsigned short s_pinode;unsigned int s_inodeNICINOD;unsigned int s_rinode;char s_fmod;(5) 用户密码struct pwdunsigned short p_uid;unsigned short p_gid;char *password PWDSIZ;(6) 目录struct dirstruct direct directDIRNUM;int size;(7) 查找内存i节点的hash表struct hinodestruct inode *i_frow;(8) 系统打开表struct filechar f_flag;unsigned int f_count;struct inode *f_inode;unsigned long f_off;(9) 用户打开表struct userunsigned short u_default_mode;unsigned short u_uid;unsigned short u_gid;unsigned short u_ofileNOFILE;3主要函数(1) i节点内容获取函数iget()(2) i节点内容释放函数iput()(3) 目录创建函数mkdir()(4) 目录搜索函数namei()(5) 磁盘块分配函数balloc()(6) 磁盘块释放函数bfree()(7) 分配节点区函数ialloc()(8) 释放i节点区函数ifree()(9) 搜索当前目录下文件的函数iname()(10) 访问控制函数access()(11) 显示目录和文件用函数_dir()(12) 改变当前目录用函数chdir()(13) 打开文件函数open()(14) 创建文件函数create()(15) 读文件用函数read()(16) 写文件用函数write()(17) 用户登录函数login()(18) 用户退出函数logout()(19) 文件系统格式化函数format()(20) 进入文件系统函数install()(21) 关闭文件函数close()(22) 退出文件系统函数halt()(23) 文件删除函数delete()4主程序说明BeginStep1 对磁盘进行格式化Step2 调用install(),进入文件系统Step3 调用_dir(),显示当前目录Step4 调用login(),用户注册Step5 调用mkdir()和chdir()创建目录Step6 调用creat()创建文件0Step7 分配缓冲区Step8 写文件0Step9 关闭文件0和释放缓冲Step10 调用mkdir()和chdir()创建子目录Step11 调用creat(),创建文件1Step12 分配缓冲区Step13 写文件1Step14 关闭文件1和释放缓冲Step15 调用chdir()将当前目录移到上一级Step16 调用creat(),创建文件2Step17 分配缓冲区Step18 调用write(),写文件2Step19 关闭文件2和释放缓冲Step20 调用delete(),删除文件0Step21 调用creat(),创建文件3Step22 为文件3分配缓冲区Step23 调用write(),写文件3Step24 关闭文件3并释放缓冲区Step25 调用open(),打开文件2Step26 为文件2分配缓冲Step27 写文件3后关闭文件3Step28 释放缓冲Step29 用户退出(logout)Step30 关闭(halt)End该文件系统实际是为用户提供一个解释执行相关命令的环境。主程序中的大部分语句都被用来执行相应的命令。程序1.编程管理文件makefile2头文件filesys.h3主程序main() (文件名main.c)4.初始化磁盘格式程序format() (文件名format.c)5.进入文件系统程序install() (文件名install.c)6.退出程序halt() (文件名halt.c)7.获取释放i节点内容程序iget()/iput() (文件名igetput.c)8.i节点分配合和释放函数ialloc()和ifree() (文件名iallfre.c)9.磁盘块分配与释放函数balloc()与bfree() (文件名ballfre.c)10.搜索函数namei()和iname() (文件名name.c)11.访问控制函数access() (文件名access.c)12.显示列表函数dir()和目录创建函数mkdir()等(文件名dir.c)13.文件创建函数creat()(文件名creat.c)14.打开文件函数open()(文件名open.c)15.关闭文件系统函数close() (文件名close.c)16.删除文件函数delete() (文件名delete.c)17.读写文件函数read()与write()(文件名rdwt.c)18.注册和退出函数login()和logout()(文件名log.c)结果对上述makefile文件进行编译,得执行文件filsys,在Linux系统中运行结果如下:$ filsys$ format$ Do you want to format the disk? y $ Format will erase all context on the disk. Are You Sure! y $ install$ dir CURRENT DIRECTORY: . d xxx xxx xxx block chain:1 .d xxx xxx xxx block chain:2 $ login please input your uid : 2118 password : ok ! 2118s user id is : 0$ mkdir a2118$ chdir a2118$ creat ( 2118 , “file0.c” , 01700 ) the file file0.c fd:0$ write ( 0 , buf , 3077 ) $ close ( 0 , 0 ) $ mkdir subdir$ chdir subdir $ creat ( 2118 , “file1.c”, 01700 ) the file file1.c fd:0$ write ( 0 , buf , 2068 ) $ chdir .$ creat ( 2118 , “file2.c”, 01700 ) the file file2.c fd:1$ write ( 1 , buf , 1791 )$ dir CURRENT DIRECTORY: . d xxx xxx xxx block chain:1 .d xxx xxx xxx block chain:2 file0.cf xxx - - 3077 block chain:4 5 6 7 8 9 10 subdird xxx xxx xxx block chain:11 file2.cf xxx - - 1791 block chain:17 18 19 20 $ delete file0.c$ creat ( 2118 , “file3.c” , 01700 ) the file file3.c fd:2$ write ( 2 , buf , 4396 ) $ close ( 0 , 2 ) $ dir CURRENT DIRECTORY: . d xxx xxx xxx block chain:1 .d xxx xxx xxx block chain:2 subdird xxx xxx xxx block chain:11 file2.cf xxx - - 1791 block chain:17 18 19 20 file3.cf xxx - - 4396 block chain:4 5 6 7 8 9 10 21 22 23 $ close ( 0 , 0 ) $ close ( 0 , 1 ) $ open ( 2118 , “file2.c”, 03 ) the file file2.c fd:0 $ write ( 0 , buf , 1636 )$ close ( 0 , 0 ) $ dir CURRENT DIRECTORY: . d xxx xxx xxx block chain:1 .d xxx xxx xxx block chain:2 subdird xxx xxx x

温馨提示

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

评论

0/150

提交评论