操作系统课程设计实验指导书new.docx

上传人:b****7 文档编号:16656769 上传时间:2023-07-16 格式:DOCX 页数:27 大小:23.55KB
下载 相关 举报
操作系统课程设计实验指导书new.docx_第1页
第1页 / 共27页
操作系统课程设计实验指导书new.docx_第2页
第2页 / 共27页
操作系统课程设计实验指导书new.docx_第3页
第3页 / 共27页
操作系统课程设计实验指导书new.docx_第4页
第4页 / 共27页
操作系统课程设计实验指导书new.docx_第5页
第5页 / 共27页
操作系统课程设计实验指导书new.docx_第6页
第6页 / 共27页
操作系统课程设计实验指导书new.docx_第7页
第7页 / 共27页
操作系统课程设计实验指导书new.docx_第8页
第8页 / 共27页
操作系统课程设计实验指导书new.docx_第9页
第9页 / 共27页
操作系统课程设计实验指导书new.docx_第10页
第10页 / 共27页
操作系统课程设计实验指导书new.docx_第11页
第11页 / 共27页
操作系统课程设计实验指导书new.docx_第12页
第12页 / 共27页
操作系统课程设计实验指导书new.docx_第13页
第13页 / 共27页
操作系统课程设计实验指导书new.docx_第14页
第14页 / 共27页
操作系统课程设计实验指导书new.docx_第15页
第15页 / 共27页
操作系统课程设计实验指导书new.docx_第16页
第16页 / 共27页
操作系统课程设计实验指导书new.docx_第17页
第17页 / 共27页
操作系统课程设计实验指导书new.docx_第18页
第18页 / 共27页
操作系统课程设计实验指导书new.docx_第19页
第19页 / 共27页
操作系统课程设计实验指导书new.docx_第20页
第20页 / 共27页
亲,该文档总共27页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

操作系统课程设计实验指导书new.docx

《操作系统课程设计实验指导书new.docx》由会员分享,可在线阅读,更多相关《操作系统课程设计实验指导书new.docx(27页珍藏版)》请在冰点文库上搜索。

操作系统课程设计实验指导书new.docx

操作系统课程设计实验指导书new

操作系统课程设计

【设计题目】

Linux二级文件系统设计

【开发语言及实现平台或实验环境】

C++/VC++

【设计目的】

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

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

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

【设计要求】

理解Linux的文件系统的组织;掌握常用的数据结构;系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件;使用文件来模拟外存,进行数据结构设计和操作算法的设计,实现一个文件系统并实现基本的文件操作(为了简便文件系统,不考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容)。

要求:

1、对程序的每一部分要有详细的设计分析说明

2、程序执行的每个步骤要有具体的提示内容或输出

3、源代码格式规范,注释不少于三分之一

4、设计合适的测试用例,对得到的运行结果要有分析,

5、设计中遇到的问题,设计的心得体会

6、提交完整程序代码、课程设计报告及相关文档

【设计原理】

一.外存管理

文件系统是一个含有大量的文件及其属性,对文件进行操作、管理的软件,以及向用户提供使用文件的接口的一个集合。

在逻辑上它的层次结构是这样的:

文件系统接口

对对象的操作和管理的软件集合

逻辑文件系统

基本I/O管理程序(文件组织模块)

基本文件系统(物理I/O层)

I/O控制层(设备驱动程序)

对象及其属性说明

作为产品的操作系统有各自的文件系统。

比如MS的WINDOWS系列使用的是FAT16、FAT32或NTFS的文件系统、LINUX使用的是EXT2、EXT3文件系统等等。

二.linux的EXT2文件系统

linux使用一个叫虚拟文件系统的技术从而可以支持多达几十种的不同文件系统,而EXT2是linux自己的文件系统。

它有几个重要的数据结构,一个是超级块,用来描述目录和文件在磁盘上的物理位置、文件大小和结构等信息。

inode也是一个重要的数据结构。

文件系统中的每个目录和文件均由一个inode描述。

它包含:

文件模式(类型和存取权限)、数据块位置等信息。

如果希望详细学习EXT2文件系统可以参看linux内核代码include/linux/ext2_fs.h、include/linux/ext2_fs_sb.h等文件。

一个文件系统除了重要的数据结构之外,还必须为用户提供有效的接口操作。

比如EXT2提供的OPEN/CLOSE接口操作。

三.用内存来模拟外存

真正的文件系统对外存进行管理,涉及到许多硬件、设备管理方面的底层技术,一方面这些技术不属于操作系统核心内容,一方面过多的内容不免造成实验者顾此失彼,所以这里推荐一种使用内存来模拟外存的方式,可以跳过这些硬件技术而直接把精力放在数据结构设计和操作算法设计上面。

假定pInode是一个指向inode结构的指针,而且它已经放入的需要放入的数值了,现在需要将其写入到特定位置。

可用如下代码:

……

fd=fopen(“filesystem”,”w+b”);//fd是FILE指针类型,w便是写方式,b表示二进制

fseek(fd,specific_area,SEEK_SET);//fd是文件指针;specific_area为整形,

//为需要入pInode的位置

fwrite(pInode,1,sizeof(inode),fd);//写入pInode信息

 

【设计内容】

一、任务

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

要求做到以下几点:

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

login用户登录

dir列目录

create创建文件

delete删除文件

open打开文件

close关闭文件

read读文件

write写文件

cd进出目录

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

3.源文件可以进行读写保护

二、程序设计

1.设计思想

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

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

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

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

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

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

如:

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

2.主要数据结构和部分代码

参考程序见下(本程序需要在c:

下建一个名为osfile的目录及一个名为file的子目录):

#include"stdio.h"

#include"string.h"

#include"conio.h"

#include"stdlib.h"

#defineMAXNAME25/*thelargestlengthofmfdname,ufdname,filename*/

#defineMAXCHILD50/*thelargestchild*/

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

typedefstruct/*thestructureofOSFILE*/

{intfpaddr;/*filephysicaladdress*/

intflength;/*filelength*/

intfmode;/*filemode:

0-ReadOnly;1-WriteOnly;2-ReadandWrite(default);*/

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;

voidclrscr()

{

system("cls");

}

voidmain()

{inti,j,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.*/

voidLoginF();/*LOGINFileSystem*/

voidDirF();/*DirFileSystem*/

voidCdF();/*ChangeDir*/

voidCreateF();/*CreateFile*/

voidDeleteF();/*DeleteFile*/

voidModifyFM();/*ModifyFileMode*/

voidOpenF();/*OpenFile*/

voidCloseF();/*CloseFile*/

voidReadF();/*ReadFile*/

voidWriteF();/*WriteFile*/

voidQuitF();/*QuitFileSystem*/

voidhelp();

if((fp_mfd=fopen("c:

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

{fp_mfd=fopen("c:

\\osfile\\mfd","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));}

elseprintf("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)

{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:

choiceend=1;OpenF();if(!

wgetchar)getchar();break;

case6:

choiceend=1;CloseF();if(!

wgetchar)getchar();break;

case7:

choiceend=1;ReadF();if(!

wgetchar)getchar();break;

case8:

choiceend=1;WriteF();if(!

wgetchar)getchar();break;

case9:

printf("\nYouhaveexitedthissystem.");

QuitF();exit(0);break;

case10:

choiceend=1;clrscr();break;

case11:

CdF();choiceend=1;break;

case20:

help();choiceend=1;break;

default:

choiceend=0;

}

}

}

elseprintf("\nAccessdenied.");

}

voidhelp(void)

{

printf("\nTheCommandList\n");

printf("\nCdAttribCreatewriteReadOpenClsDeleteExitClose\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.*/

{char*rtrim(char*str);

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*/

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

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

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

voidSetPANo(intRorW);/*Setphysicaladdressnum*/

while

(1)

{findout=0;

printf("\n\nLoginName:

");

gets(loginame);

ltrim(rtrim(loginame));

fp_mfd=fopen("c:

\\osfile\\mfd","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;//何时不为1?

执行else后的语句

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","rb");

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

=0;j++)

{strcpy(str,"c:

\\osfile\\");

strcat(str,ufd_lp.ufdname);

ufd[j]=(OSUFD*)malloc(sizeof(OSUFD));//开辟ufd指针变化

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;

SetPANo(0);

printf("\n\nLoginsuccessful!

WelcometothisFileSystem\n\n");

loginsuc=1;

return;}

else

{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){loginsuc=0;flag=0;return;}

}

}

}

else

{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","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);

if((fp_ufd=fopen(str,"rb"))==NULL)

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

fclose(fp_ufd);

}

fp_mfd=fopen("c:

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

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

=0;j++)

{strcpy(str,"c:

\\osfile\\");

strcat(str,ufd_lp.ufdname);

ufd[j]=(OSUFD*)malloc(sizeof(OSUFD));

strcpy(ufd[j]->ufdname,strupr(ufd_lp.ufdname));

fp_ufd=fopen(str,"rb");

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;

SetPANo(0);

printf("\n\nLoginSuccessful!

WelcometothisSystem\n\n");

loginsuc=1;

return;

}

else

{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){loginsuc=0;flag=0;return;}

}

}

}

}

}

voidSetPANo(intRorW)/*Setphysicaladdressnum,0-read,1-write*/

{inti,j;

if(RorW==0)

{if((fp_file_p=fopen("c:

\\osfile\\file\\fil

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

当前位置:首页 > 经管营销 > 经济市场

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

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