杨闯0821113814Word文件下载.docx
《杨闯0821113814Word文件下载.docx》由会员分享,可在线阅读,更多相关《杨闯0821113814Word文件下载.docx(40页珍藏版)》请在冰豆网上搜索。
LOGIN用户登录
DIR列文件目录
CREATE创建文件
DELETE删除文件
OPEN打开文件
CLOSE关闭文件
WRITE写文件
5.因系统小,文件目录的检索可以使用简单的线性搜索。
设计方法:
根据设计任务书的要求,画出程序设计流程图,确定程序的功能,把整个程序根据功能要求分解为各个子程序,利用TC语言分编写程序代码,然后进行上机调试、修改、进行连接,测试,写出设计总结报告。
设计步骤:
1.充分了解各项设计要求。
深入理解有关文件控制块、目录的概念。
并体会和了解目录管理的实施办法。
2.按要求对进程调度程序进行分解,根据功能将其分解成多个子模块。
3.建立主控制模块程序流程图及各功能子模块程序流程图,要求条理清楚、简单明了、功能完备。
4.根据流程图编制主程序代码及子程序代码。
要求程序设计结构清晰,简洁,便于修改和调试。
5.上述设计要求一人单独进行,独立完成设计。
6.设计完成后,上机进行运行调试。
7.程序运行成功,然后进行某些功能测试,选择有实用性、特殊性的数据进行录入调试,使设计进一步得到改进并完善。
8.打印出程序运行结果,并对结果进行分析,验证程序设计的正确性。
9.写出课程设计报告书。
时间分配:
内容
时间分配
发放任务书、课题交底、查阅有关资料
4学时
程序设计
8学时
上机调试,验证程序设计正确性
6学时
设计总结报告
2学时
合计
20学时
程序运行结果如下:
用户登录时所要进行的用户名输入和密码设置!
并且两次密码输入要一致!
列文件目录的现实可以直观的现实出文件的使用类型工作方法!
创建一个文件和所给出的文件名显示功能!
最后用#号键来结束进程来完成一个文件名的创建!
(三)、课程设计结论和实验心得
根据本次对文件系统的的程序设计可以了解在运行C语言时要注意一些语言上的细节不然程序在运行时,也可能出现问题使得在调试程序时浪费很多的时间!
一、设计主要参考资料:
1.《计算机操作系统》汤子赢等西安电子科技大学出版社
2.《操作系统教程提解与实验指导》孟静高等教育出版社2003年
源程序如下:
#include"
stdio.h"
string.h"
conio.h"
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*/
charufdpword[8];
/*ufdpassword*/
}OSUFD_LOGIN;
typedefstruct/*fileopenmode*/
intifopen;
/*ifopen:
0-close,1-open*/
intopenmode;
/*0-readonly,1-writeonly,2-readandwrite*/
}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,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("
wb"
fclose(fp_mfd);
}
for(i=0;
i<
MAX;
i++)fpaddrno[i]=0;
clrscr();
/*clearscreen*/
LoginF();
/*userlogin*/
if(loginsuc==1)/*LoginSuccessfully*/
while
(1)
{
wgetchar=0;
if(choiceend==1)
{
printf("
\n\nC:
\\%s>
"
strupr(dirname));
}
else
cuowuminglinghuowenjianming.\nC:
strupr(username));
gets(choice);
strcpy(choice,ltrim(rtrim(strlwr(choice))));
if(strcmp(choice,"
dir"
)==0)choice1=1;
elseif(strcmp(choice,"
create"
)==0)choice1=2;
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;
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("
\nniyijtuichuxit!
\n"
QuitF();
exit(0);
case10:
clrscr();
case11:
CdF();
case20:
help();
default:
choiceend=0;
}
elseprintf("
\nAccessdenied."
voidhelp(void)
printf("
\nminglingliebiao:
\nDIRCREATEDELETEOPENCLOSEREADWRITEEXIT\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]='
returnstr;
char*ltrim(char*str)/*removetheheadingblanks.*/
strrev(str);
rtrim(str);
voidLoginF()/*LOGINFileSystem*/
charloginame[MAXNAME],loginpw[9],logincpw[9],str[50];
inti,j,flag=1;
chara[25];
intfindout;
/*loginusernotexist*/
voidInputPW(char*password);
/*inputpassword,use'
*'
replace*/
voidSetPANo(intRorW);
/*Setphysicaladdressnum*/
while
(1)
findout=0;
printf("
\n\nuser:
gets(loginame);
ltrim(rtrim(loginame));
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*/
code:
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);
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);
printf("
\n\ndenglucg!
\n\n"
loginsuc=1;
return;
}
else
flag=1;
while(flag)
printf("
denglushib,mimacuow!
again:
(Y/N):
gets(a);
ltrim(rtrim(a));
if(strcmp(strupr(a),"
Y"
)==0)
loginsuc=0;
flag=0;
elseif(strcmp(strupr(a),"
N"
)==0)
return;
else
code(<
=8):
/*inputnewpassword,use'
\nquercode(<
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);
if((fp_ufd=fopen(str,"
LoginFailed!
PasswordError.TryAgain(Y/N):
el