文档详情

文件系统模拟设计 c++.doc

发布:2017-12-16约8.59千字共11页下载文档
文本预览下载声明
#include stdio.h #include iostream.h #include string.h #include iomanip.h #define FILENAME_LENGTH 10 //文件名称长度 #define COMMAND_LENGTH 10 //命令行长度 #define PARA_LENGTH 30 //参数长度 //账号结构 typedef struct users { char name[8]; char pwd[10]; }users; //文件结构 struct fnode { char filename[FILENAME_LENGTH]; int isdir; int isopen; char content[255]; //我是目录/我是文件 fnode *parent; fnode *child; fnode *prev; fnode *next; }; //账号 users usrarray[8] = { usr1,usr1, usr2,usr2, usr3,usr3, usr4,usr4, usr5,usr5, 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,*ttemp; char para[PARA_LENGTH],command[COMMAND_LENGTH],temppara[PARA_LENGTH],recentpara[PARA_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; 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; } else { ttemp=recent-child; while(ttemp-next) { ttemp=ttemp-next; if(strcmp(ttemp-filename,temp-filename)==0ttemp-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; cintemp-content; if(recent-child==NULL) { temp-parent=recent;
显示全部
相似文档