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

上传人:聆听****声音 文档编号:567541 上传时间:2023-04-29 格式:DOCX 页数:40 大小:98.28KB
下载 相关 举报
操作系统课程设计--二级文件系统设计.docx_第1页
第1页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第2页
第2页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第3页
第3页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第4页
第4页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第5页
第5页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第6页
第6页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第7页
第7页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第8页
第8页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第9页
第9页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第10页
第10页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第11页
第11页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第12页
第12页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第13页
第13页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第14页
第14页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第15页
第15页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第16页
第16页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第17页
第17页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第18页
第18页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第19页
第19页 / 共40页
操作系统课程设计--二级文件系统设计.docx_第20页
第20页 / 共40页
亲,该文档总共40页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

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

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

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

操作系统课程设计报告

专业:

学号:

姓名:

提交日期:

操作系统课程设计报告

【设计题目】

二级文件系统设计

【设计目的】

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

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

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

【设计内容】一、任务

为Linux系统设计一个简单的二级文件系统。

要求做到以下几点:

1.可以实现下列几条命令:

login用户登录dir列目录create创建文件delete删除文件open打开文件close关闭文件read读文件write写文件cd进出目录

2.列目录时要列出文件名,物理地址,保护码和文件长度

3.源文件可以进行读写保护二、程序设计

设计思想

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

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

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

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

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

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

如:

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

【实验环境】

C++/VC++

【设计原理】

对采用二级文件目录的文件系统工作的机理了如指掌,对文件系统的相关操作要掌握。

【设计思路】

1.主要数据结构

#defineMAXNAME25/*thelargestlengthofmfdname,ufdname,filename*/#defineMAXCHILD50/*thelargestchild每个用户名下最多有50个文件*/#defineMAX(MAXCHILD*MAXCHILD)/*thesizeoffpaddrno*/

typedefstruct/*thestructureofOSFILE定义主文件*/

{

39

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();

3.程序流程设计

总体功能程序结构图

开始

注册账号

登录

选择操作

结束

列目

创建

删除

打开

关闭

读文

写文

进出

文件

文件

文件

文件

目录

打开命令的程序流程图

开始

输入文

件内容

是否存在

是否打开

出现错误

打开文件

结束

删除命令的程序流程图

开始

输入文

件内容

是否存在

是否关闭

出现错误

删除文件

结束

关闭命令的程序流程图

开始

输入文

件内容

是否存在

是否关闭

出现错误

关闭文件

结束

写命令的程序流程图

开始

输入文

件内容

是否存在

是否打开

出现错误

打开文件

写入内容

结束

【源程序清单】#include"stdio.h"#include"string.h"

#include"conio.h"#include"stdlib.h"

#defineMAXNAME25/*thelargestlengthofmfdname,ufdname,filename*/#defineMAXCHILD50/*thelargestchild*/

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

typedefstruct/*thestructureofOSFILE*/

{

int fpaddr; /*filephysicaladdress*/

int flength; /*filelength*/

int fmode; /*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;

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

intucount=0;/*thecountofmfd'sufds*/

intfcount[MAXCHILD];/*thecountofufd'sfiles*/intloginsuc=0;/*whetherloginsuccessfully*/

charusername[MAXNAME];/*recordloginuser'sname22*/chardirname[MAXNAME];/*recordcurrentdirectory*/

intfpaddrno[MAX];/*recordfilephysicaladdressnum*/

OSUFD_OPENMODEifopen[MAXCHILD][MAXCHILD];/*recordfileopen/close*/intwgetchar;/*whethergetchar()*/

FILE*fp_mfd,*fp_ufd,*fp_file_p,*fp_file;

voidLoginF();/*LOGINFileSystem*/voidDirF();/*DirFileSystem*/

voidCdF();/*ChangeDir*/voidCreateF();/*CreateFile*/voidDeleteF();/*DeleteFile*/

voidModifyFM();/*ModifyFileMode*/voidOpenF();/*OpenFile*/

voidCloseF();/*CloseFile*/voidReadF();/*ReadFile*/voidWriteF();/*WriteFile*/

voidQuitF();/*QuitFileSystem*/voidhelp();

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

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

voidSetPANo(intRorW);/*Setphysicaladdressnum*/

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

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

voidclrscr()

{

system("cls");

}

voidmain()

{

inti,choice1;

charchoice[50];/*choiceoperation:

dir,create,delete,open,delete,modify,read,write*/intchoiceend=1;/*whetherchoiceend*/

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

if((fp_mfd=fopen("c:

\\osfile\\mfd.txt","rb"))==NULL)

{

fp_mfd=fopen("c:

\\osfile\\mfd.txt","wb");fclose(fp_mfd);

}

for(i=0;i

//textattr(BLACK*16|WHITE);clrscr(); /*clearscreen*/LoginF(); /*userlogin*/clrscr();

if(loginsuc==1)/*LoginSuccessfully*/

{

while

(1)

{

wgetchar=0;

if(choiceend==1)printf("\n\nC:

\\%s>",strupr(dirname));

else

printf("Badcommandorfilename.\nC:

\\%s>",strupr(username));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")==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;elseif(strcmp(choice,"cd")==0)choice1=11;elseif(strcmp(choice,"help")==0)choice1=20;elsechoice1=12;

switch(choice1)

{

}

}

}

else

case1:

DirF();choiceend=1;break;

case2:

CreateF();choiceend=1;if(!

wgetchar)getchar();break;case3:

DeleteF();choiceend=1;if(!

wgetchar)getchar();break;case4:

ModifyFM();choiceend=1;if(!

wgetchar)getchar();break;case5:

OpenF();choiceend=1;if(!

wgetchar)getchar();break;case6:

CloseF();choiceend=1;if(!

wgetchar)getchar();break;case7:

ReadF();choiceend=1;if(!

wgetchar)getchar();break;case8:

WriteF();choiceend=1;if(!

wgetchar)getchar();break;case9:

printf("\nYouhaveexitedthissystem.");

QuitF();exit(0);break;

case10:

clrscr();choiceend=1;break;case11:

CdF();choiceend=1;break;case20:

help();choiceend=1;break;default:

choiceend=0;

printf("\nAccessdenied.");

}

voidhelp(void)

{

printf("\nTheCommandList\n");

printf("\nCdAttribCreate write Read Open Cls Delete Exit Close\n");

}

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

{

intn=strlen(str)-1;while(n>=0)

{

if(*(str+n)!

='')

{

*(str+n+1)='\0';break;

}

elsen--;

}

if(n<0)str[0]='\0';returnstr;

}

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

{

strrev(str);rtrim(str);strrev(str);returnstr;

}

voidLoginF()/*LOGINFileSystem*/

{

charloginame[MAXNAME],loginpw[9],logincpw[9],str[50];inti,j,flag=1;

chara[25];

intfindout;/*loginusernotexist*/

while

(1)

{

findout=0;printf("\n\nLoginName:

");gets(loginame);ltrim(rtrim(loginame));

fp_mfd=fopen("c:

\\osfile\\mfd.txt","rb");for(i=0;fread(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd)!

=0;i++)

if(strcmp(strupr(ufd_lp.ufdname),strupr(loginame))==0)

{

findout=1;

strcpy(logincpw,ufd_lp.ufdpword);

}

fclose(fp_mfd);

if(findout==1)/*userexist*/

{

printf("LoginPassword:

");

InputPW(loginpw);/*inputpassword,use'*'replace*/if(strcmp(loginpw,logincpw)==0)

{

strcpy(username,strupr(loginame));strcpy(dirname,username);fp_mfd=fopen("c:

\\osfile\\mfd.txt","rb");

for(j=0;fread(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd)!

=0;j++)

{

strcpy(str,"c:

\\osfile\\");strcat(str,ufd_lp.ufdname);strcat(str,".txt");ufd[j]=(OSUFD*)malloc(sizeof(OSUFD));

strcpy(ufd[j]->ufdname,strupr(ufd_lp.ufdname));fp_ufd=fopen(str,"rb");

fcount[j]=0;

for(i=0;fread(&ufd[j]->ufdfile[i],sizeof(OSFILE),1,fp_ufd)!

=0;i++,fcount[j]++)

{

ifopen[j][i].ifopen=0;ifopen[j][i].openmode=4;

}

fclose(fp_ufd);

}

fclose(fp_mfd);ucount=j;

}

else

{

SetPANo(0);

printf("\n\nLoginsuccessful!

WelcometothisFileSystem\n\n");loginsuc=1;

return;

printf("\n\n");flag=1;while(flag)

{

printf("LoginFailed!

PasswordError.TryAgain(Y/N):

");gets(a);

ltrim(rtrim(a));

if(strcmp(strupr(a),"Y")==0)

{

loginsuc=0;flag=0;

}

elseif(strcmp(strupr(a),"N")==0)

{

}

}

else

{

loginsuc=0;flag=0;return;

}

}

printf("NewPassword(<=8):

");

InputPW(loginpw);/*inputnewpassword,use'*'replace*/printf("\nConfirmPassword(<=8):

");/*inputnewpassword,use'*'replace*/InputPW(logincpw);

if(strcmp(loginpw,logincpw)==0)

{

strcpy(ufd_lp.ufdname,strupr(loginame));strcpy(ufd_lp.ufdpword,loginpw);fp_mfd=fopen("c:

\\osfile\\mfd.txt","ab");fwrite(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd);fclose(fp_mfd);

strcpy(username,strupr(loginame));strcpy(dirname,loginame);

////////////////////////////////////////////////////////strcpy(str,"c:

\\osfile\\");strcat(str,username);

strcat(str,".txt");if((fp_ufd=fopen(str,"rb"))==NULL)

{

fp_ufd=fopen(str,"wb");fclose(fp_ufd);

}

fp_mfd=fopen("c:

\\osfile\\mfd.txt","rb");for(j=0;fread(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd)!

=0;j++)

{

/////////////////////////////////////strcpy(str,"c:

\\osfile\\");strcat(s

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

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2