文件系统模拟设计 c++

  • 格式:doc
  • 大小:61.50 KB
  • 文档页数:11

下载文档原格式

  / 11
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#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],recentpa ra[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);

cin>>temp->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)==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);

cin>>temp->filename;

cin>>temp->content;

if(recent->child==NULL)

{

temp->parent=recent;

temp->child=NULL;

recent->child=temp;

temp->prev=temp->next=NULL;

cout<<"文件建立成功!"<

}

else

{

ttemp=recent->child;