资源描述:
《文件系统模拟设计 c++》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include"stdio.h"#include"iostream.h"#include"string.h"#include"iomanip.h"#defineFILENAME_LENGTH10//文件名称长度#defineCOMMAND_LENGTH10//命令行长度#definePARA_LENGTH30//参数长度//账号结构typedefstructusers{charname[8];charpwd[10];}users;//文件结构structfnode{charfilename[FILENAME_LENGTH];intis
2、dir;intisopen;charcontent[255];//我是目录/我是文件fnode*parent;fnode*child;fnode*prev;fnode*next;};//账号usersusrarray[8]={"usr1","usr1","usr2","usr2","usr3","usr3","usr4","usr4","usr5","usr5","usr6","usr6","usr7","usr7","usr8","usr8",};fnode*initfile(charfilename[],intisdir);void
3、createroot();intrun();intfindpara(char*topara);boolchklogin(char*users,char*pwd);voidhelp();intmkdir();intcreate();intread();intwrite();intdel();intcd();intdir();fnode*root,*recent,*temp,*ttemp;charpara[PARA_LENGTH],command[COMMAND_LENGTH],temppara[PARA_LENGTH],recentpar
4、a[PARA_LENGTH];//创建文件与目录结点fnode*initfile(charfilename[],intisdir){fnode*node=newfnode;strcpy(node->filename,filename);node->isdir=isdir;node->isopen=0;node->parent=NULL;node->child=NULL;node->prev=NULL;node->next=NULL;returnnode;}//创建文件存储结点voidcreateroot(){recent=root=in
5、itfile("/",1);root->parent=NULL;root->child=NULL;root->prev=root->next=NULL;strcpy(para,"/");}intmkdir(){temp=initfile("",1);cin>>temp->filename;if(recent->child==NULL){temp->parent=recent;temp->child=NULL;recent->child=temp;temp->prev=temp->next=NULL;}else{ttemp=recent-
6、>child;while(ttemp->next){ttemp=ttemp->next;if(strcmp(ttemp->filename,temp->filename)==0&&ttemp->isdir==1){printf("对不起,目录已存在!");return1;}}ttemp->next=temp;temp->parent=NULL;temp->child=NULL;temp->prev=ttemp;temp->next=NULL;}return1;}intcreate(){temp=initfile("",0);cin>>t
7、emp->filename;cin>>temp->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&&
8、ttemp->isdir==0){printf("对不起,文件已存在!");return1;}}ttemp->next=temp;temp->parent=NULL;temp->child=NULL;tem