




已阅读5页,还剩14页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
操作系统课程设计报告操作系统课程设计报告专 业:学 号:姓 名:任艺锦提交日期:2012年1月5日【设计目的】(1)本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现。(2)结合数据结构、程序设计、计算机原理等课程的知识,设计一个二级文件系统,进一步理解操作系统。(3)通过分对实际问题的分析、设计、编程实现,提高实际应用、编程的能力【设计内容】1. 理解二级目录的文件系统的组织;2. 掌握常用的数据结构;3. 为linux系统设计一个简单的二级文件系统。其中第一级对应于用户账号,第二级对应于用户帐号下的文件;使用文件来模拟外存,进行数据结构设计和操作算法的设计,实现一个文件系统并实现基本的文件操作(为了简便文件系统,暂不考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容)。要求做到以下几点:可以实现下列几条命令:2 login 用户登录dir 列目录create 创建文件delete 删除文件open 打开文件close 关闭文件write 写文件read 读文件cd 进出目录列目录时要列出文件名,物理地址,保护码和文件长度;源文件可以进行读写保护。【实验环境】windows xp操作系统microsoft visual c+ 6.0【相关知识综述】本实验设计的文件系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件。为了简便文件系统暂未考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容。首先应确定文件系统的数据结构:主目录、子目录及活动文件等。主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。用户创建的文件,可以编号存储于磁盘上。如:file0,file1,file2并以编号作为物理地址,在目录中进行登记。【设计思路】主要数据结构:#define maxname 25 /*the largest length of mfdname,ufdname,filename*/#define maxchild 50 /*the largest child*/#define max (maxchild*maxchild) /*the size of fpaddrno*/typedef struct /*the structure of osfile*/ int fpaddr; /*file physical address*/ int flength; /*file length*/ int fmode; /*file mode:0-read only;1-write only;2-read and write(default);*/ char fnamemaxname; /*file name*/ osfile;typedef struct /*the structure of osufd*/ char ufdnamemaxname; /*ufd name*/ osfile ufdfilemaxchild; /*ufd own file*/ osufd;typedef struct /*the structure of osufdlogin*/ char ufdnamemaxname; /*ufd name*/ char ufdpword8; /*ufd password*/ osufd_login;typedef struct /*file open mode*/ nt ifopen; /*ifopen:0-close,1-open*/ int openmode; /*0-read only,1-write only,2-read and write,3-initial*/ osufd_openmode;主要函数: void loginf(); /*login filesystem*/ void dirf(); /*dir filesystem*/ void cdf(); /*change dir*/ void createf(); /*create file*/ void deletef(); /*delete file*/ void modifyfm(); /*modify filemode*/ void openf(); /*open file*/ void closef(); /*close file*/ void readf(); /*read file*/ void writef(); /*write file*/ void quitf(); /*quit filesystem*/ void help();注意事项:操作后用exit命令退出,完成向ufd文件的写入程序设计的流程图见下页使用microsoft office visio 20031.程序流程图(总体)2. 删除模块3. 打开模块4. 关闭模块5. 写模块【源程序清单】1. delete删除功能void deletef() char fnamemaxname; char str50,str150; int i,j,k; char a25; char *rtrim(char *str); char *ltrim(char *str); int existf(char *filename); int existd(char *dirname); printf(nplease input filename:); gets(fname); ltrim(rtrim(fname); i=existf(fname); if (i=0) k=existd(username); if(ifopenki.ifopen=1) printf(n%s has been opened. please close it before delete.n,fname); wgetchar=1; elseif(ufdk-ufdfilei.fmode=3) printf(n%s is in protect status. n,fname); wgetchar=1; else printf(%s will be deleted. are you sure?please input y or n:,fname); gets(a); ltrim(rtrim(a); if(strcmp(strupr(a),y)=0) fpaddrnoufdk-ufdfilei.fpaddr=0; for(j=i;jufdfilej.fname,ufdk-ufdfilej+1.fname); ufdk-ufdfilej.fpaddr=ufdk-ufdfilej+1.fpaddr; ufdk-ufdfilej.flength=ufdk-ufdfilej+1.flength; ufdk-ufdfilej.fmode=ufdk-ufdfilej+1.fmode; ifopenkj=ifopenkj+1; remove(str1); fcountk-; printf(n%s has been deleted successfully.n,fname); wgetchar=1; else if(strcmp(strupr(a),n)=0) printf(n%s hasnt been deleted.n,fname); wgetchar=1; else printf(n%s doesnt exist.n,fname);wgetchar=1;2. open打开功能void openf() /*open file*/char fnamemaxname; char str25,str125,fmode25; int i,k; char *rtrim(char *str); char *ltrim(char *str); int existf(char *filename); int existd(char *dirname); printf(n please input filename:); gets(fname); ltrim(rtrim(fname); i=existf(fname); if (i=0) k=existd(dirname); if(!ifopenki.ifopen) if (ufdk-ufdfilei.fmode=3) printf(nerror. the files mode is protected. you cant open it.n);wgetchar=1; elseprintf(please input fileopenmode(0-read only,1-write only,2-read and write):); gets(fmode); ; ltrim(rtrim(fmode); ;if(strcmp(fmode,0)=0)|(strcmp(fmode,1)=0)|(strcmp(fmode,2)=0)if(fmode0=0) ;strcpy(str,read only); if(ufdk-ufdfilei.fmode=0)|(ufdk-ufdfilei.fmode=2) ifopenki.ifopen=1; else if(fmode0=1) strcpy(str,write only); if(ufdk-ufdfilei.fmode=1)|(ufdk-ufdfilei.fmode=2) ifopenki.ifopen=1; else if(fmode0=2) strcpy(str,read and write); if(ufdk-ufdfilei.fmode=2) ifopenki.ifopen=1; if(ufdk-ufdfilei.fmode=0) strcpy(str1,read only); else if(ufdk-ufdfilei.fmode=1) strcpy(str1,write only); else if(ufdk-ufdfilei.fmode=2) strcpy(str1,read and write); if(ifopenki.ifopen=1) ifopenki.openmode=atoi(fmode); if (ifopenki.openmode=0) strcpy(str,read only); else if(ifopenki.openmode=1) strcpy(str,write only); else if(ifopenki.openmode=2) strcpy(str,read and write); printf(n%s has been opened. openmode is %s,filemode is %sn,fname,strupr(str),strupr(str1); wgetchar=1; else printf(nerror. %s hasnt been opened. openmode error. openmode is %s,but filemode is %sn,fname,strupr(str),strupr(str1); wgetchar=1; elseprintf(nerror. %s please input fileopenmode range between 0 and 2.n,fname); wgetchar=1; elseprintf(nerror. %s is in open status.n,fname);wgetchar=1; else printf(nerror. %s does not exist.n,fname); wgetchar=1; 3. close关闭功能void closef() /*close file*/int i,k,n=0; char fnamemaxname; char *rtrim(char *str); char *ltrim(char *str); int existf(char *filename); int existd(char *dirname); k=existd(dirname); printf(nopen files in the ufd:n); for(i=0;iufdfilei.fname); n+; if(n%5=0)&(n!=0) printf(n); while(n!=0) printf(n please input filename that you want to close:); gets(fname); ltrim(rtrim(fname); i=existf(fname); if(i=0) if(ifopenki.ifopen=1) ifopenki.ifopen=0; printf(n%s has been closed successfully.n,fname); wgetchar=1; else printf(nerror.%s is in closing status.n,fname); wgetchar=1; else printf(nerror. %s is not exist.n,fname); wgetchar=1; break; while (n=0)printf(n there are no file in open status.); wgetchar=1;break;4. write写功能void writef() /*write file*/int i,k,n=0,length;char fnamemaxname;char str255,str1255;char *rtrim(char *str); char *ltrim(char *str); int existf(char *filename); int existd(char *dirname);printf(opened files list:n); k=existd(dirname); for(i=0;iufdfilei.fname); n+;if(n%5=0)&(n!=0)printf(n); printf(n%d files openned.n,n); if(n=0) wgetchar=1; if(n!=0) printf(nplease input filename:); gets(fname); ltrim(rtrim(fname); i=existf(fname); if(i=0) if(ifopenki.ifopen=1)if(ifopenki.openmode=1) |(ifopenki.openmode=2) itoa(ufdk-ufdfilei.fpaddr,str,10);strcpy(str1,file); strcat(str1,str); strcpy(str,c:osfilefile);strcat(str,str1); strcat(str,.txt); fp_file=fopen(str,ab);length=writef1(); ufdk-ufdfilei.flength=ufdk-ufdfilei.flength+length; printf(nn%d length.n,ufdk-ufdfilei.flength); printf(nthe file has been write successfully!);fclose(fp_file);else if(ifopenki.openmode=0) printf(nerror.%s has been opened with read only mode. it isnt write.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 工作中如何提高专注力和时间利用率
- 工业自动化技术的前沿进展
- 工业自动化技术的发展及市场应用
- 工作中的决策能力与执行力培养
- 工业设备能效优化策略
- 工业领域安全防护系统设计
- 工作繁忙人士的健康膳食建议
- 工作流程优化及资源管理方法
- 工厂设备选型与采购策略培训
- 工程测量中的遥感技术应用分析
- 食品供应不合格产品退换方案
- 华为大学人才培养与发展实践
- 年产12000吨水合肼(100%)项目环评报告书
- 《有机波谱分析》期末考试试卷及参考答案
- 最详细的整车开发流程
- 部编版七年级历史(下)材料论述题专项训练
- 年产1000吨乳酸的生产工艺设计
- 博克服装CAD制版说明操作手册(共95页)
- 光电效应测普朗克常数-实验报告
- (完整word版)数据模型与决策课程案例分析
- 物业服务参与校园文化建设及举办大型活动配合措施
评论
0/150
提交评论