专业:计算机科学与技术学号:09101312姓名:王林提交日期:2012-3-1操作系统课程设计报告操作系统课程设计报告1【设计目的】(1)本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现。(2)结合数据结构、程序设计、计算机原理等课程的知识,设计一个二级文件系统,进一步理解操作系统。(3)通过分对实际问题的分析、设计、编程实现,提高学生实际应用、编程的能力……………………………………..【设计内容】1、delete删除文件;2、open打开文件;3、close关闭文件;4、write写文件;………………………………….【实验环境】Windows7系统;VisualC++;【相关知识综述】本文件系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件。另外,为了简便文件系统未考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容。首先应确定文件系统的数据结构:主目录、子目录及活动文件等。主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。用户创建的文件,可以编号存储于磁盘上。如:file0,file1,file2…并以编号作为物理地址,在目录中进行登记。【设计思路】1主要数据结构#defineMAXNAME25/*thelargestlengthofmfdname,ufdname,filename*/#defineMAXCHILD50/*thelargestchild每个用户名下最多有50个文件*/#defineMAX(MAXCHILD*MAXCHILD)/*thesizeoffpaddrno*/typedefstruct/*thestructureofOSFILE定义主文件*/{intfpaddr;/*filephysicaladdress*/intflength;/*filelength*/intfmode;/*filemode:0-ReadOnly;1-WriteOnly;2-ReadandWrite;3-Protect;*/charfname[MAXNAME];/*filename*/}OSFILE;typedefstruct/*thestructureofOSUFD定义用户文件目录*/{操作系统课程设计报告2charufdname[MAXNAME];/*ufdname*/OSFILEufdfile[MAXCHILD];/*ufdownfile*/}OSUFD;typedefstruct/*thestructureofOSUFD'LOGIN定义登陆*/{charufdname[MAXNAME];/*ufdname*/charufdpword[8];/*ufdpassword*/}OSUFD_LOGIN;typedefstruct/*fileopenmode定义操作方式*/{intifopen;/*ifopen:0-close,1-open*/intopenmode;/*0-readonly,1-writeonly,2-readandwrite,3-initial*/}OSUFD_OPENMODE;2主要函数voidLoginF();/*LOGINFileSystem*/voidDirF();/*DirFileSystem*/voidCreateF();/*CreateFile*/voidDeleteF();/*DeleteFile*/voidModifyFM();/*ModifyFileMode*/voidOpenF();/*OpenFile*/voidCloseF();/*CloseFile*/voidReadF();/*ReadFile*/voidWriteF();/*WriteFile*/voidQuitF();/*QuitFileSystem*/voidCdF();/*ChangeDir*/voidhelp();【源程序清单】#includestdio.h#includestring.h#includeconio.h#includestdlib.h#defineMAXNAME25/*thelargestlengthofmfdname,ufdname,filename*/#defineMAXCHILD50/*thelargestchild*/#defineMAX(MAXCHILD*MAXCHILD)/*thesizeoffpaddrno*/typedefstruct/*thestructureofOSFILE*/{intfpaddr;/*filephysicaladdress*/intflength;/*filelength*/intfmode;/*filemode:0-ReadOnly;1-WriteOnly;2-ReadandWrite(default);*/操作系统课程设计报告3charfname[MAXNAME];/*filename*/}OSFILE;typedefstruct/*thestructureofOSUFD*/{charufdname[MAXNAME];/*ufdname*/OSFILEufdfile[MAXCHILD];/*ufdownfile*/}OSUFD;typedefstruct/*thestructureofOSUFD'LOGIN*/{charufdname[MAXNAME];/*ufdname*/charufdpword[8];/*ufdpassword*/}OSUFD_LOGIN;typedefstruct/*fileopenmode*/{intifopen;/*ifopen:0-close,1-open*/intopenmode;/*0-readonly,1-writeonly,2-readandwrite,3-initial*/}OSUFD_OPENMODE;OSUFD*ufd[MAXCHILD];/*ufdandufdownfiles*/OSUFD_LOGINufd_lp;intucount=0;/*thecountofmfd'sufds*/intfcount[MAXCHILD];/*thecountofufd'sfiles*/intloginsuc=0;/*whetherloginsuccessfully*/charusername[MAXNAME];/*recordloginuser'sname22*/chardirname[MAXNAME];/*recordcurrentdirectory*/intfpaddrno[MAX];/*recordfilephysicaladdressnum*/OSUFD_OPENMODEifopen[MAXCHILD][MAXCHILD];/*recordfileopen/close*/intwgetchar;/*whethergetchar()*/FILE*fp_mfd,*fp_ufd,*fp_file_p,*fp_file;voidLoginF();/*LOGINFileSystem*/voidDirF();/*DirFileSystem*/voidCdF();/*ChangeDir*/voidCreateF();/*CreateFile*/voidDeleteF();/*DeleteFile*/voidModifyFM();/*ModifyFileMode*/voidOpenF();/*OpenFile*/voidCloseF();/*CloseFile*/voidReadF();/*ReadFile*/操作系统课程设计报告4voidWriteF();/*WriteFile*/voidQuitF();/*QuitFileSystem*/voidhelp();char*rtrim(char*str);/*removethetrailingblanks.*/char*ltrim(char*str);/*removetheheadingblanks.*/voidInputPW(char*password);/*inputpassword,use'*'replace*/voidSetPANo(intRorW);/*Setphysicaladdressnum*/intExistD(char*dirname);/*WhetherDirNameExist,Exist-i,NotExist-0*/intWriteF1();/*writefile*/intExistF(char*filename);/*WhetherFileNameExist,Exist-i,NotExist-0*/intFindPANo();/*findoutphysicaladdressnum*/voidclrscr(){system(cls);}voidmain(){inti,choice1;charchoice[50];/*choiceoperation:dir,create,delete,open,delete,modify,read,write*/intchoiceend=1;/*whetherchoiceend*/char*rtrim(char*str);/*removethetrailingblanks.*/char*ltrim(char*str);/*removetheheadingblanks.*/if((fp_mfd=fopen(c:\\osfile\\mfd.txt,rb))==NULL){fp_mfd=fopen(c:\\osfile\\mfd.txt,wb);fclose(fp_mfd);}for(i=0;iMAX;i++)fpaddrno[i]=0;//textattr(BLACK*16|WHITE);clrscr();/*clearscreen*/LoginF();/*userlogin*/clrscr();if(loginsuc==1)/*LoginSuccessfully*/{while(1){操作系统课程设计报告5wgetchar=0;if(choiceend==1)printf(\n\nC:\\%s,strupr(dirname));elseprintf(Badcommandorfilename.\nC:\\%s,strupr(username));gets(choice);strcpy(choice,ltrim(rtrim(strlwr(choice))));if(strcmp(choice,dir)==0)choice1=1;elseif(strcmp(choice,create)==0)choice1=2;elseif(strcmp(choice,delete)==0)choice1=3;elseif(strcmp(choice,attrib)==0)choice1=4;elseif(strcmp(choice,open)==0)choice1=5;elseif(strcmp(choice,close)==0)choice1=6;elseif(strcmp(choice,read)==0)choice1=7;elseif(strcmp(choice,write)==0)choice1=8;elseif(strcmp(choice,exit)==0)choice1=9;elseif(strcmp(choice,cls)==0)choice1=10;elseif(strcmp(choice,cd)==0)choice1=11;elseif(strcmp(choice,help)==0)choice1=20;elsechoice1=12;switch(choice1){case1:DirF();choiceend=1;break;case2:CreateF();choiceend=1;if(!wgetchar)getchar();break;case3:DeleteF();choiceend=1;if(!wgetchar)getchar();break;