操作系统课程设计实验指导书_第1页
操作系统课程设计实验指导书_第2页
操作系统课程设计实验指导书_第3页
操作系统课程设计实验指导书_第4页
操作系统课程设计实验指导书_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

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

文档简介

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

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

3、及向用户提供使用文件的接口的一个集合。在逻辑上它的层次结构是这样的:文件系统接口对对象的操作和管理的软件集合逻辑文件系统基本I/O管理程序(文件组织模块)基本文件系统(物理I/O层)I/O控制层(设备驱动程序)对象及其属性说明 作为产品的操作系统有各自的文件系统。比如MS的WINDOWS系列使用的是FAT16、FAT32或NTFS的文件系统、LINUX使用的是EXT2、EXT3文件系统等等。二linux的EXT2文件系统 linux使用一个叫虚拟文件系统的技术从而可以支持多达几十种的不同文件系统,而EXT2是linux自己的文件系统。它有几个重要的数据结构,一个是超级块,用来描述目录和文件在磁

4、盘上的物理位置、文件大小和结构等信息。inode也是一个重要的数据结构。文件系统中的每个目录和文件均由一个inode描述。它包含:文件模式(类型和存取权限)、数据块位置等信息。如果希望详细学习EXT2文件系统可以参看linux内核代码include/linux/ext2_fs.h、include/linux/ext2_fs_sb.h等文件。一个文件系统除了重要的数据结构之外,还必须为用户提供有效的接口操作。比如EXT2提供的OPEN/CLOSE接口操作。三用内存来模拟外存真正的文件系统对外存进行管理,涉及到许多硬件、设备管理方面的底层技术,一方面这些技术不属于操作系统核心内容,一方面过多的内容

5、不免造成实验者顾此失彼,所以这里推荐一种使用内存来模拟外存的方式,可以跳过这些硬件技术而直接把精力放在数据结构设计和操作算法设计上面。 假定pInode是一个指向inode结构的指针,而且它已经放入的需要放入的数值了,现在需要将其写入到特定位置。可用如下代码:fd=fopen(“filesystem”,”w+b”); /fd是FILE指针类型,w便是写方式,b表示二进制fseek(fd, specific_area,SEEK_SET);/ fd是文件指针;specific_area为整形,/ 为需要入pInode的位置fwrite(pInode,1,sizeof(inode),fd); / 写

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

7、录及活动文件等。主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。用户创建的文件,可以编号存储于磁盘上。如: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 MA

8、XCHILD 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

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

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

11、in 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

12、,*fp_file;void clrscr()system(cls);void main()int i,j,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.*/ vo

13、id 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(); /*Wri

14、te File*/ void QuitF(); /*Quit FileSystem*/ void help(); if(fp_mfd=fopen(c:osfilemfd,rb)=NULL) fp_mfd=fopen(c:osfilemfd,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(choic

15、e,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(choic

16、e,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) g

17、etchar();break;case 3:DeleteF();choiceend=1;if(!wgetchar)getchar();break;case 4:ModifyFM();choiceend=1;if(!wgetchar) getchar();break;case 5:choiceend=1;OpenF();if (!wgetchar) getchar();break;case 6:choiceend=1;CloseF();if (!wgetchar) getchar();break;case 7:choiceend=1;ReadF();if (!wgetchar) getchar(

18、);break;case 8:choiceend=1;WriteF();if (!wgetchar) getchar();break;case 9:printf(nYou have exited this system.); QuitF();exit(0);break;case 10:choiceend=1;clrscr();break;case 11:CdF();choiceend=1;break;case 20:help();choiceend=1;break;default:choiceend=0; else printf(nAccess denied.);void help(void)

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

20、;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; else printf(nn); flag=1; while(flag) printf(Login Failed! Passwor

21、d 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; else printf(New Password(=8):); InputPW(loginpw); /*input new password,use * replace*/ printf(nConfirm Password(ufdname,strupr(ufd_lp.ufdname); fp

22、_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; else printf(nn); flag=1; while(flag) print

23、f(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

24、,rb)=NULL) fp_file_p=fopen(c:osfilefilefile_p,wb); fclose(fp_file_p); fp_file_p=fopen(c:osfilefilefile_p,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,wb); /*for(i=1;iMAX;i+) if(i%13)=0) fpaddr

25、noi=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-; else passwordj=0; break; passwordj=0;void DirF() /*Dir FileSystem*/int i,j,c

26、ount=0; char sfmode25,sfpaddr25,str25; int ExistD(char *dirname); /*Whether DirName Exist,Exist-i,Not Exist-0*/ 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;

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

28、filei.fname,sfpaddr,ufdj-ufdfilei.flength,sfmode); printf(n %3d file(s)n,fcountj); else printf(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

29、,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; char *rtrim(char *str); /*remove the trailing blanks.*/ char *ltrim(char *str); /*remove the heading blanks.*/ int ExistD

30、(char *filename); /*Whether DirName Exist,Exist-i,Not Exist-0*/printf(n请同学们自己完成n);/* 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(dirn

31、ame),); else printf(nError.%s does not exist.n,dname);*/void CreateF() /*Create File*/int fpaddrno,flag=1,i; char fnameMAXNAME,str50,str150,strtext255,a25; char fmode25; char *rtrim(char *str); /*remove the trailing blanks.*/ char *ltrim(char *str); /*remove the heading blanks.*/ int FindPANo(); /*f

32、ind out physical address num*/ int WriteF1(); /*write file*/ int ExistF(char *filename); /*Whether FileName Exist,Exist-i,Not Exist-0*/ int ExistD(char *dirname); if (strcmp(strupr(dirname),strupr(username)!=0) printf(nError. You must create file in your own dir.n);wgetchar=1; else printf(nPlease in

33、put FileName:); gets(fname); ltrim(rtrim(fname); if (ExistF(fname)=0) printf(nError. Name %s has already existed.n,fname);wgetchar=1; else printf(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)|(

34、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(

35、fpaddrno,str1,10); strcat(str,str1); 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(

36、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 e

37、xist=0; int ExistD(char *dirname); 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

38、.ifopen=1) printf(nError.%s is in open status. Close it before modify.n,fname);wgetchar=1; else if(ufdk-ufdfilei.fmode=0) strcpy(str,read only); /*FileMode*/ else if(ufdk-ufdfilei.fmode=1) strcpy(str,write only); else if(ufdk-ufdfilei.fmode=2) strcpy(str,read and write); else strcpy(str,Protect); pr

39、intf(%s filemode is %s.n,fname,strupr(str); printf(Modify to(0-read only,1-write only,2-read and write,3-Protect):); gets(fmode); ltrim(rtrim(fmode); if(strcmp(fmode,0)=0) ufdk-ufdfilei.fmode=0;printf(n%s has been modified to READ ONLY mode successfully.n,fname);wgetchar=1; else if(strcmp(fmode,1)=0) u

温馨提示

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

评论

0/150

提交评论