实验二文件系统模拟设计_第1页
实验二文件系统模拟设计_第2页
实验二文件系统模拟设计_第3页
实验二文件系统模拟设计_第4页
实验二文件系统模拟设计_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

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

文档简介

1、实验二文件系统模拟设计一、实验目的通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能及内部实现。二、实验内容为linux 系统设计一个简单的二级文件系统。要求做到以下几点:(1)可以实现下列几条命令(至少4 条); login 用户登录 dir 列文件目录 create 创建文件 delete 删除文件 open 打开文件 close 关闭文件 read 读文件 write 写文件(2)列目录时要列出文件名、物理地址、保护码和文件长度;(3)源文件可以进行读写保三、实验内容指导提示(1)首先应确定文件系统的数据结构:主目录、 子目录及活动文件等。主目录和子目录都以文件的形式存放于磁盘

2、,这样便于查找和修改。(2)用户创建的文件,可以编号存储于磁盘上。如file0, file1,file2.并以编号作为物理地址,在目录中进行登记。程序设计思想参考 (1) 设计思想本系统是模拟实现多用户多目录的文件系统(8 个用户) , 在系统出现登录后 , 输入用户与口令,在用户登录系统后 , 可建立文件卷, 将用户输入的文件保存在指定的文件中。系统的命令与其命令的具体实现,此模拟系统共提供了上述命令, 并根据命令的含义与要求, 用 c+ 编程来完成所有具体操作。该系统可以模拟完成用户的登陆和验证 , 列出文件和目录, 新建目录 , 改变目录 , 创立和编写文件, 删除文件和退出系统等功能。

3、【注:在linux下用 g+编译 c+】 (2) 主要数据结构用户结构:账号与密码结构typedef struct users char name8; char pwd10; users; 本系统有8 个默认的用户名, 前面是用户名 , 后面为密码 , 用户登陆时只要输入正确便可进入系统, 否则提示失败要求重新输入。users usrarray8 = usr1,usr1, usr2,usr2, usr3,usr3, usr4,usr4, usr5,usr5, usr6,usr6, usr7,usr7, usr8,usr8, ; (3) 数据结构说明a) 文件结构链表struct fnode c

4、har filenamefilename_length; int isdir; int isopen; char content255; fnode *parent; fnode *child; fnode *prev; fnode *next; ; b) 函数介绍fnode *initfile(char filename,int isdir);/初始化文件或目录void createroot();/建立系统根目录int run();系统运行int findpara(char *topara);对参数进行处理bool chklogin(char *users, char *pwd);检查账号与

5、口令void help();命令列表int mkdir();建立目录int create();建立文件int read();读取文件int write();写入文件int del();删除文件int cd();切换目录int dir();文件与目录列表(4) 各模块流程图(5) 、模拟文件系统参考程序清单#include stdio.h #include iostream.h #include string.h #include iomanip.h #define filename_length 10 /文件名称长度#define command_length 10 /命令行长度#define

6、 para_length 30 /参数长度/ 账号结构typedef struct users char name8; char pwd10; users; / 文件结构struct fnode char filenamefilename_length; int isdir; int isopen; char content255; fnode *parent; fnode *child; fnode *prev; fnode *next; ; / 账号users usrarray8 = usr1,usr1, usr2,usr2, usr3,usr3, usr4,usr4, usr5,usr5

7、, usr6,usr6, usr7,usr7, usr8,usr8, ; fnode *initfile(char filename,int isdir); void createroot(); int run(); int findpara(char *topara); bool chklogin(char *users, char *pwd); void help(); int mkdir(); int create(); int read(); int write(); int del(); int cd(); int dir(); fnode *root,*recent,*temp,*

8、ttemp; char parapara_length,commandcommand_length,tempparapara_length,recentparapara_length; / 创建文件与目录结点fnode* initfile(char filename,int isdir) fnode *node=new fnode; strcpy(node-filename,filename); node-isdir=isdir; node-isopen=0; node-parent=null; node-child=null; node-prev=null; node-next=null;

9、return node; / 创建文件存储结点void createroot () recent=root=initfile(/,1); root-parent=null; root-child=null; root-prev=root-next=null; strcpy(para,/); int mkdir() temp=initfile( ,1); cintemp-filename; if(recent-child=null) temp-parent=recent; temp-child=null; recent-child=temp; temp-prev=temp-next=null;

10、else ttemp=recent-child; while(ttemp-next) ttemp=ttemp-next; if(strcmp(ttemp-filename,temp-filename)=0&ttemp-isdir=1) printf(对不起 , 目录已存在 !); return 1; ttemp-next=temp; temp-parent=null; temp-child=null; temp-prev=ttemp; temp-next=null; return 1; int create() temp=initfile( ,0); cintemp-filename;

11、 cintemp-content; if(recent-child=null) temp-parent=recent; temp-child=null; recent-child=temp; temp-prev=temp-next=null; cout 文件建立成功!child; while(ttemp-next) ttemp=ttemp-next; if(strcmp(ttemp-filename,temp-filename)=0&ttemp-isdir=0) printf(对不起 , 文件已存在 !); return 1; ttemp-next=temp; temp-parent=

12、null; temp-child=null; temp-prev=ttemp; temp-next=null; cout 文件建立成功!endl; return 1; int dir() int i=0,j=0; temp=new fnode; temp=recent; if(temp!=root) cout .child=null) couttotal: directors i files j child; while(temp) if(temp-isdir) cout filenameendl;i+; else cout filenamenext; couttotal: directors

13、 i files j filename; if(recent-child=null) cout 文件不存在 !child-filename,filename)=0) coutchild-contentchild; while(temp-next) if(strcmp(temp-next-filename,filename)=0) coutnext-contentendl; return 1; cout 文件不存在 !filename; if(recent-child=null) cout 文件不存在 !child-filename,filename)=0) recent-child-isope

14、n=1;/设置文件标记为打开 cinrecent-child-content; recent-child-isopen=0;/设置文件标记为关闭 cout 文件写入成功!child; while(temp-next) if(strcmp(temp-next-filename,filename)=0) recent-child-isopen=1;/设置文件标记为打开 cintemp-next-content; recent-child-isopen=0;/设置文件标记为关闭 cout 文件写入成功!endl; return 1; cout 文件不存在 !topara; if(strcmp(top

15、ara,.)=0) int i; while(recent-prev) recent=recent-prev; if(recent-parent) recent=recent-parent; i=strlen(para); while(parai!=/ & i0) i-; if(i!=0) parai=0; else parai+1=0; else findpara(topara); return 1; int findpara(char *topara) int i=0; int sign=1; if(strcmp(topara,/)=0) recent=root; strcpy(p

16、ara,/); return 1; temp=recent; strcpy(temppara,para); if(topara0=/) recent=root-child; i+; strcpy(para,/); else if(recent!=null & recent!=root) strcat(para,/); if(recent & recent-child) if(recent-isdir) recent=recent-child; else printf(路径错误! n); return 1; while(ichild) i+; if(recent-isdir) r

17、ecent=recent-child; else printf(路径错误 n); return 0; strcat(para,/); while(toparai!=/ & ifilename,recentpara)!=0 | (recent-isdir!=1) & recent-next!=null) recent=recent-next; if(strcmp(recent-filename,recentpara)=0) if(recent-isdir=0) strcpy(para,temppara); recent=temp; printf(是文件不是目录。n); retur

18、n 0; strcat(para,recent-filename); if(strcmp(recent-filename,recentpara)!=0 | recent=null) strcpy(para,temppara); recent=temp; printf(输入路径错误 n); return 0; return 1; int del() char filenamefilename_length; cinfilename; temp=new fnode; if(recent-child) temp=recent-child; while(temp-next & (strcmp(

19、temp-filename,filename)!=0 | temp-isdir!=0) temp=temp-next; if(strcmp(temp-filename,filename)!=0) cout 不存在该文件!endl; return 0; else cout 不存在该文件!parent=null) temp-prev-next=temp-next; if(temp-next) temp-next-prev=temp-prev; temp-prev=temp-next=null; else if(temp-next) temp-next-parent=temp-parent; tem

20、p-parent-child=temp-next; delete temp; cout 文件已删除 !endl; bool chklogin(char *users, char *pwd) int i; for(i=0; i8; i+) if( (strcmp(users,)=0) & (strcmp(pwd,usrarrayi.pwd)=0) return true; return false; void help(void) cout 命令一览 endl; coutendl; coutcreate: 建立文件。 endl; coutread: 读取文件。 endl; coutwrite: 写入文件 , 支持多线程 endl; coutdel : 删除文件。 endl; coutmkdir: 建立目录。 endl; coutcd: 切换目录。 endl; coutlogout: 退出登录。 endl; int run() coutlinux:para; cincommand; if(strcmp(command,mkdir)=0) mkdir(); else if(strcmp(command,dir)=0) dir(); else if(strcmp(command,cd)=0) cd()

温馨提示

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

评论

0/150

提交评论