收藏 分销(赏)

操作系统课程设计报告-模拟文件系统.doc

上传人:二*** 文档编号:4513874 上传时间:2024-09-26 格式:DOC 页数:31 大小:183KB 下载积分:5 金币
下载 相关 举报
操作系统课程设计报告-模拟文件系统.doc_第1页
第1页 / 共31页
本文档共31页,全文阅读请下载到手机保存,查看更方便
资源描述
- . 目录 第1章 需求分析……...….........……………………………………1 第2章 概要设计……...….........……………………………………1 2.1 系统的主要功能……...….........…………………………….1 2.2系统模块功能构造……...….........……………………..……1 2.3运行环境要求……...….........……………………………..…2 2.4数据构造设计……...….........…………………………..……2 第3章 详细设计……...….........……………………………………3 3.1模块设计……...….........…………………………………..…3 3.2算法流程图……...….........…………………………..………3 第4章 系统源代码……...….........…………………………………4 第5章 系统测试及调试……...….........……………………………4 5.1运行结果及分析……...….........……………………..………4 5.2系统测试结论……...….........…………………………..……5 第6章 总结与体会……...….........…………………………………6 第7章 参考文献……...….........……………………………………6 附录……...….........……………………………………………….….7 第1章 需求分析 通过模拟文件系统的实现,深入理解操作系统中文件系统的理论知识, 加深对教材中的重要算法的理解。同时通过编程实现这些算法,更好地掌握操作系统的原理及实现方法,提高综合运用各专业课知识的能力;掌握操作系统构造、实现机理和各种典型算法,系统地了解操作系统的设计和实现思路,并了解操作系统的开展动向和趋势。 模拟二级文件管理系统的课程设计目的是通过研究Linux的文件系统构造,模拟设计一个简单的二级文件系统,第一级为主目录文件,第二级为用户文件。 第2章 概要设计 2.1 系统的主要功能 1) 系统运行时根据输入的用户数目创立主目录 2) 能够实现以下命令: l Login 用户登录 Create 建立文件 l Read 读取文件 Write写入文件 l Delete 删除文件 Mkdir 建立目录 Cd 切换目录 Logout 退出登录 2.2系统模块功能构造 2.3运行环境要求 操作系统windows xp ,开发工具vc++6.0 2.4数据构造设计 用户构造:账号与密码构造 typedef struct users { char     name[8]; char     pwd[10]; }users; 本系统有8个默认的用户名,前面是用户名,后面为密码,用户登陆时只要输入正确便可进入系统,否那么提示失败要求重新输入。 users usrarray[8] = { "usr1","usr1", "usr2","usr2", "usr3","usr3", "usr4","usr4", "usr5","usr5", "usr6","usr6", "usr7","usr7", "usr8","usr8", }; (3)数据构造说明 a)文件构造链表 struct fnode { char filename[FILENAME_LENGTH]; int  isdir; int isopen; char content[255]; 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);检查账号与口令 void help();命令列表 int mkdir();建立目录 int create();建立文件 int read();读取文件 int write();写入文件 int del();删除文件 int cd();切换目录 int dir();文件与目录列表 第3章 详细设计 3.1模块设计 此课程设计把文本作为研究对象来模拟操作系统的文件系统工作过程。所以用一个字符串数组来模拟磁盘空间,顾名思义,模拟磁盘提供字符的存储效劳。 所有用户构成一个数组,每个数组元素是一个构造体,每个构造体包括三局部,用户的用户名、用户密码和文件链表〔由于模拟文件系统的文件数量不多,故文件表采用线性链表来存储。线性表每个结点放置一个文件的FCB,其中存储一个文件的信息,文件名、长度、类型、创立时间等〕; 磁盘空间分配表,采用链表构造,每个节点保存模拟磁盘的一个逻辑块的信息,包括块的最大长度,文件占用长度,占用标志。如果占用标志为0,即该空间可分配给文件。初始化磁盘空间分配表链表,首先把整个模拟磁盘作来一块,并置占用位为0。当有进程申请磁盘空间时,从头开场遍历,检查占用位,如果该块为可分配,那么检查块大小,假设块长度大于或等于申请空间大小,那么把块的前一局部〔等于申请大小〕分配给文件,并置标志位为占用。剩下的大小作来一个新块,作来一个新节点插入到原节点的后边,标志位为可用。这样就实现了模拟磁盘的线性分配。 3.2算法流程图 模拟二级文件系统 主界面 用户登录 切换目录 退出登录 建立目录 删除文件 写入文件 读取文件 建立文件 第4章 系统源代码 见附录 第5章 系统测试及调试 5.1运行结果及分析 5.2系统测试结论 从运行结果截图中可以看到,程序分别执行了它所包含的7个功能,并且每个功能都能正确的执行。假设程序执行开场,三次都未输入正确的和密码,程序会退出不再执行。 第6章 总结与体会 虽然我们做过很屡次课程设计了,但是感觉自己还有好多需要学习的地方,接到题目要求时,设计大体的框架,考虑好所使用的数据构造,然后用高级编程语言分模块的把架子的思路编写出来,调试,运行,再看看是不是符合题目的要求,上网找些资料,看看想想是不是要提高要求,才可以满足实际的需要,最后把收集的劳动成果组合起来,一个小程序终于成型了,虽然每次的过程差不多都一样,但是每次都会有不同的体会。 通过本次的课程设计,使我能够正确运用操作系统课程中所学的根本理论和知识,加深了对文件系统根本概念的理解,以及磁盘文件系统的文件操作。在设计过程中,查询了不少相关资料,不断的发现问题、提出问题、解决问题。在对自己所编写的源程序段的纠错的过程中,使我更好的理解了操作系统中文件系统的理论知识,同时在编程时用到了模块化的设计思想,这种编程方法可以使我们的编程变的更简单,可以使我们的查错与纠错变的更方便。总的来说通过这次的设计的学习使我学到了很多在平时的学习中学不到的很多东西,通过这次课程设计,使我对操作系统和编程产生兴趣,我想我会在这条路上继续前进下去。我相信,只要不断的严格要求自己,注意培养自己的思维能力,就一定会有更大更辉煌的开展和提高。 第7章 参考文献 ?操作系统原理实验教程?,清华大学胡峰松主编 ?操作系统实验教程?,清华大学丽芬等编著 ?计算机操作系统实验教程?,清华大学颜彬等编著 附录 系统的主要源代码 #include "stdio.h" #include "iostream.h" #include "string.h" #include "iomanip.h" #define FILENAME_LENGTH 10 //文件名称长度 #define MAND_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],mand[MAND_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); 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<<"文件建立成功!"<<endl; } else { ttemp=recent->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=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<<"\ <DIR> "<<".."<<endl;i++;} if(temp->child==NULL) { cout<<"Total: "<<" directors" <<i<<" files"<< j <<endl; return 1; } temp=temp->child; while(temp) { if(temp->isdir) {cout<<"<DIR>\ "<<temp->filename<<endl;i++;} else {cout<<"<FILE> "<<temp->filename<<endl;j++;} temp=temp->next; } cout<<"Total: "<<" directors" <<i<<"files"<< j <<endl; } int read() { char filename[FILENAME_LENGTH]; cin>>filename; if(recent->child==NULL) { cout<<"文件不存在!"<<endl; return 1; } if(strcmp(recent->child->filename,filename)==0) { cout<<recent->child->content<<endl; return 1; } else { temp=recent->child; while(temp->next) { if(strcmp(temp->next->filename,filename)==0) {cout<<temp->next->content<<endl; return 1;} } cout<<"文件不存在!"<<endl; } } int write() { char filename[FILENAME_LENGTH]; cin>>filename; if(recent->child==NULL) { cout<<"文件不存在!"<<endl; return 1; } if(strcmp(recent->child->filename,filename)==0) { recent->child->isopen=1;//设置文件标记为翻开 cin>>recent->child->content; recent->child->isopen=0;//设置文件标记为关闭 cout<<"文件写入成功!"<<endl; return 1; } else { temp=recent->child; while(temp->next) { if(strcmp(temp->next->filename,filename)==0) { recent->child->isopen=1;//设置文件标记为翻开 cin>>temp->next->content; recent->child->isopen=0;//设置文件标记为关闭 cout<<"文件写入成功!"<<endl; return 1;} } cout<<"文件不存在!"<<endl; } } int cd() { char topara[PARA_LENGTH]; cin>>topara; if(strcmp(topara,"..")==0) { int i; while(recent->prev) recent=recent->prev; if(recent->parent) { recent=recent->parent; } i=strlen(para); while(para[i]!='/' && i>0) i--; if(i!=0) para[i]='\0'; else para[i+1]='\0'; } else { findpara(topara); } return 1; } int findpara(char *topara) { int i=0; int sign=1; if(strcmp(topara,"/")==0) { recent=root; strcpy(para,"/"); return 1; } temp=recent; strcpy(temppara,para); if(topara[0]=='/') { 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(i<=strlen(topara) && recent) { int j=0; if(topara[i]=='/' && recent->child) { i++; if(recent->isdir) recent=recent->child; else {printf("路径错误\n"); return 0; } strcat(para,"/"); } while(topara[i]!='/' && i<=strlen(topara)) { recentpara[j]=topara[i]; i++;j++; } recentpara[j]='\0'; while((strcmp(recent->filename,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"); return 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 filename[FILENAME_LENGTH]; cin>>filename; temp=new fnode; 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) { cout<<"不存在该文件!"<<endl; return 0; } } else { cout<<"不存在该文件!"<<endl; return 0; } if(temp->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<<"文件已删除!"<<endl; } bool chklogin(char *users, char *pwd) { int i; for(i=0; i<8; i++) { if( (strcmp(users,usrarray[i].name)==0) && (strcmp(pwd,usrarray[i].pwd)==0)) return true; } return false; } void help(void) { cout<<" 命 令 一 览 "<<endl; cout<<endl; cout<<"create: 建立文件。 "<<endl; cout<<"read: 读取文件。 "<<endl; cout<<"write: 写入文件,支持多线程 "<<endl; cout<<"del : 删除文件。 "<<endl; cout<<"mkdir: 建立目录。 "<<endl; cout<<"cd: 切换目录。 "<<endl; cout<<"logout: 退出登录。 "<<endl; } int run() { cout<<"linux:"<<para<<">"; cin>>mand; if(strcmp(mand,"mkdir")==0) mkdir(); else if(strcmp(mand,"dir")==0) dir(); else if(strcmp(mand,"cd")==0) cd(); else if(strcmp(mand,"create")==0) create(); else if(strcmp(mand,"read")==0) read(); else if(strcmp(mand,"write")==0) write(); else if(strcmp(mand,"del")==0) del(); else if(strcmp(mand,"help")==0) help(); else if(strcmp(mand,"logout")==0) return 0; } int main() { int i=0; bool in=false; char users[8],pwd[12]; cout<<"|-----------------------------------------------------------------|"<<endl; cout<<"| 模拟Linux文件系统|"<<endl; cout<<"| 账号:usr1-usr8 密码:usr1-usr8 |"<<endl; cout<<"| 你只有三次时机来试验账号 |"<<endl; cout<<"|_________________________________________|"<<endl; cout<<endl; while(i<3) { cout<<"Login:"; cin>>users; cout<<"Pass:"; cin>>pwd; if(chklogin(users,pwd)) {in=true;break;} i++; } help(); createroot(); while(in) { if(!run()) break; } } . word.zl.
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 学术论文 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服