操作系统课程设计报告77292

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

专业:学号:姓名:提交日期:操作系统课程设计报告—欢迎下载1【设计目的】(1)本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现。(2)结合数据结构、程序设计、计算机原理等课程的知识,设计一个二级文件系统,进一步理解操作系统。(3)通过分对实际问题的分析、设计、编程实现,提高学生实际应用、编程的能力【设计内容】为Linux系统设计一个简单的二级文件系统。要求做到以下几点:1.可以实现下列几条命令:login用户登录dir列目录create创建文件delete删除文件open打开文件close关闭文件read读文件write写文件cd进出目录2.列目录时要列出文件名,物理地址,保护码和文件长度3.源文件可以进行读写保护【实验环境】C++/VC++【源程序清单】#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;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;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*/voidWriteF();/*WriteFile*/voidQuitF();/*QuitFileSystem*/voidhelp();char*rtrim(char*str);/*removethetrailingblanks.*/—欢迎下载3char*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);}intmain(){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){wgetchar=0;if(choiceend==1)printf(\n\nC:\\%s,strupr(dirname));elseprintf(Badcommandorfilename.\nC:\\%s,strupr(username));—欢迎下载4gets(choice);//输入所选择的strcpy(choice,ltrim(rtrim(strlwr(choice))));//将输入的值赋给choiceif(strcmp(choice,dir)==0)choice1=1;//依次将输入的值与dir,create等进行比较elseif(strcmp(choice,create)==0)choice1=2;//如果输入create将choice1置为2通过switch选择,以下依次类推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;//choice1=12时跳转到default,然后继续循环switch(choice1){case1:DirF();choiceend=1;break;case2:CreateF();choiceend=1;if(!wgetchar)getchar();break;case3:DeleteF();choiceend=1;if(!wgetchar)getchar();break;case4:ModifyFM();choiceend=1;if(!wgetchar)getchar();break;case5:OpenF();choiceend=1;if(!wgetchar)getchar();break;case6:CloseF();choiceend=1;if(!wgetchar)getchar();break;case7:ReadF();choiceend=1;if(!wgetchar)getchar();break;case8:WriteF();choiceend=1;if(!wgetchar)getchar();break;case9:printf(\nYouhaveexitedthissystem.);QuitF();exit(0);break;case10:clrscr();choiceend=1;break;case11:CdF();choiceend=1;break;case20:help();choiceend=1;break;default:choiceend=0;}}}elseprintf(\nAccessdenied.);//登录成功}voidhelp(void){printf(\nTheCommandList\n);—欢迎下载5printf(\nCdAttribCreatewriteReadOpenClsDeleteExitClose\n);}char*rtrim(char*str)/*除去末尾端的空格指针指向字符串第一个*/{intn=strlen(str)-1;//n为字符串长度减1while(n=0){if(*(str+n)!='')//末尾不存在空格{*(str+n+1)='\0';//'\n'表示结束符break;}elsen--;//如果存在空格将空格去掉}if(n0)str[0]='\0';returnstr;}char*ltrim(char*str)/*除去前端的空格*/{strrev(str);//把字符串str的所有字符的顺序颠倒rtrim(str);//去掉尾端空格strrev(str);//再颠倒过来returnstr;}voidLoginF()/*LOGINFileSystem*/{charloginame[MAXNAME],loginpw[9],logincpw[9],str[50];inti,j,flag=1;chara[25];intfindout;/*loginusernotexist*/while(1){findout=0;printf(\n\nLoginName:);gets(loginame);//输入字符串ltrim(rtrim(loginame));//去掉前后端的空格fp_mfd=fopen(c:\\osfile\\mf

1 / 27
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功