天津科技大学操作系统课程设计报告(共35页)_第1页
天津科技大学操作系统课程设计报告(共35页)_第2页
天津科技大学操作系统课程设计报告(共35页)_第3页
天津科技大学操作系统课程设计报告(共35页)_第4页
天津科技大学操作系统课程设计报告(共35页)_第5页
已阅读5页,还剩30页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精选优质文档-倾情为你奉上操作系统课程设计报告专 业:学 号:姓 名提交日期:【设计目的】1、本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现。2、结合数据结构、程序设计、计算机原理等课程的知识,设计一个二级文件系统,进一步理解操作系统。.【设计内容】为Linux系统设计一个简单的二级文件系统。要求做到以下几点:可以实现下列几条命令:login 用户登录dir 列目录create 创建文件delete 删除文件open 打开文件close 关闭文件read 读文件write 写文件cd 进出目录列目录时要列出文件名,物理地址,保护码和文件长度源文件可以进行读

2、写保护.【实验环境】Windows7操作平台Visual Studio2010【相关知识综述】理解二级目录的文件系统的组织;掌握常用的数据结构;系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件;使用文件来模拟外存,进行数据结构设计和操作算法的设计,实现一个文件系统并实现基本的文件操作(为了简便文件系统,不考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容)。【设计思路】采用的数据结构、主要的函数说明、程序流程设计等本文件系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件。另外,为了简便文件系统未考虑文件共享,文件系统安全以及管道文件与设备文

3、件等特殊内容。首先应确定文件系统的数据结构:主目录、子目录及活动文件等。主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。用户创建的文件,可以编号存储于磁盘上。如:file0,file1,file2并以编号作为物理地址,在目录中进行登记1.主要的数据结构#define MAXNAME 25 /*the largest length of mfdname,ufdname,filename表示三种文件的长度都为25*/#define MAXCHILD 50 /*the largest child每个用户下可以有50个文件*/#define MAX (MAXCHILD*MAXCHILD)

4、/*the size of fpaddrno定义一个常量2500个扇区*/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 str

5、ucture of OSUFD*/char ufdnameMAXNAME; /*ufd name*/OSFILE ufdfileMAXCHILD; /*ufd own file*/OSUFD;/*osf文件的数据结构*/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-o

6、pen*/ 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 CdF(); /*Change Dir*/void CreateF(); /*Create File*/void DeleteF(); /*Delete File*/void ModifyFM(); /*Modify FileMode*/void OpenF();

7、/*Open File*/void CloseF(); /*Close File*/void ReadF(); /*Read File*/void WriteF(); /*Write File*/void QuitF(); /*Quit FileSystem退出文件系统*/void help();3总体功能程序结构图打开命令的程序流程图 关闭命令的程序流程图写命令程序流程图 删除命令的程序流程图:【源程序清单】#include stdio.h#include string.h#include conio.h#include stdlib.h#define MAXNAME 25 /*the la

8、rgest length of mfdname,ufdname,filename表示三种文件的长度都为25*/#define MAXCHILD 50 /*the largest child每个用户下可以有50个文件*/#define MAX (MAXCHILD*MAXCHILD) /*the size of fpaddrno定义一个常量2500个扇区*/typedef struct /*the structure of OSFILE*/int fpaddr; /*file physical address物理地址*/ int flength; /*file length文件长度*/ int f

9、mode; /*file mode:0-Read Only;1-Write Only;2-Read and Write; 3-Protect;文件标识可读可写可执行*/ char fnameMAXNAME; /*file name文件名*/ OSFILE;/osfile文件的数据结构,一级文件系统上创建的文件上例如WANGFANG存储的就是这些内容typedef struct /*the structure of OSUFD*/char ufdnameMAXNAME; /*ufd name*/OSFILE ufdfileMAXCHILD; /*ufd own file*/OSUFD;/*osf

10、文件的数据结构*/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;OS

11、UFD *ufdMAXCHILD; /*ufd and ufd own files将osfile实例化ufd,有50个指向该结构的指针*/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定义了一个字符数组,存放

12、用户名最大可放25个*/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()

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

14、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 E

15、xist-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);int main()int i,choice1;char choice50; /*choice operation:dir,create,delete,open,delete,m

16、odify,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语句的目的只是为了检测该文件是否存在,若不存在则创建if(fp_mfd=fopen(c:osfilemfd.txt,rb)=NULL)/以只写的方式打开文件,返回一个指针,若不存在fp_mfd=fopen(c:os

17、filemfd.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);/将输入的值赋给choice if (strcmp(choice,dir)=0) choice1=1;/依次将输入的值与dir,create等等进行比较 else if

18、(strcmp(choice,create)=0) choice1=2;/如果输入create 则将choice1置为2通过switch进行选择 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

19、(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;/choicel=12时跳转到default:choiceend=0;因为while(1)所以要不断循环switch(choice1)case 1:DirF()

20、;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) get

21、char();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;de

22、fault: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;/n为字符串的长度减1while(n=0)/if(*(str+n)!= )/末尾不存在

23、空格*(str+n+1)=0;/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!

24、 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(log

25、inpw); /*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 Success

26、ful! 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 ad

27、dress 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

28、;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;fo

29、r(j=0;j0)/且密码个数大于0j-;j-;putchar(b);putchar( );putchar(b);/b表示退格putchar函数只能用于单个字符的输出,且一次只能输出一个字符else j-;elsepasswordj=0;/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:%s

30、dirn,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(

31、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=

32、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 inp

33、ut 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;ch

34、ar 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);w

35、getchar=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);

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论