操作系统课程设计二级文件系统.docx

上传人:b****5 文档编号:6091279 上传时间:2023-01-03 格式:DOCX 页数:52 大小:386.44KB
下载 相关 举报
操作系统课程设计二级文件系统.docx_第1页
第1页 / 共52页
操作系统课程设计二级文件系统.docx_第2页
第2页 / 共52页
操作系统课程设计二级文件系统.docx_第3页
第3页 / 共52页
操作系统课程设计二级文件系统.docx_第4页
第4页 / 共52页
操作系统课程设计二级文件系统.docx_第5页
第5页 / 共52页
点击查看更多>>
下载资源
资源描述

操作系统课程设计二级文件系统.docx

《操作系统课程设计二级文件系统.docx》由会员分享,可在线阅读,更多相关《操作系统课程设计二级文件系统.docx(52页珍藏版)》请在冰豆网上搜索。

操作系统课程设计二级文件系统.docx

操作系统课程设计二级文件系统

 

操作系统课程设计报告

 

专业:

计算机信息处理

学号:

********

******

提交日期:

2011-7-14

 

【设计目的】

1.课程设计目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现。

2.结合数据结构、程序设计、计算机原理等课程的知识,设计一个二级文件系统,进一步理解操作系统。

3.通过对实际问题的分析、设计、编程实现,提高学生实际应用、编程的能力

【设计内容】

1、delete删除文件

2、open打开文件

3、close关闭文件

4、write写文件

【实验环境】

Windows7系统

Visualstudio2010

【相关知识综述】

本文件系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件。

另外,为了简便文件系统未考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容。

首先应确定文件系统的数据结构:

主目录、子目录及活动文件等。

主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。

用户创建的文件,可以编号存储于磁盘上。

如:

file0,file1,file2…并以编号作为物理地址,在目录中进行登记。

【设计思路】

1主要数据结构

#defineMAXNAME25/*thelargestlengthofmfdname,ufdname,filename*/

#defineMAXCHILD50/*thelargestchild每个用户名下最多有50个文件*/

#defineMAX(MAXCHILD*MAXCHILD)/*thesizeoffpaddrno*/

typedefstruct/*thestructureofOSFILE定义主文件*/

{

intfpaddr;/*filephysicaladdress*/

intflength;/*filelength*/

intfmode;/*filemode:

0-ReadOnly;1-WriteOnly;2-ReadandWrite;3-Protect;*/

charfname[MAXNAME];/*filename*/

}OSFILE;

typedefstruct/*thestructureofOSUFD定义用户文件目录*/

{

charufdname[MAXNAME];/*ufdname*/

OSFILEufdfile[MAXCHILD];/*ufdownfile*/

}OSUFD;

typedefstruct/*thestructureofOSUFD'LOGIN定义登陆*/

{

charufdname[MAXNAME];/*ufdname*/

charufdpword[8];/*ufdpassword*/

}OSUFD_LOGIN;

typedefstruct/*fileopenmode定义操作方式*/

{

intifopen;/*ifopen:

0-close,1-open*/

intopenmode;/*0-readonly,1-writeonly,2-readandwrite,3-initial*/

}OSUFD_OPENMODE;

2主要函数

voidLoginF();/*LOGINFileSystem*/

voidDirF();/*DirFileSystem*/

voidCreateF();/*CreateFile*/

voidDeleteF();/*DeleteFile*/

voidModifyFM();/*ModifyFileMode*/

voidOpenF();/*OpenFile*/

voidCloseF();/*CloseFile*/

voidReadF();/*ReadFile*/

voidWriteF();/*WriteFile*/

voidQuitF();/*QuitFileSystem*/

voidCdF();/*ChangeDir*/

voidhelp();

【主要程序段】

1Delete函数

voidDeleteF()/*DeleteFile*/

{charfname[MAXNAME],str[50],str1[50];

inti,k,j;

intfpaddrno1;

if(strcmp(strupr(ltrim(rtrim(dirname))),"")==0)/*无法删除主目录的文件*/

{

printf("\nError.Pleaseconverttoufddirbeforedelete.\n");

wgetchar=1;

}

if(strcmp(strupr(dirname),strupr(username))!

=0)/*无法删除非自己目录的文件*/

{

printf("\nError.Youcanonlymodifyfilemodeinyourselfdir.\n");

wgetchar=1;

}

else

{

printf("\nPleaseinputFileName:

");

gets(fname);//从键盘获取所要删除的文件名

ltrim(rtrim(fname));

i=ExistF(fname);//获取文件编号

if(i>=0)

{

k=ExistD(username);

if(ifopen[k][i].ifopen==1)/*文件打开时无法删除*/

{

printf("\nError.\'%s\'isinopenstatus.Closeitbeforedelete.\n",fname);

wgetchar=1;

}

else

{

if(ufd[k]->ufdfile[i].fmode==3)/*被保护的文件无法删除*/

{

printf("\nError.\'%s\'isinprotectstatus.Closeitbeforedelete.\n",fname);

wgetchar=1;

}

else

{

fpaddrno1=ufd[k]->ufdfile[i].fpaddr;//获取文件对应的物理文件名

fpaddrno[fpaddrno1]=0;//回收盘块

for(j=i;j

{

ufd[k]->ufdfile[j]=ufd[k]->ufdfile[j+1];//从被删除的文件号开始,数组值全部前移一个

}

strcpy(str,"d:

\\osfile\\file\\file");

itoa(fpaddrno1,str1,10);//整数转化成字符串

strcat(str,str1);

strcat(str,".txt");

remove(str);//删除物理文件

fcount[k]--;//k用户文件数量少1

printf("\n\'%s\'isdeletedsuccessfully.\n",fname);

wgetchar=1;

}

}

}

else//所要删除的文件不存在

{

printf("\nError.\'%s\'dosenotexist.\n",fname);

wgetchar=1;

}

}

}

2Open函数

voidOpenF()/*OpenFile*/

{

charfname[MAXNAME];

inti,k,j;

if(strcmp(strupr(dirname),strupr(username))!

=0)/*在自己的目录里才能打开*/

{

printf("\nError.Youcanonlyopeninyourselfdir.\n");

wgetchar=1;

}

else

{

k=ExistD(username);

for(j=0;j

{

printf("%15s",ufd[k]->ufdfile[j].fname);

}

printf("\nPleaseinputFileName:

");

gets(fname);//获取所要打开的文件名

ltrim(rtrim(fname));

i=ExistF(fname);//获取目录编号

if(i>=0)

{

if(ifopen[k][i].ifopen==1)//输入的文件是打开的

{

printf("\nError.\'%s\'isinopenstatus.\n",fname);

wgetchar=1;

}

else

{

ifopen[k][i].ifopen=1;//修改为打开的

if(ufd[k]->ufdfile[i].fmode==0)/*根据文件的模式设置打开模式*/

{ifopen[k][i].openmode=0;}

elseif(ufd[k]->ufdfile[i].fmode==1)

{ifopen[k][i].openmode=1;}

elseif(ufd[k]->ufdfile[i].fmode==2)

{ifopen[k][i].openmode=2;}

elseifopen[k][i].openmode=3;

printf("\n\'%s\'isopenedsuccessfully\n",fname);

wgetchar=1;

}

}

else//文件不存在

{

printf("\nError.\'%s\'dosenotexist.\n",fname);

wgetchar=1;

}

}

}

3Close函数

voidCloseF()/*CloseFile*/

{

charfname[MAXNAME];

inti,k,j;

if(strcmp(strupr(dirname),strupr(username))!

=0)/*不在自己的目录里没法进行*/

{

printf("\nError.Youcanonlyclosefileinyourselfdir.\n");

wgetchar=1;

}

else

{

k=ExistD(username);

for(j=0;j

{

if(ifopen[k][j].ifopen==1)//如果文件是打开的

printf("%15s",ufd[k]->ufdfile[j].fname);

}

printf("\nPleaseinputFileName:

");

gets(fname);//从键盘上读入所要关闭的文件

ltrim(rtrim(fname));

i=ExistF(fname);//获取文件编号

if(i>=0)

{

ifopen[k][i].ifopen=0;/*关闭文件*/

printf("\n\'%s\'closedsuccessfully\n",fname);

wgetchar=1;

}

else//所要关闭的文件不存在

{

printf("\nError.\'%s\'dosenotexist.\n",fname);

wgetchar=1;

}

}

}

4Write函数

voidWriteF()/*WriteFile*/

{

inti,k,n=0;

intlength;

charfname[MAXNAME],values[1000];

charstr[255],str1[255],c;

if(strcmp(strupr(ltrim(rtrim(dirname))),"")==0)//只能写自己目录下的文件

{

printf("\nError.Pleaseconverttoufddirbeforewrite.\n");

wgetchar=1;

return;

}

printf("\nCaution:

Openfilefirst\n");

printf("OpenedFile(s)List:

\n");

k=ExistD(dirname);//获取目录编号

for(i=0;i

{

if(ifopen[k][i].ifopen==1)//如果文件是打开的

{

printf("%15s",ufd[k]->ufdfile[i].fname);

n++;

}

if((n%4==0)&&(n!

=0))printf("\n");

}

printf("\n%dfilesopenned.\n",n);

if(n==0)wgetchar=1;//没有打开的文件

if(n!

=0)

{

printf("\nPleaseinputFileName:

");

gets(fname);//从键盘获取所要写的文件

ltrim(rtrim(fname));

i=ExistF(fname);//获取文件编号

if(i>=0)

{

if(ifopen[k][i].ifopen==1)//如果文件是打开的

{

if((ifopen[k][i].openmode==1)||(ifopen[k][i].openmode==2))//文件是只写,或者是可读可写的

{

itoa(ufd[k]->ufdfile[i].fpaddr,str,10);//获取文件对应的物理地址

strcpy(str1,"file");

strcat(str1,str);

strcpy(str,"d:

\\osfile\\file\\");

strcat(str,str1);

strcat(str,".txt");

fp_file=fopen(str,"ab");//以二进制只写的形式打开,每次将内容添加到文件末尾接着上一次内容

length=WriteF1();

ufd[k]->ufdfile[i].flength=ufd[k]->ufdfile[i].flength+length;//计算总长度

printf("\n\n%dLength.\n",ufd[k]->ufdfile[i].flength);

printf("\n\nYouhavewritefilesuccessfully!

!

");

fclose(fp_file);

wgetchar=0;

}

elseif(ifopen[k][i].openmode==0)//文件是只读的

{

printf("\nError.\'%s\'hasbeenopenedwithREADONLYmode.Itisn\'twrite.\n",fname);

wgetchar=1;

}

else//文件是保护的

{

printf("\nError.\'%s\'hasbeenopenedwithPROTECTmode.Itisn\'twrite.\n",fname);

wgetchar=1;

}

}

else//文件是关闭的

{

printf("\nError.\'%s\'isinclosingstatus.Pleaseopenitbeforewrite\n",fname);

wgetchar=1;

}

}

else//所指定的文件不存在

{

printf("\nError.\'%s\'doesnotexist.\n",fname);

wgetchar=1;

}

}

}

【程序流程设计】

1总的功能结构图:

2部分子模块程序流程图

(1)打开命令的程序流程图:

(2)关闭命令的程序流程图:

(3)写命令的程序流程图:

(4)删除命令的程序流程图:

【测试结果】

1删除文件

2打开的文件不能删除

3打开文件,其中已经打开的文件不能再次打开

3关闭文件

4写文件,其中只有打开了文件才能写入

5写文件

6只读文件和保护文件不能写入

7其他函数

 

【参考文献】

计算机操作系统,西安电子科技大学出版社,方敏主编,2004.8

部分函数含义引用于

【源程序清单】

#include"stdio.h"

#include"string.h"

#include"conio.h"

#include"stdlib.h"

#defineMAXNAME25/*thelargestlengthofmfdname,ufdname,filename*/

#defineMAXCHILD50/*thelargestchild每个用户名下最多有50个文件*/

#defineMAX(MAXCHILD*MAXCHILD)/*thesizeoffpaddrno*/

typedefstruct/*thestructureofOSFILE定义主文件*/

{

intfpaddr;/*filephysicaladdress*/

intflength;/*filelength*/

intfmode;/*filemode:

0-ReadOnly;1-WriteOnly;2-ReadandWrite;3-Protect;*/

charfname[MAXNAME];/*filename*/

}OSFILE;

typedefstruct/*thestructureofOSUFD定义用户文件目录*/

{

charufdname[MAXNAME];/*ufdname*/

OSFILEufdfile[MAXCHILD];/*ufdownfile*/

}OSUFD;

typedefstruct/*thestructureofOSUFD'LOGIN定义登陆*/

{

charufdname[MAXNAME];/*ufdname*/

charufdpword[8];/*ufdpassword*/

}OSUFD_LOGIN;

typedefstruct/*fileopenmode定义操作方式*/

{

intifopen;/*ifopen:

0-close,1-open*/

intopenmode;/*0-readonly,1-writeonly,2-readandwrite,3-protect*/

}OSUFD_OPENMODE;

voidLoginF();/*LOGINFileSystem*/

voidDirF();/*DirFileSystem*/

voidCreateF();/*CreateFile*/

voidDeleteF();/*DeleteFile*/

voidModifyFM();/*ModifyFileMode*/

voidOpenF();/*OpenFile*/

voidCloseF();/*CloseFile*/

voidReadF();/*ReadFile*/

voidWriteF();/*WriteFile*/

voidQuitF();/*QuitFileSystem*/

voidCdF();/*ChangeDir*/

voidhelp();

char*rtrim(char*str);/*removethetrailingblanks.*/

char*ltrim(char*str);/*removetheheadingblanks.*/

voidInputPW(char*password);/*inputpassword,use'*'replace*/

intExistD(char*dirname);/*WhetherDirNameExist,Exist-i,NotExist-0*/

intWriteF1();/*writefile*/

intExistF(char*filename);/*WhetherFileNameExist,Exist-i,NotExist-0*/

voidSetPANo(intRorW);/*Setphysicaladdressnum*/

intFindPANo();/*findoutphysicaladdressnum*/

intucount=0;/*thecountofmfd'sufds用户数*/

intfcount[MAXCHILD];/*thecountofufd'sfiles子文件数*/

intloginsuc=0;/*whetherloginsuccessfully登陆成功*/

charusername[MAXNAME];/*recordloginuser'sname22用户名*/

chardirname[MAXNAME];/*recordcurrentdirectory使用的用户目录*/

intfpaddrno[MAX];/*recordfilephysicaladdressnum物?

理地址号,存放自己所创建的所有文件的地址*/

intwgetchar;/*whethergetchar()*/

OSUFD*ufd[MAXCHILD];/*ufdandufdownfiles*/

OSUFD_LOGINufd_lp;//用户登录结构体类型的变量

OSUFD_OPENMODEifopen[MAXCHILD][MAXCHILD];

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1