操作系统课程设计实验指导书天津科技大学.doc

上传人:PIYPING 文档编号:10744037 上传时间:2021-06-02 格式:DOC 页数:21 大小:76.50KB
返回 下载 相关 举报
操作系统课程设计实验指导书天津科技大学.doc_第1页
第1页 / 共21页
操作系统课程设计实验指导书天津科技大学.doc_第2页
第2页 / 共21页
操作系统课程设计实验指导书天津科技大学.doc_第3页
第3页 / 共21页
操作系统课程设计实验指导书天津科技大学.doc_第4页
第4页 / 共21页
操作系统课程设计实验指导书天津科技大学.doc_第5页
第5页 / 共21页
点击查看更多>>
资源描述

《操作系统课程设计实验指导书天津科技大学.doc》由会员分享,可在线阅读,更多相关《操作系统课程设计实验指导书天津科技大学.doc(21页珍藏版)》请在三一文库上搜索。

1、操作系统课程设计实验指导书课 程 号:10110206适用专业:计算机科学与技术、网络工程、软件工程制 定 人教 研 室:计算机科学与技术教研室计算机科学与信息工程学院2007 年5 月操作系统课程设计【设计题目】二级文件系统设计【开发语言及实现平台或实验环境】C+/VC+【设计目的】(1)本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现。(2)结合数据结构、程序设计、计算机原理等课程的知识,设计一个二级文件系统,进一步理解操作系统。(3)通过分对实际问题的分析、设计、编程实现,提高学生实际应用、编程的能力【设计要求】理解二级目录的文件系统的组织;掌握常用的

2、数据结构;系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件;使用文件来模拟外存,进行数据结构设计和操作算法的设计,实现一个文件系统并实现基本的文件操作(为了简便文件系统,不考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容)。要求:1、 对程序的每一部分要有详细的设计分析说明 2、 程序执行的每个步骤要有具体的提示内容或输出3、 源代码格式规范,注释不少于四分之一4、 设计合适的测试用例,对得到的运行结果要有分析,5、 设计中遇到的问题,设计的心得体会6、 提交完整程序代码、课程设计报告及相关文档【设计原理】对采用二级文件目录的文件系统工作的机理了如指掌,对文件

3、系统的相关操作要掌握。【设计内容】一、 任务为Linux系统设计一个简单的二级文件系统。要求做到以下几点:1.可以实现下列几条命令:login 用户登录dir 列目录create 创建文件delete 删除文件open 打开文件close 关闭文件read 读文件write 写文件cd 进出目录2列目录时要列出文件名,物理地址,保护码和文件长度3源文件可以进行读写保护二、 程序设计1. 设计思想本文件系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件。另外,为了简便文件系统未考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容。首先应确定文件系统的数据结构:主目录、

4、子目录及活动文件等。主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。用户创建的文件,可以编号存储于磁盘上。如:file0,file1,file2并以编号作为物理地址,在目录中进行登记。2. 主要数据结构和部分代码参考程序见下(本程序需要在c:下建一个名为osfile的目录及一个名为file的子目录):#include stdio.h#include string.h#include conio.h#include stdlib.h#define MAXNAME 25 /*the largest length of mfdname,ufdname,filename*/#define

5、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

6、 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 ifo

7、pen; /*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 su

8、ccessfully*/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_

9、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

10、 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)

11、; /*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,delet

12、e,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

13、 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(cho

14、ice,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,h

15、elp)=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

16、) 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;cas

17、e 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=

18、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! Welco

19、me 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);

20、 /*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! W

21、elcome 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

22、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;

23、*/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

24、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;iufd

25、filei.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-ufdfile

26、i.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,No

27、t 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,st

28、rupr(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 cre

29、ate 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(rt

30、rim(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(

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1