实验六 文件系统设计结果

上传人:第*** 文档编号:30560528 上传时间:2018-01-30 格式:DOC 页数:23 大小:97.50KB
返回 下载 相关 举报
实验六  文件系统设计结果_第1页
第1页 / 共23页
实验六  文件系统设计结果_第2页
第2页 / 共23页
实验六  文件系统设计结果_第3页
第3页 / 共23页
实验六  文件系统设计结果_第4页
第4页 / 共23页
实验六  文件系统设计结果_第5页
第5页 / 共23页
点击查看更多>>
资源描述

《实验六 文件系统设计结果》由会员分享,可在线阅读,更多相关《实验六 文件系统设计结果(23页珍藏版)》请在金锄头文库上搜索。

1、 1 / 23实验六 文件系统设计1目的和要求本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现。2实验内容为 DOS 系统设计一个简单的二级文件系统,可以实现下列几条命令DIR 列文件目录CREATE 创建文件DELETE 删除文件MODIFY 修改文件OPEN 打开文件CLOSE 关闭文件列目录时要列出文件名,物理地址,保护码和文件长度。3实验环境PC 兼容机Windows、DOS 系统、Turbo c 2.0C 语言4实验提示首先应确定文件系统的数据结构:主目录、活动文件等。主目录文件的形式存放于磁盘,这样便于查找和修改。主目录结构:Ufdname 用户

2、名Ufdfile 指向用户的活动文件活动文件结构:Fpaddr 文件物理地址Flength 文件长度 Fmode 文件属性(file mode:0-Read Only;1-Write Only;2-Read and Write(default))Fname 文件名称用户创建的文件,可以编号存储于磁盘上。如:file0,file1,file2并 2 / 23以编号作为物理地址,在目录中进行登记。本程序需要在 c:下建一个名为 osfile 的目录及一个名为 file 的子目录,在利用程序创建了文件系统后,可以在这个文件夹下查看到相关的内容。5实验程序#include stdio.h#includ

3、e string.h#include conio.h#include stdlib.h#define MAXNAME 25 /*the largest length of mfdname,ufdname,filename*/#define MAXCHILD 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;

4、 /*file length*/int fmode; /*file mode:0-Read Only;1-Write Only;2-Read and Write(default);*/char fnameMAXNAME; /*file name*/ OSFILE;typedef struct /*the structure of OSUFD*/char ufdnameMAXNAME; /*ufd name*/OSFILE ufdfileMAXCHILD; /*ufd own file*/OSUFD;typedef struct /*the structure of OSUFDLOGIN*/ch

5、ar 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 ufd own files*/OSUFD_LOGIN ufd_lp;int uc

6、ount=0; /*the count of mfds ufds*/ 3 / 23int fcountMAXCHILD; /*the count of ufds files*/int loginsuc=0; /*whether login successfully*/char usernameMAXNAME; /*record login users name22*/char dirnameMAXNAME;/*record current directory*/int fpaddrnoMAX; /*record file physical address num*/OSUFD_OPENMODE

7、 ifopenMAXCHILDMAXCHILD; /*record file open/close*/int wgetchar; /*whether getchar()*/FILE *fp_mfd,*fp_ufd,*fp_file_p,*fp_file;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);

8、/*remove the trailing blanks.*/char *ltrim(char *str); /*remove the heading blanks.*/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

9、*/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_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);g

10、ets(choice);strcpy(choice,ltrim(rtrim(strlwr(choice);if (strcmp(choice,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

11、;else if(strcmp(choice,read)=0) choice1=7;else if(strcmp(choice,modify)=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();choice

12、end=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:choiceend=1;OpenF();if (!wgetchar) getchar();break;case 6:choiceend=1;CloseF();if (!wgetchar) getchar();

13、break;case 7:choiceend=1;ReadF();if (!wgetchar) getchar();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:ch

14、oiceend=0;else printf(nAccess denied.); 5 / 23void help(void)printf(nThe Command Listn);/*printf(nCd Attrib Create Modify Read Open Cls Delete Exit Closen);*/printf(Create : Create a file(You can initialize files attribute and content.)n);printf(Open : Open a file to modifyn);printf(Close : Close a

15、file.n);printf(Modify : Modify the opened file.n);printf(Delete : Delete existed files.n);printf(CD : Change current directory.n);printf(Exit : Exit this program.n);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;fread(&ufdj-ufdfilei,sizeof(OSFILE),1,fp_ufd)!=0;i+

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 其它办公文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号