操作系统课程设计报告文档格式.docx
《操作系统课程设计报告文档格式.docx》由会员分享,可在线阅读,更多相关《操作系统课程设计报告文档格式.docx(35页珍藏版)》请在冰豆网上搜索。
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*/
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);
char*ltrim(char*str);
if((fp_mfd=fopen("
c:
\\osfile\\mfd.txt"
"
rb"
))==NULL)
{
fp_mfd=fopen("
wb"
fclose(fp_mfd);
}
for(i=0;
i<
MAX;
i++)fpaddrno[i]=0;
//textattr(BLACK*16|WHITE);
clrscr();
/*clearscreen*/
LoginF();
/*userlogin*/
if(loginsuc==1)/*LoginSuccessfully*/
while
(1)
{
wgetchar=0;
if(choiceend==1)
printf("
\n\nC:
\\%s>
"
strupr(dirname));
else
Badcommandorfilename.\nC:
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选择,以下依次类推
delete"
)==0)choice1=3;
attrib"
)==0)choice1=4;
open"
)==0)choice1=5;
close"
)==0)choice1=6;
read"
)==0)choice1=7;
write"
)==0)choice1=8;
exit"
)==0)choice1=9;
)==0)choice1=10;
cd"
)==0)choice1=11;
help"
)==0)choice1=20;
elsechoice1=12;
//choice1=12时跳转到default,然后继续循环
switch(choice1)
{
case1:
DirF();
choiceend=1;
break;
case2:
CreateF();
if(!
wgetchar)getchar();
case3:
DeleteF();
wgetchar)getchar();
case4:
ModifyFM();
case5:
OpenF();
if(!
case6:
CloseF();
case7:
ReadF();
case8:
WriteF();
case9:
printf("
\nYouhaveexitedthissystem."
QuitF();
exit(0);
case10:
clrscr();
case11:
CdF();
case20:
help();
default:
choiceend=0;
}
}
else
printf("
\nAccessdenied."
//登录成功
voidhelp(void)
printf("
\nTheCommandList\n"
\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]='
returnstr;
char*ltrim(char*str)/*除去前端的空格*/
strrev(str);
//把字符串str的所有字符的顺序颠倒
rtrim(str);
//去掉尾端空格
//再颠倒过来
voidLoginF()/*LOGINFileSystem*/
charloginame[MAXNAME],loginpw[9],logincpw[9],str[50];
inti,j,flag=1;
chara[25];
intfindout;
/*loginusernotexist*/
while
(1)
findout=0;
\n\nLoginName:
gets(loginame);
//输入字符串
ltrim(rtrim(loginame));
//去掉前后端的空格
//打开该文件,返回给一个文件指针
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);
if(findout==1)/*userexist*/
printf("
LoginPassword:
InputPW(loginpw);
if(strcmp(loginpw,logincpw)==0)
strcpy(username,strupr(loginame));
strcpy(dirname,username);
fp_mfd=fopen("
for(j=0;
j++)
{
strcpy(str,"
\\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,"
fcount[j]=0;
for(i=0;
ufd[j]->
ufdfile[i],sizeof(OSFILE),1,fp_ufd)!
i++,fcount[j]++)
{
ifopen[j][i].ifopen=0;
ifopen[j][i].openmode=4;
}
fclose(fp_ufd);
}
fclose(fp_mfd);
ucount=j;
SetPANo(0);
\n\nLoginsuccessful!
WelcometothisFileSystem\n\n"
loginsuc=1;
return;
\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"
return;
else
NewPassword(<
=8):
/*inputnewpassword,use'
\nConfirmPassword(<
InputPW(logincpw);
strcpy(ufd_lp.ufdname,strupr(loginame));
strcpy(ufd_lp.ufdpword,loginpw);
ab"
fwrite(&
ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd);
strcpy(dirname,loginame);
////////////////////////////////////////////////////////
strcpy(str,"
strcat(str,username);
strcat(str,"
if((fp_ufd=fopen(str,"
/////////////////////////////////////
ifopen[j][i].openmode=4;
\n\nLoginSuccessful!
WelcometothisSystem\n\n"
voidSetPANo(intRorW)/*Setphysicaladdressnum,0-read,1-write*/
inti,j;
if(RorW==0)
if((fp_file_p=fopen("
\\osfile\\file\\file_p.txt"
))==NULL)//如果文件未读成功
fp_file_p=fopen("
//创建该文件
fclose(fp_file_p);
fp_file_p=fopen("
///////////////////////////////////////////////////////////////////
j,sizeof(i