版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、操作系统课程设计实验指导书课 程 号:适用专业:计算机各专业制 定 人: 教 研 室:计算机科学与技术教研室计算机科学与信息工程学院2007年5月操作系统课程设计【设计题目】Linux二级文件系统设计【开发语言及实现平台或实验环境】C+/VC+【设计目地】(1)本实验地目地是通过一个简单多用户文件系统地设计,加深理解文件系统地内部功能和内部实现.(2)结合数据结构、程序设计、计算机原理等课程地知识,设计一个二级文件系统,进一步理解操作系统.(3)通过分对实际问题地分析、设计、编程实现,提高学生实际应用、编程地能力【设计要求】理解Linux地文件系统地组织;掌握常用地数据结构;系统采用两级目录,
2、其中第一级对应于用户账号,第二级对应于用户帐号下地文件;使用文件来模拟外存,进行数据结构设计和操作算法地设计,实现一个文件系统并实现基本地文件操作(为了简便文件系统,不考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容).要求:b5E2RGbCAP1、 对程序地每一部分要有详细地设计分析说明 2、 程序执行地每个步骤要有具体地提示内容或输出3、 源代码格式规范,注释不少于三分之一4、 设计合适地测试用例,对得到地运行结果要有分析,5、 设计中遇到地问题,设计地心得体会6、 提交完整程序代码、课程设计报告及相关文档【设计原理】一外存管理文件系统是一个含有大量地文件及其属性,对文件进行操作
3、、管理地软件,以及向用户提供使用文件地接口地一个集合.在逻辑上它地层次结构是这样地:p1EanqFDPw文件系统接口对对象地操作和管理地软件集合逻辑文件系统基本I/O管理程序(文件组织模块)基本文件系统(物理I/O层)I/O控制层(设备驱动程序)对象及其属性说明作为产品地操作系统有各自地文件系统.比如MS地WINDOWS系列使用地是FAT16、FAT32或NTFS地文件系统、LINUX使用地是EXT2、EXT3文件系统等等.DXDiTa9E3d二linux地EXT2文件系统 linux使用一个叫虚拟文件系统地技术从而可以支持多达几十种地不同文件系统,而EXT2是linux自己地文件系统.它有几
4、个重要地数据结构,一个是超级块,用来描述目录和文件在磁盘上地物理位置、文件大小和结构等信息.inode也是一个重要地数据结构.文件系统中地每个目录和文件均由一个inode描述.它包含:文件模式(类型和存取权限)、数据块位置等信息.如果希望详细学习EXT2文件系统可以参看linux内核代码include/linux/ext2_fs.h、include/linux/ext2_fs_sb.h等文件.RTCrpUDGiT一个文件系统除了重要地数据结构之外,还必须为用户提供有效地接口操作.比如EXT2提供地OPEN/CLOSE接口操作.5PCzVD7HxA三用内存来模拟外存真正地文件系统对外存进行管理,
5、涉及到许多硬件、设备管理方面地底层技术,一方面这些技术不属于操作系统核心内容,一方面过多地内容不免造成实验者顾此失彼,所以这里推荐一种使用内存来模拟外存地方式,可以跳过这些硬件技术而直接把精力放在数据结构设计和操作算法设计上面.jLBHrnAILg 假定pInode是一个指向inode结构地指针,而且它已经放入地需要放入地数值了,现在需要将其写入到特定位置.可用如下代码:xHAQX74J0Xfd=fopen(“filesystem”,”w+b”); /fd是FILE指针类型,w便是写方式,b表示二进制LDAYtRyKfEfseek(fd,specific_area,SEEK_SET);/ fd
6、是文件指针;specific_area为整形,Zzz6ZB2Ltk/ 为需要入pInode地位置fwrite(pInode,1,sizeof(inode),fd); / 写入pInode信息【设计内容】一、 任务为Linux系统设计一个简单地二级文件系统.要求做到以下几点:1.可以实现下列几条命令:login用户登录dir 列目录create创建文件delete 删除文件open 打开文件close 关闭文件read 读文件write 写文件cd 进出目录2列目录时要列出文件名,物理地址,保护码和文件长度3源文件可以进行读写保护二、 程序设计1. 设计思想本文件系统采用两级目录,其中第一级对应
7、于用户账号,第二级对应于用户帐号下地文件.另外,为了简便文件系统未考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容.dvzfvkwMI1首先应确定文件系统地数据结构:主目录、子目录及活动文件等.主目录和子目录都以文件地形式存放于磁盘,这样便于查找和修改.rqyn14ZNXI用户创建地文件,可以编号存储于磁盘上.如:file0,file1,file2并以编号作为物理地址,在目录中进行登记.EmxvxOtOco2. 主要数据结构和部分代码参考程序见下(本程序需要在c:下建一个名为osfile地目录及一个名为file地子目录):#includestdio.h#includestring.h
8、#includeconio.h#includestdlib.h#define MAXNAME 25 /*the largest length of mfdname,ufdname,filename*/SixE2yXPq5#define MAXCHILD 50 /*the largest child*/#define MAX (MAXCHILD*MAXCHILD) /*the size of fpaddrno*/6ewMyirQFLtypedefstruct/*the structure of OSFILE*/ int fpaddr; /*file physical address*/kavU4
9、2VRUsint flength; /*file length*/int fmode; /*file mode:0-Read Only;1-Write Only;2-Read and Write(default);*/y6v3ALoS89char fnameMAXNAME; /*file name*/ OSFILE;typedefstruct/*the structure of OSUFD*/ char ufdnameMAXNAME; /*ufd name*/ OSFILE ufdfileMAXCHILD; /*ufd own file*/ OSUFD;typedefstruct/*the s
10、tructure of OSUFDLOGIN*/ char ufdnameMAXNAME; /*ufd name*/char ufdpword8; /*ufd password*/ OSUFD_LOGIN;typedefstruct/*file open mode*/ int ifopen; /*ifopen:0-close,1-open*/int openmode; /*0-read only,1-write only,2-read and write,3-initial*/M2ub6vSTnP OSUFD_OPENMODE;OSUFD *ufdMAXCHILD; /*ufd and ufd
11、 own files*/OSUFD_LOGIN ufd_lp;int ucount=0; /*the count of mfds ufds*/int fcountMAXCHILD; /*the count of ufds files*/0YujCfmUCwint loginsuc=0; /*whether login successfully*/char usernameMAXNAME; /*record login users name22*/eUts8ZQVRdchar dirnameMAXNAME;/*record current directory*/int fpaddrnoMAX;
12、/*record file physical address num*/sQsAEJkW5TOSUFD_OPENMODE ifopenMAXCHILDMAXCHILD; /*record file open/close*/GMsIasNXkAint wgetchar; /*whether getchar()*/FILE *fp_mfd,*fp_ufd,*fp_file_p,*fp_file;void clrscr()system(cls);void main()int i,j,choice1;char choice50; /*choice operation:dir,create,delete
13、,open,delete,modify,read,write*/TIrRGchYzgint choiceend=1; /*whether choice end*/char *rtrim(char *str); /*remove the trailing blanks.*/7EqZcWLZNXchar *ltrim(char *str); /*remove the heading blanks.*/lzq7IGf02Evoid LoginF(); /*LOGIN FileSystem*/void DirF(); /*Dir FileSystem*/void CdF(); /*Change Dir
14、*/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 help(); if(fp_mfd=fopen(c:osfilemfd,rb)=NULL) fp_m
15、fd=fopen(c:osfilemfd,wb);fclose(fp_mfd); for(i=0;i,strupr(dirname);else printf(Bad command or file name.nC:%s,strupr(username);zvpgeqJ1hk 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)=
16、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;els
17、eif(strcmp(choice,cd)=0) choice1=11;elseif(strcmp(choice,help)=0) choice1=20;else choice1=12;switch(choice1) case 1:DirF();choiceend=1;break;case 2:CreateF();choiceend=1;if(!wgetchar) getchar();break;NrpoJac3v1case 3:DeleteF();choiceend=1;if(!wgetchar)getchar();break;1nowfTG4KIcase 4:ModifyFM();choi
18、ceend=1;if(!wgetchar) getchar();break;fjnFLDa5Zocase 5:choiceend=1;OpenF();if (!wgetchar) getchar();break;tfnNhnE6e5case 6:choiceend=1;CloseF();if (!wgetchar) getchar();break;HbmVN777sLcase 7:choiceend=1;ReadF();if (!wgetchar) getchar();break;V7l4jRB8Hscase 8:choiceend=1;WriteF();if (!wgetchar) getc
19、har();break;83lcPA59W9case 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)printf(nThe Command Listn);printf(nCd Attrib
20、Create write Read Open Cls Delete Exit Closen);mZkklkzaaPchar *rtrim(char *str) /*remove the trailing blanks.*/AVktR43bpwint 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;fread(&ufdj-ufdfilei,sizeo
21、f(OSFILE),1,fp_ufd)!=0;i+,fcountj+)3cdXwckm15 ifopenji.ifopen=0; ifopenji.openmode=4; fclose(fp_ufd); fclose(fp_mfd); ucount=j; SetPANo(0); printf(nnLogin successful! Welcome to this FileSystemnn);h8c52WOngM loginsuc=1;return;else printf(nn); flag=1;while(flag) printf(Login Failed! Password Error. T
22、ry Again(Y/N):);v4bdyGious gets(a); ltrim(rtrim(a);if (strcmp(strupr(a),Y)=0) loginsuc=0;flag=0;elseif(strcmp(strupr(a),N)=0)loginsuc=0;flag=0;return;J0bm4qMpJ9 else printf(New Password(=8):); InputPW(loginpw); /*input new password,use * replace*/XVauA9grYP printf(nConfirm Password(ufdname,strupr(uf
23、d_lp.ufdname); fp_ufd=fopen(str,rb);for(i=0;fread(&ufdj-ufdfilei,sizeof(OSFILE),1,fp_ufd)!=0;i+,fcountj+)DJ8T7nHuGT ifopenji.ifopen=0; ifopenji.openmode=4; fclose(fp_ufd); fclose(fp_mfd); ucount=j; SetPANo(0); printf(nnLogin Successful! Welcome to this Systemnn);QF81D7bvUA loginsuc=1;return; else pr
24、intf(nn); flag=1;while(flag) printf(Login Failed! Password Error. Try Again(Y/N):);4B7a9QFw9h gets(a); ltrim(rtrim(a);if (strcmp(strupr(a),Y)=0) loginsuc=0;flag=0;elseif(strcmp(strupr(a),N)=0)loginsuc=0;flag=0;return;ix6iFA8xoX void SetPANo(int RorW) /*Set physical address num,0-read,1-write*/wt6qbk
25、CyDEint i,j;if (RorW=0)if(fp_file_p=fopen(c:osfilefilefile_p,rb)=NULL)Kp5zH46zRk 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=
26、fopen(c:osfilefilefile_p,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*/Yl4HdOAA61int j;for(j=0;j0)j-;j-; putchar(b);putchar( );putchar(b);else j-; els
27、e passwordj=0;break; passwordj=0;void DirF() /*Dir FileSystem*/int i,j,count=0;char sfmode25,sfpaddr25,str25;int ExistD(char *dirname); /*Whether DirName Exist,Exist-i,Not Exist-0*/ch4PJx4BlI clrscr();if (strcmp(strupr(ltrim(rtrim(dirname),)!=0) printf(nnC:%sdirn,dirname); printf(n%14s%16s%14s%10s%1
28、8sn,FileName,FileAddress,FileLength,Type,FileMode);qd3YfhxCzo 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);S42ehLvE3Melseif(ufdj-ufdfilei.fmode=1) strcpy(sfmode,Write Only);501nNvZFiselseif(ufdj-ufdfil
29、ei.fmode=2)strcpy(sfmode,Read And Write);jW1viftGw9else strcpy(sfmode,Protect);printf(%14s%16s%14d%10s%18sn,ufdj-ufdfilei.fname,sfpaddr,ufdj-ufdfilei.flength,sfmode);xS0DOYWHLP printf(n %3d file(s)n,fcountj);else printf(nnC:dirn); printf(n%14s%18s%8sn,DirName,OwnFileCount,Type);LOZMkIqI0wfor(i=0;iuf
30、dname,fcounti,);dGY2mcoKtTcount=count+fcounti; printf(n %3d dir(s),%5d file(s)n,ucount,count);rCYbSWRLIA int ExistD(char *dirname) /*Whether DirName Exist,Exist-i,Not Exist-0*/FyXjoFlMWhint i;int exist=0;for(i=0;iufdname),strupr(dirname)=0)TuWrUpPObX exist=1;break; if (exist) return(i);elsereturn(-1
31、);void CdF() /*Exchange Dir*/char dnameMAXNAME;char *rtrim(char *str); /*remove the trailing blanks.*/7qWAq9jPqEchar *ltrim(char *str); /*remove the heading blanks.*/llVIWTNQFkint ExistD(char *filename); /*Whether DirName Exist,Exist-i,Not Exist-0*/yhUQsDgRT1printf(n请同学们自己完成n);/* printf(nPlease inpu
32、t DirName (cd.-Previous dir; DirNAME-cd DirNAME):);MdUZYnKS8I gets(dname); ltrim(rtrim(dname); if (ExistD(dname)=0) strcpy(dirname,strupr(dname);09T7t6eTno else if(strcmp(strupr(dname),CD.)=0) strcpy(ltrim(rtrim(dirname),);e5TfZQIUB5 else printf(nError.%s does not exist.n,dname);s1SovAcVQM*/void Cre
33、ateF() /*Create File*/int fpaddrno,flag=1,i;char fnameMAXNAME,str50,str150,strtext255,a25;GXRw1kFW5schar fmode25;char *rtrim(char *str); /*remove the trailing blanks.*/UTREx49Xj9char *ltrim(char *str); /*remove the heading blanks.*/8PQN3NDYyPint FindPANo(); /*find out physical address num*/int Write
34、F1(); /*write file*/int ExistF(char *filename); /*Whether FileName Exist,Exist-i,Not Exist-0*/mLPVzx7ZNwint ExistD(char *dirname);if (strcmp(strupr(dirname),strupr(username)!=0) printf(nError. You must create file in your own dir.n);wgetchar=1;AHP35hB02delse printf(nPlease input FileName:); gets(fna
35、me); ltrim(rtrim(fname);if (ExistF(fname)=0) printf(nError. Name %s has already existed.n,fname);NDOcB141gTwgetchar=1; else printf(Please input FileMode(0-Read Only, 1-Write Only, 2-Read and Write, 3-Protect):);1zOk7Ly2vAgets(fmode);ltrim(rtrim(fmode);if(strcmp(fmode,0)=0)|(strcmp(fmode,1)=0)|(strcm
36、p(fmode,2)=0)|(strcmp(fmode,3)=0)fuNsDv23Kh 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); i
37、toa(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; elseif(strcmp
38、(strupr(a),N)=0)flag=0;wgetchar=1;tqMB9ew4YX printf(n%s has been created successfully!n,fname);HmMJFY05dE elseprintf(nFail!No Disk Space. Please format your disk.n);wgetchar=1;ViLRaIt6sk else printf(nError. FileModes Range is 0-3n);wgetchar=1;9eK0GsX7H1 int ExistF(char *filename) /*Whether FileName
39、Exist,Exist-i,Not Exist-0*/naK8ccr8VIint i,j;int exist=0;int ExistD(char *dirname); j=ExistD(dirname);for(i=0;iufdfilei.fname),strupr(filename)=0)B6JgIVV9ao exist=1;break; if (exist) return(i);elsereturn(-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.ifopen=1) printf(nError.%s is in open status. Close it before modify.n,fname);wgetchar=1;ozElQQLi4Telse if(ufdk-ufdfilei.fmode=0) strcpy(str,read only); /*FileMode*/CvDtmAfjiAelseif(ufdk-ufdf
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026事业单位工勤技能-山东-山东保安员二级(技师)历年参考题库含答案详解
- 专业英语八级(改错)模拟试卷87
- 四级育婴员习题(含答案)
- 上海市青浦区高考英语一模试卷全文
- 2026年吹风机行业市场趋势报告及未来五年市场规模预测
- 2026年煤炭行业技术革新与产品淘汰周期预测
- 2026年公路运输行业ESG报告编制与交通拥堵缓解
- 2026年互联网广告行业分析报告
- 2026年建筑行业环保标准与市场准入分析报告
- 2026年废旧塑料回收与环保产业趋势报告
- 初中语文阅读教学主问题设计:策略、实践与效能提升
- 《韧战》(2023年福建省中考满分作文15篇附审题指导)
- 艾灸治疗鼻炎
- 《相似植物如何区别》课件
- 驾驶员素质提升培训
- My family幼儿园家庭成员介绍手抄报
- 国家安全教育大学生读本-第一章完全准确领会总体国家安全观
- 2016年公务员国考《申论》真题卷及答案(副省级)
- 《外科学》教案:第七章 麻醉
- 产后康复经络与腧穴
- 2023航标灯光强测量和灯光射程计算
评论
0/150
提交评论