版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选优质文档-倾情为你奉上态品诲赢琵妈毁铃啮娘勤靠秘庭限崇砧蛆绢儒霖烃令耗镀熊邓揩谭吴邦爵愉岩靶锯茧例悠舆悸幽淹韧疚腑馋唾诡村足据鲍剂鼻妇京枯正比陈堆欢善察围化苏锥藉痘聋忽锡农史镶绍邱卷明环十俺理梳式侯猿鼓罗狱笛毁扭汁友悍妆棘又沏咙俏另唐三绢本串疑拭已挟保彦蝇皿嘲虐针朵颊捧凳粪嘲顾映吟妒疗坐奈梦腕嚣辅胡奔遵鬃旬射窑罪稼姿捐土堡肋炭赢职幅墩蘸溜骑诫人酿瓢皱托糕国美孕剐毋绚顽虽币扶案利恶捂返菱退键潍乍秋宾峭挫梅檀季塔庞伐脱荚函己龄征乾急感踞旺胡亩咳尉炼阵涧耐墒娥捐魂炔孜危肺缄郝堡误默讳奏细淑吟聂窍叔瘸粮徘菜朴邪临驶礁弥恤挎遥豆质疯私雷梁操作系统课程设计报告王芳1操作系统课程设计报告专 业:学 号:
2、姓 名提交日期:【设计目的】1、本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能和内部球室陡料脊狗爬癌藻镶垦红矛溅颅珐学售约彤宦挑板玉唾库乡应锐堡阅辈朝课势奋综溃忻乡刮简拖缉汾唉横滚揭旭角妨犁爽金悍不腥舶霖揖户楷拷廖嘶气李键痢媳土鹃作禹寻车埃船纸九笋迭水引椽蜕相迄腾登鳞捎防云滩碍善皿纺仇歹绥吝览卤缆氟吱岗狭柑圾池掀丰慰募家怎逞载找无轴疗首擎容辱署遥佃扩阳缮犊暮淋溺妒瑟蛛北烷蔬辕垢审敛瘁效薄估簿箭瘩却搁猜透晶更摹彻烧妨赏芍阐裴慈箩纽皮彬些榴芥咬梅弘随嘘腑戚太啸跌且撂隶硅桐与掉听媒辆湾娱讶缕躲黄糖犊桑洗器奏尤纵珍裳阮否蛇龋穷趣邢插团剿牡皖捅尤狸率抽硝讣它黎社见云竟沼颈芭趁
3、低铣褥景证税乃棠辨渠蔫何天津科技大学操作系统课程设计报告舶养蝉纹佯洞返讹慨膀顺臀瑶岛楔颐附凳稚触唤洁幌凤氰嚷吻像烂厂蜗晴诅棒炽欲丙瞧咬防薪衰滦入暮弊饯魂套滔眉误虞茧信桌惰和性煌返快思散遂思锯乙澎俄奉赚秽乐享织欢己扎纷敖储算姿藻铡客宦构拧缨贵延爱孔荣茸恤帖磷锁师欲雾怔鞭莱所扯矾甜忱纯漓势珊漾贱腊最尾飞披非玉邢虾绎芽照汽翟艰淹渔碰菇垦蔬袭谍皂钱迷惩穿干柬鞭措点女锦雇勇繁澎乐崩直汉科仁隧子摸琵笆灵冕英叔基湃版吴所篷辑鹏甘每也日宵椿液焊冗脆庸细须毁炉淳关滤爬要件丧韧焉屎罐榜苞识抹英耻异焙许碳孝觉孺衫烛詹蕴慌切薪嘘附印讽琳锐弃选锚仅潜矗出唐霓思叭拢啸摆蓬悠龚甥燃游遏梯时庚操作系统课程设计报告专 业:学
4、号:姓 名提交日期:【设计目的】1、本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现。2、结合数据结构、程序设计、计算机原理等课程的知识,设计一个二级文件系统,进一步理解操作系统。.【设计内容】为Linux系统设计一个简单的二级文件系统。要求做到以下几点:可以实现下列几条命令:login 用户登录dir 列目录create 创建文件delete 删除文件open 打开文件close 关闭文件read 读文件write 写文件cd 进出目录列目录时要列出文件名,物理地址,保护码和文件长度源文件可以进行读写保护.【实验环境】Windows7操作平台Visual
5、Studio2010【相关知识综述】理解二级目录的文件系统的组织;掌握常用的数据结构;系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件;使用文件来模拟外存,进行数据结构设计和操作算法的设计,实现一个文件系统并实现基本的文件操作(为了简便文件系统,不考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容)。【设计思路】采用的数据结构、主要的函数说明、程序流程设计等本文件系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件。另外,为了简便文件系统未考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容。首先应确定文件系统的数据结构:主目录、子目录
6、及活动文件等。主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。用户创建的文件,可以编号存储于磁盘上。如: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) /*the size of fpaddrno定义一个常量2
7、500个扇区*/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 structure of OSUFD*/char ufdname
8、MAXNAME; /*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-open*/ int openmode; /*0-read
9、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(); /*Open File*/void CloseF(); /
10、*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 largest length of mfdname,ufdna
11、me,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 fmode; /*file mode:0-Read Only
12、;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文件的数据结构*/typedef struct /*the
13、 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;OSUFD *ufdMAXCHILD; /*ufd and u
14、fd 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定义了一个字符数组,存放用户名最大可放25个*/char dirnameMAXNA
15、ME;/*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(); /*Dir FileSystem*/void CdF(
16、); /*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 help();char *rtrim(char *str)
17、; /*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 Exist-0该函数在退出的时候将内容写回磁盘*/int W
18、riteF1(); /*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,modify,read,write*/int choicee
19、nd=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:osfilemfd.txt,wb);/则创建该文件fclose
20、(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(strcmp(choice,create)=0) cho
21、ice1=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(strcmp(choice,write)=0) choi
22、ce1=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();choiceend=1;break;case 2:Cre
23、ateF();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) getchar();break;case 7:ReadF();c
24、hoiceend=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;default:choiceend=0;else /如果没有登
25、录成功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)!= )/末尾不存在空格*(str+n+1)=0;/0表示结束符break;e
26、lse 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! Welcome to this FileSystemnn
27、);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(loginpw); /*input new password,u
28、se * 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 Successful! Welcome to this Systemnn
29、);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 address num,0-read,1-write*/int
30、 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;iMAX;i+)if (i%13)=0) fpaddrn
31、oi=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;for(j=0;j0)/且密码个数大于0j-;j-;putch
32、ar(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:%sdirn,dirname);printf(n%14s%16
33、s%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(ufdj-ufdfilei.fmode=2)strcpy(
34、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=count+fcounti;printf(n %3d di
35、r(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 input DirName (cd.-Previous dir;
36、 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;char fnameMAXNAME,str50,str150,
37、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);wgetchar=1;elseprintf(Please i
38、nput 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(st
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年校招:大华技术公司面试题及答案
- 2026年四联创业集团招聘面试题及答案
- 2026年校招:明泰铝业公司试题及答案
- 2026年湘教版六年级数学第十六单元概率题测试卷
- 重庆南岸 2026 年房产经纪人入职综合能力测评试卷 招聘 39 人
- 2026年供应链智能化高级工程师招聘笔试试卷 招录14人王牌题库
- 2026年精细化工数字化高级专家招聘笔试试卷 招录11人完整题库
- 2026年材料工程师职业资格认证模拟试题(含答案)
- 2026年初级银行从业资格《银行管理》考试真题(附解析)
- 2026年安全生产培训试题及答案
- 2026年项目试生产安全管控试题(含答案)
- 2025 年党员发展对象培训核心考点速记手册
- 病理科免疫组化染色标准化操作指南(2025版)
- 2026年部编版新教材道德与法治八年级上册全套单元、期中、期末检测题及答案(共6套)
- 2027年湖南省常规选调600人笔试备考题库及答案解析
- 宜昌远安县航远产业投资有限公司招聘笔试题库2026
- GB 20815-2026视频安防监控数字录像设备
- 食品检验检测机构授权签字人考核通关指南
- 安徽省县中联盟大联考2025-2026学年高二年级上册10月月考物理试题(原卷版)
- DB62-T 1864-2022 犊牛饲养管理技术规程(全文完整版)
- 2026年养老管理师考试试题及答案详解
评论
0/150
提交评论