




已阅读5页,还剩23页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
操作系统课程设计报告操作系统课程设计报告专 业:计算机科学与技术学 号:09101312姓 名:王林提交日期:2012-3-1【设计目的】(1)本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现。(2)结合数据结构、程序设计、计算机原理等课程的知识,设计一个二级文件系统,进一步理解操作系统。(3)通过分对实际问题的分析、设计、编程实现,提高学生实际应用、编程的能力.【设计内容】1、delete 删除文件;2、open 打开文件;3、close 关闭文件;4、write 写文件;.【实验环境】windows7系统;visual c+;【相关知识综述】本文件系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件。另外,为了简便文件系统未考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容。首先应确定文件系统的数据结构:主目录、子目录及活动文件等。主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。用户创建的文件,可以编号存储于磁盘上。如:file0,file1,file2并以编号作为物理地址,在目录中进行登记。【设计思路】1 主要数据结构#define maxname 25 /*the largest length of mfdname,ufdname,filename*/#define maxchild 50 /*the largest child每个用户名下最多有50个文件*/#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; 3-protect;*/ 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定义操作方式*/int ifopen; /*ifopen:0-close,1-open*/ int openmode; /*0-read only,1-write only,2-read and write,3-initial*/osufd_openmode;2 主要函数void loginf(); /*login filesystem*/void dirf(); /*dir filesystem*/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 cdf(); /*change dir*/void help();【源程序清单】#include stdio.h#include string.h#include conio.h#include stdlib.h#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*/int ifopen; /*ifopen:0-close,1-open*/ int openmode; /*0-read only,1-write only,2-read and write,3-initial*/osufd_openmode;osufd *ufdmaxchild; /*ufd and ufd own files*/osufd_login ufd_lp;int ucount=0; /*the count of mfds ufds*/int fcountmaxchild; /*the count of ufds files*/int loginsuc=0; /*whether login successfully*/char usernamemaxname; /*record login users name22*/char dirnamemaxname;/*record current directory*/int fpaddrnomax; /*record file physical address num*/osufd_openmode ifopenmaxchildmaxchild; /*record file open/close*/int wgetchar; /*whether getchar()*/file *fp_mfd,*fp_ufd,*fp_file_p,*fp_file;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();char *rtrim(char *str); /*remove the trailing blanks.*/char *ltrim(char *str); /*remove the heading blanks.*/void inputpw(char *password); /*input password,use * replace*/void setpano(int rorw); /*set physical address num*/int existd(char *dirname); /*whether dirname exist,exist-i,not exist-0*/int writef1(); /*write file*/int existf(char *filename); /*whether filename exist,exist-i,not exist-0*/int findpano(); /*find out physical address num*/ void clrscr()system(cls);void main()int i,choice1;char choice50; /*choice operation:dir,create,delete,open,delete,modify,read,write*/int choiceend=1; /*whether choice end*/char *rtrim(char *str); /*remove the trailing blanks.*/char *ltrim(char *str); /*remove the heading blanks.*/if(fp_mfd=fopen(c:osfilemfd.txt,rb)=null)fp_mfd=fopen(c:osfilemfd.txt,wb);fclose(fp_mfd);for(i=0;i,strupr(dirname);else printf(bad command or file name.nc:%s,strupr(username); gets(choice); strcpy(choice,ltrim(rtrim(strlwr(choice); if (strcmp(choice,dir)=0) choice1=1; else if(strcmp(choice,create)=0) choice1=2; else if(strcmp(choice,delete)=0) choice1=3; else if(strcmp(choice,attrib)=0) choice1=4; else if(strcmp(choice,open)=0) choice1=5; else if(strcmp(choice,close)=0) choice1=6; else if(strcmp(choice,read)=0) choice1=7; else if(strcmp(choice,write)=0) choice1=8; else if(strcmp(choice,exit)=0) choice1=9; else if(strcmp(choice,cls)=0) choice1=10; else if(strcmp(choice,cd)=0) choice1=11; else if(strcmp(choice,help)=0) choice1=20; else choice1=12;switch(choice1)case 1:dirf();choiceend=1;break;case 2:createf();choiceend=1;if(!wgetchar) getchar();break;case 3:deletef();choiceend=1;if(!wgetchar)getchar();break;case 4:modifyfm();choiceend=1;if(!wgetchar) getchar();break;case 5:openf();choiceend=1;if (!wgetchar) getchar();break;case 6:closef();choiceend=1;if (!wgetchar) getchar();break;case 7:readf();choiceend=1;if (!wgetchar) getchar();break;case 8:writef();choiceend=1;if (!wgetchar) getchar();break;case 9:printf(nyou have exited this system.); quitf();exit(0);break;case 10:clrscr();choiceend=1;break;case 11:cdf();choiceend=1;break;case 20:help();choiceend=1;break;default:choiceend=0;else printf(naccess denied.);void help(void)printf(nthe command listn);printf(ncd attrib create write read open cls delete exit closen);char *rtrim(char *str) /*remove the trailing blanks.*/int n=strlen(str)-1;while(n=0)if(*(str+n)!= )*(str+n+1)=0;break;else n-;if (nufdname,strupr(ufd_lp.ufdname);fp_ufd=fopen(str,rb);fcountj=0;for(i=0;fread(&ufdj-ufdfilei,sizeof(osfile),1,fp_ufd)!=0;i+,fcountj+)ifopenji.ifopen=0;ifopenji.openmode=4;fclose(fp_ufd);fclose(fp_mfd);ucount=j;setpano(0);printf(nnlogin successful! welcome to this filesystemnn);loginsuc=1;return;elseprintf(nn);flag=1;while(flag)printf(login failed! password error. try again(y/n):);gets(a);ltrim(rtrim(a);if (strcmp(strupr(a),y)=0) loginsuc=0;flag=0;else if(strcmp(strupr(a),n)=0)loginsuc=0;flag=0;return;elseprintf(new password(=8):);inputpw(loginpw); /*input new password,use * replace*/printf(nconfirm password(ufdname,strupr(ufd_lp.ufdname);fp_ufd=fopen(str,rb);for(i=0;fread(&ufdj-ufdfilei,sizeof(osfile),1,fp_ufd)!=0;i+,fcountj+)ifopenji.ifopen=0; ifopenji.openmode=4;fclose(fp_ufd);fclose(fp_mfd);ucount=j;setpano(0);printf(nnlogin successful! welcome to this systemnn);loginsuc=1;return; elseprintf(nn);flag=1;while(flag)printf(login failed! password error. try again(y/n):);gets(a);ltrim(rtrim(a);if (strcmp(strupr(a),y)=0) loginsuc=0;flag=0;else if(strcmp(strupr(a),n)=0)loginsuc=0;flag=0;return;void setpano(int rorw) /*set physical address num,0-read,1-write*/int i,j;if (rorw=0)if(fp_file_p=fopen(c:osfilefilefile_p.txt,rb)=null) fp_file_p=fopen(c:osfilefilefile_p.txt,wb);fclose(fp_file_p); fp_file_p=fopen(c:osfilefilefile_p.txt,rb);/for(i=0;fread(&j,sizeof(int),1,fp_file_p)!=0;i+)fpaddrnoj=1;/*for(i=1;imax;i+)if (i%13)=0) fpaddrnoi=1;*/elsefp_file_p=fopen(c:osfilefilefile_p.txt,wb);/*for(i=1;imax;i+)if(i%13)=0) fpaddrnoi=0;*/for(i=0;imax;i+)if (fpaddrnoi=1)fwrite(&i,sizeof(int),1,fp_file_p);fclose(fp_file_p);void inputpw(char *password) /*input password,use * replace*/int j;for(j=0;j0)j-;j-;putchar(b);putchar( );putchar(b);else j-;elsepasswordj=0;break;passwordj=0;void dirf() /*dir filesystem*/int i,j,count=0;char sfmode25,sfpaddr25,str25;clrscr();if (strcmp(strupr(ltrim(rtrim(dirname),)!=0)printf(nnc:%sdirn,dirname);printf(n%14s%16s%14s%10s%18sn,filename,fileaddress,filelength,type,filemode);j=existd(dirname);for(i=0;iufdfilei.fpaddr,str,10);strcpy(sfpaddr,file);strcat(sfpaddr,str);if (ufdj-ufdfilei.fmode=0) strcpy(sfmode,read only);else if(ufdj-ufdfilei.fmode=1) strcpy(sfmode,write only);else if(ufdj-ufdfilei.fmode=2)strcpy(sfmode,read and write);else strcpy(sfmode,protect);printf(%14s%16s%14d%10s%18sn,ufdj-ufdfilei.fname,sfpaddr,ufdj-ufdfilei.flength,sfmode);printf(n %3d file(s)n,fcountj);elseprintf(nnc:dirn);printf(n%14s%18s%8sn,dirname,ownfilecount,type);for(i=0;iufdname,fcounti,);count=count+fcounti;printf(n %3d dir(s),%5d file(s)n,ucount,count);int existd(char *dirname) /*whether dirname exist,exist-i,not exist-0*/int i;int exist=0;for(i=0;iufdname),strupr(dirname)=0)exist=1;break;if (exist) return(i);else return(-1);void cdf() /*exchange dir*/char dnamemaxname;printf(nplease input dirname (cd.-previous dir; dirname-cd dirname):);gets(dname);ltrim(rtrim(dname);if (existd(dname)=0) strcpy(dirname,strupr(dname);else if(strcmp(strupr(dname),cd.)=0) strcpy(ltrim(rtrim(dirname),);else printf(nerror.%s does not exist.n,dname);void createf() /*create file*/int fpaddrno,flag=1,i;char fnamemaxname,str50,str150,a25;char fmode25; if (strcmp(strupr(dirname),strupr(username)!=0)printf(nerror. you must create file in your own dir.n);wgetchar=1;elseprintf(nplease input filename:);gets(fname);ltrim(rtrim(fname);if (existf(fname)=0)printf(nerror. name %s has already existed.n,fname);wgetchar=1;elseprintf(please input filemode(0-read only, 1-write only, 2-read and write, 3-protect):);gets(fmode);ltrim(rtrim(fmode);if(strcmp(fmode,0)=0)|(strcmp(fmode,1)=0)|(strcmp(fmode,2)=0)|(strcmp(fmode,3)=0)fpaddrno=findpano();if (fpaddrno=0)i=existd(username);strcpy(ufdi-ufdfilefcounti.fname,fname);ufdi-ufdfilefcounti.fpaddr=fpaddrno;ufdi-ufdfilefcounti.fmode=atoi(fmode);ifopenifcounti.ifopen=0;ifopenifcounti.openmode=4;strcpy(str,c:osfilefilefile);itoa(fpaddrno,str1,10);strcat(str,str1);strcat(str,.txt);fp_file=fopen(str,wb);fclose(fp_file);fcounti+;while(flag)printf(input text now(y/n):);gets(a);ltrim(rtrim(a);ufdi-ufdfilefcounti-1.flength=0;if(strcmp(strupr(a),y)=0)fp_file=fopen(str,wb+);ufdi-ufdfilefcounti-1.flength=writef1();flag=0;else if(strcmp(strupr(a),n)=0)flag=0;wgetchar=1;printf(n%s has been created successfully!n,fname);elseprintf(nfail!no disk space. please format your disk.n);wgetchar=1;else printf(nerror. filemodes range is 0-3n);wgetchar=1;int existf(char *filename) /*whether filename exist,exist-i,not exist-0*/int i,j;int exist=0;j=existd(dirname);for(i=0;iufdfilei.fname),strupr(filename)=0)exist=1;break;if (exist) return(i);else return(-1);int findpano() /*find out physical address num*/int i;for(i=0;imax;i+)if (fpaddrnoi=0) fpaddrnoi=1;break;if (i=0)k=existd(username);if(ifopenki.ifopen=1)/*文件打开时无法删除*/printf(nerror.%s is in open status. close it before delete.n,fname);wgetchar=1;else if(ufdk-ufdfilei.fmode=3)/*被保护的文件无法删除*/ printf(nerror.%s is in protect status. close it before delete.n,fname);wgetchar=1; else fpaddrno1=ufdk-ufdfile
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025-2030年中国LED固化灯行业市场现状供需分析及投资评估规划分析研究报告
- 酒水供货合同协议
- 还原房购买合同协议书
- 食品加工生产设备采购合同
- 艺术公司计划书
- 2025年中国苹果酸钠项目商业计划书
- 中国动力电池铝塑膜项目创业投资方案
- 宠物医疗服务app创业计划书
- 2025年特种用途钢丝及钢丝绳项目合作计划书
- 2025年热孔高分子材料项目发展计划
- 医院急诊预检分诊分级标准(试行)-成人患者
- 老年友善医院护理培训
- 核电行业核电站安全运行与应急预案方案
- 培训学员管理制度范文(2篇)
- 《有效团队管理培训》课件
- 2024-2025学年新教材高中化学 第四章 物质结构 元素周期律 4.1.1 原子结构与元素周期表教案 新人教版必修第一册
- 2023-2024学年广东省深圳市福田区七年级(下)期末英语试卷
- 2024年陕西省专业技术人员继续教育学习平台党史党纪专题学习考试答案
- 8.3 法治社会 课件高中政治统编版必修三政治与法治
- 医疗器械经营质量体系文件-质量管理制度
- DB11T 811-2011 场地土壤环境风险评价筛选值
评论
0/150
提交评论