操作系统试验模拟文件管理系统.doc_第1页
操作系统试验模拟文件管理系统.doc_第2页
操作系统试验模拟文件管理系统.doc_第3页
操作系统试验模拟文件管理系统.doc_第4页
操作系统试验模拟文件管理系统.doc_第5页
免费预览已结束,剩余13页可下载查看

下载本文档

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

文档简介

_装 订 线【实验报告正文】一、实验目的和要求(必填)实验目的:通过在VC平台下编程,设计和调试一个简单的文件系统,通过模拟文件操作命令的执行,来模拟文件系统对文件及目录的管理。实验要求:两名学生成组结对完成实验,仿真出文件系统中对文件和目录的操作。二、实验内容(必填)文件管理:实现一个简单的文件系统三、实验原理或实验方法(必填)原理:通过结构体来描述文件和目录,利用链表知识实现目录树结构,通过对链表的操作实现整个文件系统中目录和文件的相关操作。方法:学生两人结对进行实验,分别实现对文件和目录的操作。对文件的操作包括:创建文件create、读文件read、写文件write、删除文件delete。对目录的操作包括:创建目录mkdir、切换目录cd、展示目录内容dir、删除目录rm。四、主要仪器设备或实验条件Windows操作系统,VC开发环境五、实验步骤(含实验数据记录处理)或操作设计过程记录#include stdio.h#include iostream.h#include string.h#define FILENAME_LENGTH 10 /文件名称长度#define COMMAND_LENGTH 10 /命令行长度#define PATH_LENGTH 30 /参数长度struct filenode char filenameFILENAME_LENGTH; int isdir; char content255; filenode *parent; filenode *child; filenode *prev; filenode *next;filenode *initnode(char filename,int isdir); void createroot(); int run(); int findpath(char *topath); void help(); int mkdir(); int create(); int read(); int write(); int del(); int rm(); int cd(); int dir();filenode *root,*recent,*temp,*ttemp,*temp_child;char pathPATH_LENGTH,commandCOMMAND_LENGTH,temppathPATH_LENGTH,recentpathPATH_LENGTH;/创建文件或目录的存储节点filenode* initnode(char filename,int isdir) filenode *node=new filenode; strcpy(node-filename,filename); node-isdir=isdir;node-parent=NULL; node-child=NULL; node-prev=NULL;node-next=NULL;return node;/初始化文件系统根结点void createroot () recent=root=initnode(/,1); root-parent=NULL; root-child=NULL; root-prev=root-next=NULL; strcpy(path,/); void help() coutendl; coutcreate: 建立文件。 endl; coutread: 读取文件。 endl; coutwrite: 写入文件。 endl; coutdelete: 删除文件。 endl; coutrm: 删除目录。 endl; coutmkdir: 建立目录。 endl; coutcd: 切换目录。 endl; coutdir: 显示目录。 endl; coutlogout: 退出登录。 endl;int dir()int i=0,j=0;temp=new filenode;temp=recent;if(temp=root)cout .endl; 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 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 0; cout文件不存在!filename; if(recent-child=NULL) cout文件不存在!child-filename,filename)=0) cinrecent-child-content; cout文件写入成功!child; while(temp-next) if(strcmp(temp-next-filename,filename)=0) cintemp-next-content; cout文件写入成功!endl; return 0; cout文件不存在!filename; temp=new filenode; if(recent-child) temp=recent-child; while(temp-next & (strcmp(temp-filename,filename)!=0 | temp-isdir!=0) temp=temp-next; if(strcmp(temp-filename,filename)!=0 | temp-isdir!=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; temp-parent-child=temp-next; delete temp; cout文件已删除!filename; temp=new filenode; if(recent-child) temp=recent-child; while(temp-next & (strcmp(temp-filename,filename)!=0 | temp-isdir!=1) temp=temp-next; if(strcmp(temp-filename,filename)!=0 | temp-isdir!=1) 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; temp-parent-child=temp-next; delete temp; cout目录已删除!topath; if(strcmp(topath,.)=0) return 0; if(strcmp(topath,.)=0) int i; while(recent-prev)recent=recent-prev; /向前回溯,找到第一次创建的目录if(recent-parent) recent=recent-parent; i=strlen(path);/ printf(%d %sn,i,path); while(pathi!=/ & i0) i-; /找到最右边的/if(i!=0) pathi=0; /printf(%s,path); /path中不止有一个/else pathi+1=0; elsefindpath(topath); return 0;int findpath(char *topath) unsigned int i=0; int sign=1; if(strcmp(topath,/)=0) /如果命令是cd / recent=root; strcpy(path,/); return 0; temp=recent; strcpy(temppath,path); if(topath0=/) /cd命令以cd /开始 recent=root-child; i+; strcpy(path,/);/printf(n%s,path); else if(recent!=NULL & recent!=root) strcat(path,/);/ printf(n%sn,path); if(recent & recent-child)if(recent-isdir) recent=recent-child;elseprintf(路径错误!n);return 1; while(ichild) i+; if(recent-isdir) recent=recent-child; else printf(路径错误n); return 1; strcat(path,/); while(topathi!=/ & ifilename,recentpath)!=0 | (recent-isdir!=1) & recent-next!=NULL) recent=recent-next; if(strcmp(recent-filename,recentpath)=0) if(recent-isdir=0) strcpy(path,temppath); recent=temp; printf(是文件不是目录。n); return 1; strcat(path,recent-filename); if(strcmp(recent-filename,recentpath)!=0 | recent=NULL) strcpy(path,temppath); recent=temp; printf(输入路径错误n); return 1; return 0;int mkdir() temp=initnode( ,1); cintemp-filename;if(recent-child=NULL) temp-parent=recent; temp-child=NULL; recent-child=temp; temp-prev=temp-next=NULL;printf(目录建立成功!n); else ttemp=recent-child;if(strcmp(ttemp-filename,temp-filename)=0&ttemp-isdir=1) printf(目录已存在!n); return 1; while(ttemp-next) ttemp=ttemp-next; if(strcmp(ttemp-filename,temp-filename)=0&ttemp-isdir=1) printf(目录已存在!n); return 1; ttemp-next=temp; temp-parent=NULL; temp-child=NULL; temp-prev=ttemp; temp-next=NULL; printf(目录建立成功!n); return 0;int create() temp=initnode( ,0); cintemp-filename; if(recent-child=NULL) temp-parent=recent; temp-child=NULL; recent-child=temp; temp-prev=temp-next=NULL; cout文件创建成功!child; if(strcmp(ttemp-filename,temp-filename)=0&ttemp-isdir=0) printf(文件已存在!n); return 1; while(ttemp-next) ttemp=ttemp-next; if(strcmp(ttemp-filename,temp-filename)=0&ttemp-isdir=0) printf(文件已存在!n); return 1; ttemp-next=temp; temp-parent=NULL; temp-child=NULL; temp-prev=ttemp; temp-next=NULL; cout文件建立成功!endl; return 0;int run() coutfilesystem:path;cincommand; if(strcmp(command,mkdir)

温馨提示

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

评论

0/150

提交评论