操作系统课程设计报告.docx

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

操作系统课程设计报告.docx

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

操作系统课程设计报告.docx

操作系统课程设计报告

 

 

操作系统课程设计报告

 

专业:

学号:

姓名:

提交日期:

 

【设计目的】

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

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

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

【设计内容】

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

要求做到以下几点:

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

login用户登录

dir列目录

create创建文件

delete删除文件

open打开文件

close关闭文件

read读文件

write写文件

cd进出目录

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

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

【实验环境】

C++/VC++

【源程序清单】

#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;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");

}

intmain()

{

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))));//将输入的值赋给choice

if(strcmp(choice,"dir")==0)choice1=1;//依次将输入的值与dir,create等进行比较

elseif(strcmp(choice,"create")==0)choice1=2;//如果输入create将choice1置为2通过switch选择,以下依次类推

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;//choice1=12时跳转到default,然后继续循环

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:

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;

}

}

}

else

printf("\nAccessdenied.");//登录成功

}

voidhelp(void)

{

printf("\nTheCommandList\n");

printf("\nCdAttribCreatewriteReadOpenClsDeleteExitClose\n");

}

char*rtrim(char*str)/*除去末尾端的空格指针指向字符串第一个*/

{

intn=strlen(str)-1;//n为字符串长度减1

while(n>=0)

{

if(*(str+n)!

='')//末尾不存在空格

{

*(str+n+1)='\0';//'\n'表示结束符

break;

}

elsen--;//如果存在空格将空格去掉

}

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

returnstr;

}

char*ltrim(char*str)/*除去前端的空格*/

{

strrev(str);//把字符串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++)//检测输入登录名和mfd.txt是否一样

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;

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

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\\file_p.txt","rb"))==NULL)//如果文件未读成功

{

fp_file_p=fopen("c:

\\osfile\\file\\file_p.txt","wb");//创建该文件

fclose(fp_file_p);

}

fp_file_p=fopen("c:

\\osfile\\file\\file_p.txt","rb");

///////////////////////////////////////////////////////////////////

for(i=0;fread(&j,sizeof(i

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

当前位置:首页 > 表格模板 > 合同协议

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

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