完整word版操作系统二级文件管理课程设计.docx
《完整word版操作系统二级文件管理课程设计.docx》由会员分享,可在线阅读,更多相关《完整word版操作系统二级文件管理课程设计.docx(19页珍藏版)》请在冰点文库上搜索。
完整word版操作系统二级文件管理课程设计
操作系统二级文件管理课程设计
课程设计名称:
二级文件管理系统
专业班级:
软件工程计083-1
学生姓名:
李晓斌
学号:
20082553103
指导教师:
任满杰
设计目的:
通过具体的文件存储空间的管理、文件的物理结构、目录结构和文件操作的实现,加深对文件系统内部功能和实现过程的理解。
设计内容:
为Linux系统设计一个简单二级文件管理系统
一、实验内容描述
1实验目标
本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能及内部实现.
2实验要求
为linux系统设计一个简单的二级文件系统.要求做到以下几点:
①可以实现下列命令:
login用户登录
dir列文件目录
create创建文件
delete删除文件
open打开文件
close关闭文件
read读文件
write写文件
②列目录时要列出文件名、物理地址、保护码和文件长度.
③源文件可以进行读写保护.
程序设计
(1)设计思想
本文件系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户账号下的文件。
另外,为了简便文件系统未考虑文件共享,文件系统安全以及管理文件与设备文件等特殊内容。
(2)主要数据结构
A磁盘块结构体:
typedefstructdistTable
{
intmaxlength;
intstart;
intuseFlag;
distTable*next;
}diskNode;
diskNode*diskHead;
B文件块结构体:
structfileTable//文件块结构体
charfileName[10];
intstrat;//文件在磁盘存储空间的起始地址
intlength;//文件内容长度
intmaxlength;//文件的最大长度
charfileKind[3];//文件的属性——读写方式
structtm*timeinfo;
boolopenFlag;//判断是否有进程打开了该文件
//fileTable*next;
};
C两级目录结构体
typedefstructuser_file_directory//用户文件目录文件UFD
//charfileName[10];
fileTable*file;
user_file_directory*next;
}UFD;
//UFD*headFile;
typedefstructmaster_file_directory//主文件目录MFD
charuserName[10];
charpassword[10];
UFD*user;
}MFD;
(3)函数如下;
voiduserCreate()
charc;
inti;
if(used{printf("请输入用户名:");for(i=0;c=getch();i++){if(c==13)break;elseuserName[i]=c;printf("%c",c);}userName[i]='\0';for(i=0;i{if(!strcmp(userTable[i].userName,userName)){printf("\n");printf("该用户名已存在,创建用户失败\n");system("pause");return;}}strcpy(userTable[used].userName,userName);printf("\n");printf("请输入密码:");for(i=0;c=getch();i++){if(c==13)break;elseuserTable[used].password[i]=c;printf("*");}userTable[userID].password[i]='\0';printf("\n");printf("创建用户成功\n");used++;system("pause");}else{printf("创建用户失败,用户已达到上限\n");system("pause");}fflush(stdin);//清除文件缓冲区}intlogin(){charname[10],psw[10];charc;inti,times;printf("请输入用户名:");for(i=0;c=getch();i++){if(c==13)break;elsename[i]=c;printf("%c",c);}name[i]='\0';for(i=0;i{if(!strcmp(userTable[i].userName,name))break;}if(i==used){printf("\n您输入的用户名不存在\n");system("pause");return-1;}for(times=0;times<3;times++){memset(psw,'\0',sizeof(psw));//将psw数组内的内容设置为空printf("\n请输入密码:");for(i=0;c=getch();i++){if(c==13)break;elsepsw[i]=c;printf("*");}printf("\n");for(i=0;i{if(!strcmp(psw,userTable[i].password)){printf("用户登录成功\n");system("pause");break;}}if(i==used){printf("您输入的密码错误,您还有%d次输入机会\n",2-times);if(times==2)exit(0);}elsebreak;}fflush(stdin);returni;}intrequestDist(int&startPostion,intmaxLength){intflag=0;//标记是否分配成功diskNode*p,*q,*temp;p=diskHead;while(p){if(p->useFlag==0&&p->maxlength>maxLength){startPostion=p->start;q=(diskNode*)malloc(sizeof(diskNode));q->start=p->start;q->maxlength=maxLength;q->useFlag=1;q->next=NULL;diskHead->start=p->start+maxLength;diskHead->maxlength=p->maxlength-maxLength;flag=1;temp=p;if(diskHead->next==NULL)diskHead->next=q;else{while(temp->next)temp=temp->next;temp->next=q;}break;}p=p->next;}returnflag;}voidfileCreate(charfileName[],intlength,charfileKind[])//创建文件{//inti,j;time_trawtime;intstartPos;UFD*fileNode,*p;for(p=userTable[userID].user->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName)){printf("文件重名,创建文件失败\n");system("pause");return;}}if(requestDist(startPos,length)){fileNode=(UFD*)malloc(sizeof(UFD));fileNode->file=(fileTable*)malloc(sizeof(fileTable));//这一步必不可少,因为fileNode里面的指针也需要申请地址,否则fileNode->file指向会出错strcpy(fileNode->file->fileName,fileName);strcpy(fileNode->file->fileKind,fileKind);fileNode->file->maxlength=length;fileNode->file->strat=startPos;fileNode->file->openFlag=false;time(&rawtime);fileNode->file->timeinfo=localtime(&rawtime);fileNode->next=NULL;if(userTable[userID].user->next==NULL)userTable[userID].user->next=fileNode;else{p=userTable[userID].user->next;while(p->next)p=p->next;p->next=fileNode;}printf("创建文件成功\n");system("pause");}else{printf("磁盘空间已满或所创建文件超出磁盘空闲容量,磁盘空间分配失败\n");system("pause");}}voidfreeDisk(intstartPostion){diskNode*p;for(p=diskHead;p!=NULL;p=p->next){if(p->start==startPostion)break;}p->useFlag=false;}voidfileDel(charfileName[]){UFD*p,*q,*temp;q=userTable[userID].user;p=q->next;while(p){if(!strcmp(p->file->fileName,fileName))break;else{p=p->next;q=q->next;}}if(p){if(p->file->openFlag!=true)//先判断是否有进程打开该文件{temp=p;q->next=p->next;freeDisk(temp->file->strat);//磁盘空间回收free(temp);printf("文件删除成功\n");system("pause");}else{printf("该文件已被进程打开,删除失败\n");system("pause");}}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}voidfileCat(charfileName[])//查看文件内容{intstartPos,length;intk=0;UFD*p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){startPos=p->file->strat;length=p->file->length;p->file->openFlag=true;//文件打开标记printf("*****************************************************\n");for(inti=startPos;k{if(i%50==0)printf("\n");//一行大于50个字符换行printf("%c",disk[i]);}printf("\n\n*****************************************************\n");printf("%s已被read进程打开,请用close命令将其关闭\n",p->file->fileName);system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}voidfileWrite(charfileName[])//写入{UFD*p,*q;q=userTable[userID].user;inti,k,startPos;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){if(!strcmp(p->file->fileKind,"r"))//判断文件类型是否允许写入{printf("该文件是只读文件,写入失败\n");system("pause");return;}charstr[500];printf("pleaseinputcontent:\n");gets(str);startPos=p->file->strat;p->file->openFlag=true;//文件打开标记p->file->length=strlen(str);if(p->file->length>p->file->maxlength){printf("写入字符串长度大于该文件的总长度,写入失败\n");system("pause");return;}for(i=startPos,k=0;k<(int)strlen(str);i++,k++)disk[i]=str[k];printf("文件写入成功,请用close命令将该文件关闭\n");system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}voidfileDir(charuserName[])//显示某一用户的所有文件{UFD*p;inti,k;for(i=0;i{if(!strcmp(userTable[i].userName,userName)){k=i;break;}}if(i==MaxUser){printf("没有找到该用户,请检查输入用户名是否正确\n");system("pause");return;}else{p=userTable[k].user->next;printf("********************************************************************************\n");printf("文件名文件长度文件在磁盘的起始地址文件类型创建时间\n");for(;p!=NULL;p=p->next)printf("%s%d%d%s%s",p->file->fileName,p->file->maxlength,p->file->strat,p->file->fileKind,asctime(p->file->timeinfo));printf("********************************************************************************\n");system("pause");}}voiddiskShow()//文件在磁盘上的属性{diskNode*p;inti=0,unusedDisk=0;printf("***************************************************************************\n");printf("盘块号起始地址容量(bit)是否已被使用\n");for(p=diskHead;p!=NULL;p=p->next,i++){if(p->useFlag==false)unusedDisk+=p->maxlength;printf("%d%d%d%d\n",i,p->start,p->maxlength,p->useFlag);}printf("***************************************************************************\n");printf("磁盘空间总容量:512*1024bit已使用:%dbit末使用:%dbit\n\n",MaxDisk-unusedDisk,unusedDisk);system("pause");}voidfileClose(charfileName[])//文件关闭{UFD*p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){p->file->openFlag=false;printf("%s文件已关闭\n",p->file->fileName);system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}心得体会在设计程序之前,我先花费了一天多的时间思考设计该程序的思路,熟悉了一下学过的课本,把以前忘了的东西又熟悉了一下,然后就通过操作系统要求开始设计程序了,我采用了一个模块一测试,成功之后在写另一个模块,刚开始创建文件,显示你创建成功了,可是却在指定路径中没有该文件,只有一个二级文件目录,经过我认真的查看,发现我用的函数是创建目录的,而非创建文件。随后我就选择了给他指定一个二级文件目录,在该目录中创建文件,终于测试成功了,接着我有创建了删除文件函数,打开文件函数,关闭文件函数,如文件函数,写文件函数,虽然也遇到了好多问题,我通过测试,查资料,细心的修改和调试后,最后还是一个模块一个模块的成功完成了,但是没法实现读写保护,而且整体测试时也出现了一些逻辑问题,例如:对于创建的只读文件,只写文件,可读可写文件均可以进行读写,这不符合逻辑,经过我的认真思考后,我把程序修改了一下,实现了在读,写文件前,先打开文件,而且对于只读文件,只能读取,不能写入,对于只写文件,只能写入不能读取,对于可读可写文件,既可以读取,又可以写入等功能。对于读写保护,我试着用打开文件来控制,当读文件时,可以显示打开的文件列表,该文件列表中只有只读文件和可读可写文件,当你从只写文件读取时,提示你这是只写文件,不能读取。同理,在写文件时,显示的打开的文件列表中只有只写文件和可读可写文件,当你对只读文件写入内容时,提示你这是只读文件,不能写入。这样实现了文件的读写保护。虽然本次课程设计的所做的程序规模不是很大,但在编程中我也充分体味到作为一名程序员,要有严密的逻辑思维能力的重要性,充分学好一些逻辑学科的重要性;一个没有逻辑的程序,就不能完美地实现所要完成的功能,因此,以后学习中一定会注重培养自己的逻辑思维能力,为自己成为一个高级软件工程师做好铺垫。通过这一个星期的课程设计,加深了对于操作系统这门课程的兴趣以及深入理解,培养了耐心、认真、永不放弃等优良品质。通过这次课程设计使我相信只要做,就能做到,增强了我的自信心。当然我也深深地感到了自己对某些知识的认识不足与缺陷,今后我将通过多看书及多编程序等实际手段入手,希望自己的编程能力能得到一定的提高。
printf("请输入用户名:
");
for(i=0;c=getch();i++)
if(c==13)break;
else
userName[i]=c;
printf("%c",c);
}
userName[i]='\0';
for(i=0;i{if(!strcmp(userTable[i].userName,userName)){printf("\n");printf("该用户名已存在,创建用户失败\n");system("pause");return;}}strcpy(userTable[used].userName,userName);printf("\n");printf("请输入密码:");for(i=0;c=getch();i++){if(c==13)break;elseuserTable[used].password[i]=c;printf("*");}userTable[userID].password[i]='\0';printf("\n");printf("创建用户成功\n");used++;system("pause");}else{printf("创建用户失败,用户已达到上限\n");system("pause");}fflush(stdin);//清除文件缓冲区}intlogin(){charname[10],psw[10];charc;inti,times;printf("请输入用户名:");for(i=0;c=getch();i++){if(c==13)break;elsename[i]=c;printf("%c",c);}name[i]='\0';for(i=0;i{if(!strcmp(userTable[i].userName,name))break;}if(i==used){printf("\n您输入的用户名不存在\n");system("pause");return-1;}for(times=0;times<3;times++){memset(psw,'\0',sizeof(psw));//将psw数组内的内容设置为空printf("\n请输入密码:");for(i=0;c=getch();i++){if(c==13)break;elsepsw[i]=c;printf("*");}printf("\n");for(i=0;i{if(!strcmp(psw,userTable[i].password)){printf("用户登录成功\n");system("pause");break;}}if(i==used){printf("您输入的密码错误,您还有%d次输入机会\n",2-times);if(times==2)exit(0);}elsebreak;}fflush(stdin);returni;}intrequestDist(int&startPostion,intmaxLength){intflag=0;//标记是否分配成功diskNode*p,*q,*temp;p=diskHead;while(p){if(p->useFlag==0&&p->maxlength>maxLength){startPostion=p->start;q=(diskNode*)malloc(sizeof(diskNode));q->start=p->start;q->maxlength=maxLength;q->useFlag=1;q->next=NULL;diskHead->start=p->start+maxLength;diskHead->maxlength=p->maxlength-maxLength;flag=1;temp=p;if(diskHead->next==NULL)diskHead->next=q;else{while(temp->next)temp=temp->next;temp->next=q;}break;}p=p->next;}returnflag;}voidfileCreate(charfileName[],intlength,charfileKind[])//创建文件{//inti,j;time_trawtime;intstartPos;UFD*fileNode,*p;for(p=userTable[userID].user->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName)){printf("文件重名,创建文件失败\n");system("pause");return;}}if(requestDist(startPos,length)){fileNode=(UFD*)malloc(sizeof(UFD));fileNode->file=(fileTable*)malloc(sizeof(fileTable));//这一步必不可少,因为fileNode里面的指针也需要申请地址,否则fileNode->file指向会出错strcpy(fileNode->file->fileName,fileName);strcpy(fileNode->file->fileKind,fileKind);fileNode->file->maxlength=length;fileNode->file->strat=startPos;fileNode->file->openFlag=false;time(&rawtime);fileNode->file->timeinfo=localtime(&rawtime);fileNode->next=NULL;if(userTable[userID].user->next==NULL)userTable[userID].user->next=fileNode;else{p=userTable[userID].user->next;while(p->next)p=p->next;p->next=fileNode;}printf("创建文件成功\n");system("pause");}else{printf("磁盘空间已满或所创建文件超出磁盘空闲容量,磁盘空间分配失败\n");system("pause");}}voidfreeDisk(intstartPostion){diskNode*p;for(p=diskHead;p!=NULL;p=p->next){if(p->start==startPostion)break;}p->useFlag=false;}voidfileDel(charfileName[]){UFD*p,*q,*temp;q=userTable[userID].user;p=q->next;while(p){if(!strcmp(p->file->fileName,fileName))break;else{p=p->next;q=q->next;}}if(p){if(p->file->openFlag!=true)//先判断是否有进程打开该文件{temp=p;q->next=p->next;freeDisk(temp->file->strat);//磁盘空间回收free(temp);printf("文件删除成功\n");system("pause");}else{printf("该文件已被进程打开,删除失败\n");system("pause");}}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}voidfileCat(charfileName[])//查看文件内容{intstartPos,length;intk=0;UFD*p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){startPos=p->file->strat;length=p->file->length;p->file->openFlag=true;//文件打开标记printf("*****************************************************\n");for(inti=startPos;k{if(i%50==0)printf("\n");//一行大于50个字符换行printf("%c",disk[i]);}printf("\n\n*****************************************************\n");printf("%s已被read进程打开,请用close命令将其关闭\n",p->file->fileName);system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}voidfileWrite(charfileName[])//写入{UFD*p,*q;q=userTable[userID].user;inti,k,startPos;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){if(!strcmp(p->file->fileKind,"r"))//判断文件类型是否允许写入{printf("该文件是只读文件,写入失败\n");system("pause");return;}charstr[500];printf("pleaseinputcontent:\n");gets(str);startPos=p->file->strat;p->file->openFlag=true;//文件打开标记p->file->length=strlen(str);if(p->file->length>p->file->maxlength){printf("写入字符串长度大于该文件的总长度,写入失败\n");system("pause");return;}for(i=startPos,k=0;k<(int)strlen(str);i++,k++)disk[i]=str[k];printf("文件写入成功,请用close命令将该文件关闭\n");system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}voidfileDir(charuserName[])//显示某一用户的所有文件{UFD*p;inti,k;for(i=0;i{if(!strcmp(userTable[i].userName,userName)){k=i;break;}}if(i==MaxUser){printf("没有找到该用户,请检查输入用户名是否正确\n");system("pause");return;}else{p=userTable[k].user->next;printf("********************************************************************************\n");printf("文件名文件长度文件在磁盘的起始地址文件类型创建时间\n");for(;p!=NULL;p=p->next)printf("%s%d%d%s%s",p->file->fileName,p->file->maxlength,p->file->strat,p->file->fileKind,asctime(p->file->timeinfo));printf("********************************************************************************\n");system("pause");}}voiddiskShow()//文件在磁盘上的属性{diskNode*p;inti=0,unusedDisk=0;printf("***************************************************************************\n");printf("盘块号起始地址容量(bit)是否已被使用\n");for(p=diskHead;p!=NULL;p=p->next,i++){if(p->useFlag==false)unusedDisk+=p->maxlength;printf("%d%d%d%d\n",i,p->start,p->maxlength,p->useFlag);}printf("***************************************************************************\n");printf("磁盘空间总容量:512*1024bit已使用:%dbit末使用:%dbit\n\n",MaxDisk-unusedDisk,unusedDisk);system("pause");}voidfileClose(charfileName[])//文件关闭{UFD*p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){p->file->openFlag=false;printf("%s文件已关闭\n",p->file->fileName);system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}心得体会在设计程序之前,我先花费了一天多的时间思考设计该程序的思路,熟悉了一下学过的课本,把以前忘了的东西又熟悉了一下,然后就通过操作系统要求开始设计程序了,我采用了一个模块一测试,成功之后在写另一个模块,刚开始创建文件,显示你创建成功了,可是却在指定路径中没有该文件,只有一个二级文件目录,经过我认真的查看,发现我用的函数是创建目录的,而非创建文件。随后我就选择了给他指定一个二级文件目录,在该目录中创建文件,终于测试成功了,接着我有创建了删除文件函数,打开文件函数,关闭文件函数,如文件函数,写文件函数,虽然也遇到了好多问题,我通过测试,查资料,细心的修改和调试后,最后还是一个模块一个模块的成功完成了,但是没法实现读写保护,而且整体测试时也出现了一些逻辑问题,例如:对于创建的只读文件,只写文件,可读可写文件均可以进行读写,这不符合逻辑,经过我的认真思考后,我把程序修改了一下,实现了在读,写文件前,先打开文件,而且对于只读文件,只能读取,不能写入,对于只写文件,只能写入不能读取,对于可读可写文件,既可以读取,又可以写入等功能。对于读写保护,我试着用打开文件来控制,当读文件时,可以显示打开的文件列表,该文件列表中只有只读文件和可读可写文件,当你从只写文件读取时,提示你这是只写文件,不能读取。同理,在写文件时,显示的打开的文件列表中只有只写文件和可读可写文件,当你对只读文件写入内容时,提示你这是只读文件,不能写入。这样实现了文件的读写保护。虽然本次课程设计的所做的程序规模不是很大,但在编程中我也充分体味到作为一名程序员,要有严密的逻辑思维能力的重要性,充分学好一些逻辑学科的重要性;一个没有逻辑的程序,就不能完美地实现所要完成的功能,因此,以后学习中一定会注重培养自己的逻辑思维能力,为自己成为一个高级软件工程师做好铺垫。通过这一个星期的课程设计,加深了对于操作系统这门课程的兴趣以及深入理解,培养了耐心、认真、永不放弃等优良品质。通过这次课程设计使我相信只要做,就能做到,增强了我的自信心。当然我也深深地感到了自己对某些知识的认识不足与缺陷,今后我将通过多看书及多编程序等实际手段入手,希望自己的编程能力能得到一定的提高。
if(!
strcmp(userTable[i].userName,userName))
printf("\n");
printf("该用户名已存在,创建用户失败\n");
system("pause");
return;
strcpy(userTable[used].userName,userName);
printf("请输入密码:
userTable[used].password[i]=c;
printf("*");
userTable[userID].password[i]='\0';
printf("创建用户成功\n");
used++;
printf("创建用户失败,用户已达到上限\n");
fflush(stdin);//清除文件缓冲区
intlogin()
charname[10],psw[10];
inti,times;
printf("请输入用户名:
name[i]=c;
name[i]='\0';
for(i=0;i{if(!strcmp(userTable[i].userName,name))break;}if(i==used){printf("\n您输入的用户名不存在\n");system("pause");return-1;}for(times=0;times<3;times++){memset(psw,'\0',sizeof(psw));//将psw数组内的内容设置为空printf("\n请输入密码:");for(i=0;c=getch();i++){if(c==13)break;elsepsw[i]=c;printf("*");}printf("\n");for(i=0;i{if(!strcmp(psw,userTable[i].password)){printf("用户登录成功\n");system("pause");break;}}if(i==used){printf("您输入的密码错误,您还有%d次输入机会\n",2-times);if(times==2)exit(0);}elsebreak;}fflush(stdin);returni;}intrequestDist(int&startPostion,intmaxLength){intflag=0;//标记是否分配成功diskNode*p,*q,*temp;p=diskHead;while(p){if(p->useFlag==0&&p->maxlength>maxLength){startPostion=p->start;q=(diskNode*)malloc(sizeof(diskNode));q->start=p->start;q->maxlength=maxLength;q->useFlag=1;q->next=NULL;diskHead->start=p->start+maxLength;diskHead->maxlength=p->maxlength-maxLength;flag=1;temp=p;if(diskHead->next==NULL)diskHead->next=q;else{while(temp->next)temp=temp->next;temp->next=q;}break;}p=p->next;}returnflag;}voidfileCreate(charfileName[],intlength,charfileKind[])//创建文件{//inti,j;time_trawtime;intstartPos;UFD*fileNode,*p;for(p=userTable[userID].user->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName)){printf("文件重名,创建文件失败\n");system("pause");return;}}if(requestDist(startPos,length)){fileNode=(UFD*)malloc(sizeof(UFD));fileNode->file=(fileTable*)malloc(sizeof(fileTable));//这一步必不可少,因为fileNode里面的指针也需要申请地址,否则fileNode->file指向会出错strcpy(fileNode->file->fileName,fileName);strcpy(fileNode->file->fileKind,fileKind);fileNode->file->maxlength=length;fileNode->file->strat=startPos;fileNode->file->openFlag=false;time(&rawtime);fileNode->file->timeinfo=localtime(&rawtime);fileNode->next=NULL;if(userTable[userID].user->next==NULL)userTable[userID].user->next=fileNode;else{p=userTable[userID].user->next;while(p->next)p=p->next;p->next=fileNode;}printf("创建文件成功\n");system("pause");}else{printf("磁盘空间已满或所创建文件超出磁盘空闲容量,磁盘空间分配失败\n");system("pause");}}voidfreeDisk(intstartPostion){diskNode*p;for(p=diskHead;p!=NULL;p=p->next){if(p->start==startPostion)break;}p->useFlag=false;}voidfileDel(charfileName[]){UFD*p,*q,*temp;q=userTable[userID].user;p=q->next;while(p){if(!strcmp(p->file->fileName,fileName))break;else{p=p->next;q=q->next;}}if(p){if(p->file->openFlag!=true)//先判断是否有进程打开该文件{temp=p;q->next=p->next;freeDisk(temp->file->strat);//磁盘空间回收free(temp);printf("文件删除成功\n");system("pause");}else{printf("该文件已被进程打开,删除失败\n");system("pause");}}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}voidfileCat(charfileName[])//查看文件内容{intstartPos,length;intk=0;UFD*p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){startPos=p->file->strat;length=p->file->length;p->file->openFlag=true;//文件打开标记printf("*****************************************************\n");for(inti=startPos;k{if(i%50==0)printf("\n");//一行大于50个字符换行printf("%c",disk[i]);}printf("\n\n*****************************************************\n");printf("%s已被read进程打开,请用close命令将其关闭\n",p->file->fileName);system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}voidfileWrite(charfileName[])//写入{UFD*p,*q;q=userTable[userID].user;inti,k,startPos;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){if(!strcmp(p->file->fileKind,"r"))//判断文件类型是否允许写入{printf("该文件是只读文件,写入失败\n");system("pause");return;}charstr[500];printf("pleaseinputcontent:\n");gets(str);startPos=p->file->strat;p->file->openFlag=true;//文件打开标记p->file->length=strlen(str);if(p->file->length>p->file->maxlength){printf("写入字符串长度大于该文件的总长度,写入失败\n");system("pause");return;}for(i=startPos,k=0;k<(int)strlen(str);i++,k++)disk[i]=str[k];printf("文件写入成功,请用close命令将该文件关闭\n");system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}voidfileDir(charuserName[])//显示某一用户的所有文件{UFD*p;inti,k;for(i=0;i{if(!strcmp(userTable[i].userName,userName)){k=i;break;}}if(i==MaxUser){printf("没有找到该用户,请检查输入用户名是否正确\n");system("pause");return;}else{p=userTable[k].user->next;printf("********************************************************************************\n");printf("文件名文件长度文件在磁盘的起始地址文件类型创建时间\n");for(;p!=NULL;p=p->next)printf("%s%d%d%s%s",p->file->fileName,p->file->maxlength,p->file->strat,p->file->fileKind,asctime(p->file->timeinfo));printf("********************************************************************************\n");system("pause");}}voiddiskShow()//文件在磁盘上的属性{diskNode*p;inti=0,unusedDisk=0;printf("***************************************************************************\n");printf("盘块号起始地址容量(bit)是否已被使用\n");for(p=diskHead;p!=NULL;p=p->next,i++){if(p->useFlag==false)unusedDisk+=p->maxlength;printf("%d%d%d%d\n",i,p->start,p->maxlength,p->useFlag);}printf("***************************************************************************\n");printf("磁盘空间总容量:512*1024bit已使用:%dbit末使用:%dbit\n\n",MaxDisk-unusedDisk,unusedDisk);system("pause");}voidfileClose(charfileName[])//文件关闭{UFD*p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){p->file->openFlag=false;printf("%s文件已关闭\n",p->file->fileName);system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}心得体会在设计程序之前,我先花费了一天多的时间思考设计该程序的思路,熟悉了一下学过的课本,把以前忘了的东西又熟悉了一下,然后就通过操作系统要求开始设计程序了,我采用了一个模块一测试,成功之后在写另一个模块,刚开始创建文件,显示你创建成功了,可是却在指定路径中没有该文件,只有一个二级文件目录,经过我认真的查看,发现我用的函数是创建目录的,而非创建文件。随后我就选择了给他指定一个二级文件目录,在该目录中创建文件,终于测试成功了,接着我有创建了删除文件函数,打开文件函数,关闭文件函数,如文件函数,写文件函数,虽然也遇到了好多问题,我通过测试,查资料,细心的修改和调试后,最后还是一个模块一个模块的成功完成了,但是没法实现读写保护,而且整体测试时也出现了一些逻辑问题,例如:对于创建的只读文件,只写文件,可读可写文件均可以进行读写,这不符合逻辑,经过我的认真思考后,我把程序修改了一下,实现了在读,写文件前,先打开文件,而且对于只读文件,只能读取,不能写入,对于只写文件,只能写入不能读取,对于可读可写文件,既可以读取,又可以写入等功能。对于读写保护,我试着用打开文件来控制,当读文件时,可以显示打开的文件列表,该文件列表中只有只读文件和可读可写文件,当你从只写文件读取时,提示你这是只写文件,不能读取。同理,在写文件时,显示的打开的文件列表中只有只写文件和可读可写文件,当你对只读文件写入内容时,提示你这是只读文件,不能写入。这样实现了文件的读写保护。虽然本次课程设计的所做的程序规模不是很大,但在编程中我也充分体味到作为一名程序员,要有严密的逻辑思维能力的重要性,充分学好一些逻辑学科的重要性;一个没有逻辑的程序,就不能完美地实现所要完成的功能,因此,以后学习中一定会注重培养自己的逻辑思维能力,为自己成为一个高级软件工程师做好铺垫。通过这一个星期的课程设计,加深了对于操作系统这门课程的兴趣以及深入理解,培养了耐心、认真、永不放弃等优良品质。通过这次课程设计使我相信只要做,就能做到,增强了我的自信心。当然我也深深地感到了自己对某些知识的认识不足与缺陷,今后我将通过多看书及多编程序等实际手段入手,希望自己的编程能力能得到一定的提高。
strcmp(userTable[i].userName,name))
break;
if(i==used)
printf("\n您输入的用户名不存在\n");
return-1;
for(times=0;times<3;times++)
memset(psw,'\0',sizeof(psw));//将psw数组内的内容设置为空
printf("\n请输入密码:
psw[i]=c;
for(i=0;i{if(!strcmp(psw,userTable[i].password)){printf("用户登录成功\n");system("pause");break;}}if(i==used){printf("您输入的密码错误,您还有%d次输入机会\n",2-times);if(times==2)exit(0);}elsebreak;}fflush(stdin);returni;}intrequestDist(int&startPostion,intmaxLength){intflag=0;//标记是否分配成功diskNode*p,*q,*temp;p=diskHead;while(p){if(p->useFlag==0&&p->maxlength>maxLength){startPostion=p->start;q=(diskNode*)malloc(sizeof(diskNode));q->start=p->start;q->maxlength=maxLength;q->useFlag=1;q->next=NULL;diskHead->start=p->start+maxLength;diskHead->maxlength=p->maxlength-maxLength;flag=1;temp=p;if(diskHead->next==NULL)diskHead->next=q;else{while(temp->next)temp=temp->next;temp->next=q;}break;}p=p->next;}returnflag;}voidfileCreate(charfileName[],intlength,charfileKind[])//创建文件{//inti,j;time_trawtime;intstartPos;UFD*fileNode,*p;for(p=userTable[userID].user->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName)){printf("文件重名,创建文件失败\n");system("pause");return;}}if(requestDist(startPos,length)){fileNode=(UFD*)malloc(sizeof(UFD));fileNode->file=(fileTable*)malloc(sizeof(fileTable));//这一步必不可少,因为fileNode里面的指针也需要申请地址,否则fileNode->file指向会出错strcpy(fileNode->file->fileName,fileName);strcpy(fileNode->file->fileKind,fileKind);fileNode->file->maxlength=length;fileNode->file->strat=startPos;fileNode->file->openFlag=false;time(&rawtime);fileNode->file->timeinfo=localtime(&rawtime);fileNode->next=NULL;if(userTable[userID].user->next==NULL)userTable[userID].user->next=fileNode;else{p=userTable[userID].user->next;while(p->next)p=p->next;p->next=fileNode;}printf("创建文件成功\n");system("pause");}else{printf("磁盘空间已满或所创建文件超出磁盘空闲容量,磁盘空间分配失败\n");system("pause");}}voidfreeDisk(intstartPostion){diskNode*p;for(p=diskHead;p!=NULL;p=p->next){if(p->start==startPostion)break;}p->useFlag=false;}voidfileDel(charfileName[]){UFD*p,*q,*temp;q=userTable[userID].user;p=q->next;while(p){if(!strcmp(p->file->fileName,fileName))break;else{p=p->next;q=q->next;}}if(p){if(p->file->openFlag!=true)//先判断是否有进程打开该文件{temp=p;q->next=p->next;freeDisk(temp->file->strat);//磁盘空间回收free(temp);printf("文件删除成功\n");system("pause");}else{printf("该文件已被进程打开,删除失败\n");system("pause");}}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}voidfileCat(charfileName[])//查看文件内容{intstartPos,length;intk=0;UFD*p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){startPos=p->file->strat;length=p->file->length;p->file->openFlag=true;//文件打开标记printf("*****************************************************\n");for(inti=startPos;k{if(i%50==0)printf("\n");//一行大于50个字符换行printf("%c",disk[i]);}printf("\n\n*****************************************************\n");printf("%s已被read进程打开,请用close命令将其关闭\n",p->file->fileName);system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}voidfileWrite(charfileName[])//写入{UFD*p,*q;q=userTable[userID].user;inti,k,startPos;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){if(!strcmp(p->file->fileKind,"r"))//判断文件类型是否允许写入{printf("该文件是只读文件,写入失败\n");system("pause");return;}charstr[500];printf("pleaseinputcontent:\n");gets(str);startPos=p->file->strat;p->file->openFlag=true;//文件打开标记p->file->length=strlen(str);if(p->file->length>p->file->maxlength){printf("写入字符串长度大于该文件的总长度,写入失败\n");system("pause");return;}for(i=startPos,k=0;k<(int)strlen(str);i++,k++)disk[i]=str[k];printf("文件写入成功,请用close命令将该文件关闭\n");system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}voidfileDir(charuserName[])//显示某一用户的所有文件{UFD*p;inti,k;for(i=0;i{if(!strcmp(userTable[i].userName,userName)){k=i;break;}}if(i==MaxUser){printf("没有找到该用户,请检查输入用户名是否正确\n");system("pause");return;}else{p=userTable[k].user->next;printf("********************************************************************************\n");printf("文件名文件长度文件在磁盘的起始地址文件类型创建时间\n");for(;p!=NULL;p=p->next)printf("%s%d%d%s%s",p->file->fileName,p->file->maxlength,p->file->strat,p->file->fileKind,asctime(p->file->timeinfo));printf("********************************************************************************\n");system("pause");}}voiddiskShow()//文件在磁盘上的属性{diskNode*p;inti=0,unusedDisk=0;printf("***************************************************************************\n");printf("盘块号起始地址容量(bit)是否已被使用\n");for(p=diskHead;p!=NULL;p=p->next,i++){if(p->useFlag==false)unusedDisk+=p->maxlength;printf("%d%d%d%d\n",i,p->start,p->maxlength,p->useFlag);}printf("***************************************************************************\n");printf("磁盘空间总容量:512*1024bit已使用:%dbit末使用:%dbit\n\n",MaxDisk-unusedDisk,unusedDisk);system("pause");}voidfileClose(charfileName[])//文件关闭{UFD*p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){p->file->openFlag=false;printf("%s文件已关闭\n",p->file->fileName);system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}心得体会在设计程序之前,我先花费了一天多的时间思考设计该程序的思路,熟悉了一下学过的课本,把以前忘了的东西又熟悉了一下,然后就通过操作系统要求开始设计程序了,我采用了一个模块一测试,成功之后在写另一个模块,刚开始创建文件,显示你创建成功了,可是却在指定路径中没有该文件,只有一个二级文件目录,经过我认真的查看,发现我用的函数是创建目录的,而非创建文件。随后我就选择了给他指定一个二级文件目录,在该目录中创建文件,终于测试成功了,接着我有创建了删除文件函数,打开文件函数,关闭文件函数,如文件函数,写文件函数,虽然也遇到了好多问题,我通过测试,查资料,细心的修改和调试后,最后还是一个模块一个模块的成功完成了,但是没法实现读写保护,而且整体测试时也出现了一些逻辑问题,例如:对于创建的只读文件,只写文件,可读可写文件均可以进行读写,这不符合逻辑,经过我的认真思考后,我把程序修改了一下,实现了在读,写文件前,先打开文件,而且对于只读文件,只能读取,不能写入,对于只写文件,只能写入不能读取,对于可读可写文件,既可以读取,又可以写入等功能。对于读写保护,我试着用打开文件来控制,当读文件时,可以显示打开的文件列表,该文件列表中只有只读文件和可读可写文件,当你从只写文件读取时,提示你这是只写文件,不能读取。同理,在写文件时,显示的打开的文件列表中只有只写文件和可读可写文件,当你对只读文件写入内容时,提示你这是只读文件,不能写入。这样实现了文件的读写保护。虽然本次课程设计的所做的程序规模不是很大,但在编程中我也充分体味到作为一名程序员,要有严密的逻辑思维能力的重要性,充分学好一些逻辑学科的重要性;一个没有逻辑的程序,就不能完美地实现所要完成的功能,因此,以后学习中一定会注重培养自己的逻辑思维能力,为自己成为一个高级软件工程师做好铺垫。通过这一个星期的课程设计,加深了对于操作系统这门课程的兴趣以及深入理解,培养了耐心、认真、永不放弃等优良品质。通过这次课程设计使我相信只要做,就能做到,增强了我的自信心。当然我也深深地感到了自己对某些知识的认识不足与缺陷,今后我将通过多看书及多编程序等实际手段入手,希望自己的编程能力能得到一定的提高。
strcmp(psw,userTable[i].password))
printf("用户登录成功\n");
printf("您输入的密码错误,您还有%d次输入机会\n",2-times);
if(times==2)exit(0);
elsebreak;
fflush(stdin);
returni;
intrequestDist(int&startPostion,intmaxLength)
intflag=0;//标记是否分配成功
diskNode*p,*q,*temp;
p=diskHead;
while(p)
if(p->useFlag==0&&p->maxlength>maxLength)
startPostion=p->start;
q=(diskNode*)malloc(sizeof(diskNode));
q->start=p->start;
q->maxlength=maxLength;
q->useFlag=1;
q->next=NULL;
diskHead->start=p->start+maxLength;
diskHead->maxlength=p->maxlength-maxLength;
flag=1;
temp=p;
if(diskHead->next==NULL)diskHead->next=q;
while(temp->next)temp=temp->next;
temp->next=q;
p=p->next;
returnflag;
voidfileCreate(charfileName[],intlength,charfileKind[])//创建文件
//inti,j;
time_trawtime;
intstartPos;
UFD*fileNode,*p;
for(p=userTable[userID].user->next;p!
=NULL;p=p->next)
strcmp(p->file->fileName,fileName))
printf("文件重名,创建文件失败\n");
if(requestDist(startPos,length))
fileNode=(UFD*)malloc(sizeof(UFD));
fileNode->file=(fileTable*)malloc(sizeof(fileTable));//这一步必不可少,因为fileNode里面的指针也需要申请地址,否则fileNode->file指向会出错
strcpy(fileNode->file->fileName,fileName);
strcpy(fileNode->file->fileKind,fileKind);
fileNode->file->maxlength=length;
fileNode->file->strat=startPos;
fileNode->file->openFlag=false;
time(&rawtime);
fileNode->file->timeinfo=localtime(&rawtime);
fileNode->next=NULL;
if(userTable[userID].user->next==NULL)
userTable[userID].user->next=fileNode;
p=userTable[userID].user->next;
while(p->next)p=p->next;
p->next=fileNode;
printf("创建文件成功\n");
printf("磁盘空间已满或所创建文件超出磁盘空闲容量,磁盘空间分配失败\n");
voidfreeDisk(intstartPostion)
diskNode*p;
for(p=diskHead;p!
if(p->start==startPostion)
p->useFlag=false;
voidfileDel(charfileName[])
UFD*p,*q,*temp;
q=userTable[userID].user;
p=q->next;
strcmp(p->file->fileName,fileName))break;
q=q->next;
if(p)
if(p->file->openFlag!
=true)//先判断是否有进程打开该文件
q->next=p->next;
freeDisk(temp->file->strat);//磁盘空间回收
free(temp);
printf("文件删除成功\n");
printf("该文件已被进程打开,删除失败\n");
printf("没有找到该文件,请检查输入的文件名是否正确\n");
voidfileCat(charfileName[])//查看文件内容
intstartPos,length;
intk=0;
UFD*p,*q;
for(p=q->next;p!
startPos=p->file->strat;
length=p->file->length;
p->file->openFlag=true;//文件打开标记
printf("*****************************************************\n");
for(inti=startPos;k{if(i%50==0)printf("\n");//一行大于50个字符换行printf("%c",disk[i]);}printf("\n\n*****************************************************\n");printf("%s已被read进程打开,请用close命令将其关闭\n",p->file->fileName);system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}voidfileWrite(charfileName[])//写入{UFD*p,*q;q=userTable[userID].user;inti,k,startPos;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){if(!strcmp(p->file->fileKind,"r"))//判断文件类型是否允许写入{printf("该文件是只读文件,写入失败\n");system("pause");return;}charstr[500];printf("pleaseinputcontent:\n");gets(str);startPos=p->file->strat;p->file->openFlag=true;//文件打开标记p->file->length=strlen(str);if(p->file->length>p->file->maxlength){printf("写入字符串长度大于该文件的总长度,写入失败\n");system("pause");return;}for(i=startPos,k=0;k<(int)strlen(str);i++,k++)disk[i]=str[k];printf("文件写入成功,请用close命令将该文件关闭\n");system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}voidfileDir(charuserName[])//显示某一用户的所有文件{UFD*p;inti,k;for(i=0;i{if(!strcmp(userTable[i].userName,userName)){k=i;break;}}if(i==MaxUser){printf("没有找到该用户,请检查输入用户名是否正确\n");system("pause");return;}else{p=userTable[k].user->next;printf("********************************************************************************\n");printf("文件名文件长度文件在磁盘的起始地址文件类型创建时间\n");for(;p!=NULL;p=p->next)printf("%s%d%d%s%s",p->file->fileName,p->file->maxlength,p->file->strat,p->file->fileKind,asctime(p->file->timeinfo));printf("********************************************************************************\n");system("pause");}}voiddiskShow()//文件在磁盘上的属性{diskNode*p;inti=0,unusedDisk=0;printf("***************************************************************************\n");printf("盘块号起始地址容量(bit)是否已被使用\n");for(p=diskHead;p!=NULL;p=p->next,i++){if(p->useFlag==false)unusedDisk+=p->maxlength;printf("%d%d%d%d\n",i,p->start,p->maxlength,p->useFlag);}printf("***************************************************************************\n");printf("磁盘空间总容量:512*1024bit已使用:%dbit末使用:%dbit\n\n",MaxDisk-unusedDisk,unusedDisk);system("pause");}voidfileClose(charfileName[])//文件关闭{UFD*p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){p->file->openFlag=false;printf("%s文件已关闭\n",p->file->fileName);system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}心得体会在设计程序之前,我先花费了一天多的时间思考设计该程序的思路,熟悉了一下学过的课本,把以前忘了的东西又熟悉了一下,然后就通过操作系统要求开始设计程序了,我采用了一个模块一测试,成功之后在写另一个模块,刚开始创建文件,显示你创建成功了,可是却在指定路径中没有该文件,只有一个二级文件目录,经过我认真的查看,发现我用的函数是创建目录的,而非创建文件。随后我就选择了给他指定一个二级文件目录,在该目录中创建文件,终于测试成功了,接着我有创建了删除文件函数,打开文件函数,关闭文件函数,如文件函数,写文件函数,虽然也遇到了好多问题,我通过测试,查资料,细心的修改和调试后,最后还是一个模块一个模块的成功完成了,但是没法实现读写保护,而且整体测试时也出现了一些逻辑问题,例如:对于创建的只读文件,只写文件,可读可写文件均可以进行读写,这不符合逻辑,经过我的认真思考后,我把程序修改了一下,实现了在读,写文件前,先打开文件,而且对于只读文件,只能读取,不能写入,对于只写文件,只能写入不能读取,对于可读可写文件,既可以读取,又可以写入等功能。对于读写保护,我试着用打开文件来控制,当读文件时,可以显示打开的文件列表,该文件列表中只有只读文件和可读可写文件,当你从只写文件读取时,提示你这是只写文件,不能读取。同理,在写文件时,显示的打开的文件列表中只有只写文件和可读可写文件,当你对只读文件写入内容时,提示你这是只读文件,不能写入。这样实现了文件的读写保护。虽然本次课程设计的所做的程序规模不是很大,但在编程中我也充分体味到作为一名程序员,要有严密的逻辑思维能力的重要性,充分学好一些逻辑学科的重要性;一个没有逻辑的程序,就不能完美地实现所要完成的功能,因此,以后学习中一定会注重培养自己的逻辑思维能力,为自己成为一个高级软件工程师做好铺垫。通过这一个星期的课程设计,加深了对于操作系统这门课程的兴趣以及深入理解,培养了耐心、认真、永不放弃等优良品质。通过这次课程设计使我相信只要做,就能做到,增强了我的自信心。当然我也深深地感到了自己对某些知识的认识不足与缺陷,今后我将通过多看书及多编程序等实际手段入手,希望自己的编程能力能得到一定的提高。
if(i%50==0)printf("\n");//一行大于50个字符换行
printf("%c",disk[i]);
printf("\n\n*****************************************************\n");
printf("%s已被read进程打开,请用close命令将其关闭\n",p->file->fileName);
voidfileWrite(charfileName[])//写入
inti,k,startPos;
strcmp(p->file->fileKind,"r"))//判断文件类型是否允许写入
printf("该文件是只读文件,写入失败\n");
charstr[500];
printf("pleaseinputcontent:
\n");
gets(str);
p->file->length=strlen(str);
if(p->file->length>p->file->maxlength)
printf("写入字符串长度大于该文件的总长度,写入失败\n");
for(i=startPos,k=0;k<(int)strlen(str);i++,k++)
disk[i]=str[k];
printf("文件写入成功,请用close命令将该文件关闭\n");
voidfileDir(charuserName[])//显示某一用户的所有文件
UFD*p;
inti,k;
for(i=0;i{if(!strcmp(userTable[i].userName,userName)){k=i;break;}}if(i==MaxUser){printf("没有找到该用户,请检查输入用户名是否正确\n");system("pause");return;}else{p=userTable[k].user->next;printf("********************************************************************************\n");printf("文件名文件长度文件在磁盘的起始地址文件类型创建时间\n");for(;p!=NULL;p=p->next)printf("%s%d%d%s%s",p->file->fileName,p->file->maxlength,p->file->strat,p->file->fileKind,asctime(p->file->timeinfo));printf("********************************************************************************\n");system("pause");}}voiddiskShow()//文件在磁盘上的属性{diskNode*p;inti=0,unusedDisk=0;printf("***************************************************************************\n");printf("盘块号起始地址容量(bit)是否已被使用\n");for(p=diskHead;p!=NULL;p=p->next,i++){if(p->useFlag==false)unusedDisk+=p->maxlength;printf("%d%d%d%d\n",i,p->start,p->maxlength,p->useFlag);}printf("***************************************************************************\n");printf("磁盘空间总容量:512*1024bit已使用:%dbit末使用:%dbit\n\n",MaxDisk-unusedDisk,unusedDisk);system("pause");}voidfileClose(charfileName[])//文件关闭{UFD*p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){p->file->openFlag=false;printf("%s文件已关闭\n",p->file->fileName);system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}心得体会在设计程序之前,我先花费了一天多的时间思考设计该程序的思路,熟悉了一下学过的课本,把以前忘了的东西又熟悉了一下,然后就通过操作系统要求开始设计程序了,我采用了一个模块一测试,成功之后在写另一个模块,刚开始创建文件,显示你创建成功了,可是却在指定路径中没有该文件,只有一个二级文件目录,经过我认真的查看,发现我用的函数是创建目录的,而非创建文件。随后我就选择了给他指定一个二级文件目录,在该目录中创建文件,终于测试成功了,接着我有创建了删除文件函数,打开文件函数,关闭文件函数,如文件函数,写文件函数,虽然也遇到了好多问题,我通过测试,查资料,细心的修改和调试后,最后还是一个模块一个模块的成功完成了,但是没法实现读写保护,而且整体测试时也出现了一些逻辑问题,例如:对于创建的只读文件,只写文件,可读可写文件均可以进行读写,这不符合逻辑,经过我的认真思考后,我把程序修改了一下,实现了在读,写文件前,先打开文件,而且对于只读文件,只能读取,不能写入,对于只写文件,只能写入不能读取,对于可读可写文件,既可以读取,又可以写入等功能。对于读写保护,我试着用打开文件来控制,当读文件时,可以显示打开的文件列表,该文件列表中只有只读文件和可读可写文件,当你从只写文件读取时,提示你这是只写文件,不能读取。同理,在写文件时,显示的打开的文件列表中只有只写文件和可读可写文件,当你对只读文件写入内容时,提示你这是只读文件,不能写入。这样实现了文件的读写保护。虽然本次课程设计的所做的程序规模不是很大,但在编程中我也充分体味到作为一名程序员,要有严密的逻辑思维能力的重要性,充分学好一些逻辑学科的重要性;一个没有逻辑的程序,就不能完美地实现所要完成的功能,因此,以后学习中一定会注重培养自己的逻辑思维能力,为自己成为一个高级软件工程师做好铺垫。通过这一个星期的课程设计,加深了对于操作系统这门课程的兴趣以及深入理解,培养了耐心、认真、永不放弃等优良品质。通过这次课程设计使我相信只要做,就能做到,增强了我的自信心。当然我也深深地感到了自己对某些知识的认识不足与缺陷,今后我将通过多看书及多编程序等实际手段入手,希望自己的编程能力能得到一定的提高。
k=i;break;
if(i==MaxUser)
printf("没有找到该用户,请检查输入用户名是否正确\n");
p=userTable[k].user->next;
printf("********************************************************************************\n");
printf("文件名文件长度文件在磁盘的起始地址文件类型创建时间\n");
for(;p!
printf("%s%d%d%s%s",p->file->fileName,
p->file->maxlength,p->file->strat,p->file->fileKind,asctime(p->file->timeinfo));
voiddiskShow()//文件在磁盘上的属性
inti=0,unusedDisk=0;
printf("***************************************************************************\n");
printf("盘块号起始地址容量(bit)是否已被使用\n");
=NULL;p=p->next,i++)
if(p->useFlag==false)unusedDisk+=p->maxlength;
printf("%d%d%d%d\n",i,p->start,p->maxlength,p->useFlag);
printf("磁盘空间总容量:
512*1024bit已使用:
%dbit末使用:
%dbit\n\n",MaxDisk-unusedDisk,
unusedDisk);
voidfileClose(charfileName[])//文件关闭
p->file->openFlag=false;
printf("%s文件已关闭\n",p->file->fileName);
心得体会
在设计程序之前,我先花费了一天多的时间思考设计该程序的思路,熟悉了一下学过的课本,把以前忘了的东西又熟悉了一下,然后就通过操作系统要求开始设计程序了,我采用了一个模块一测试,成功之后在写另一个模块,刚开始创建文件,显示你创建成功了,可是却在指定路径中没有该文件,只有一个二级文件目录,经过我认真的查看,发现我用的函数是创建目录的,而非创建文件。
随后我就选择了给他指定一个二级文件目录,在该目录中创建文件,终于测试成功了,接着我有创建了删除文件函数,打开文件函数,关闭文件函数,如文件函数,写文件函数,虽然也遇到了好多问题,我通过测试,查资料,细心的修改和调试后,最后还是一个模块一个模块的成功完成了,但是没法实现读写保护,而且整体测试时也出现了一些逻辑问题,例如:
对于创建的只读文件,只写文件,可读可写文件均可以进行读写,这不符合逻辑,经过我的认真思考后,我把程序修改了一下,实现了在读,写文件前,先打开文件,而且对于只读文件,只能读取,不能写入,对于只写文件,只能写入不能读取,对于可读可写文件,既可以读取,又可以写入等功能。
对于读写保护,我试着用打开文件来控制,当读文件时,可以显示打开的文件列表,该文件列表中只有只读文件和可读可写文件,当你从只写文件读取时,提示你这是只写文件,不能读取。
同理,在写文件时,显示的打开的文件列表中只有只写文件和可读可写文件,当你对只读文件写入内容时,提示你这是只读文件,不能写入。
这样实现了文件的读写保护。
虽然本次课程设计的所做的程序规模不是很大,但在编程中我也充分体味到作为一名程序员,要有严密的逻辑思维能力的重要性,充分学好一些逻辑学科的重要性;一个没有逻辑的程序,就不能完美地实现所要完成的功能,因此,以后学习中一定会注重培养自己的逻辑思维能力,为自己成为一个高级软件工程师做好铺垫。
通过这一个星期的课程设计,加深了对于操作系统这门课程的兴趣以及深入理解,培养了耐心、认真、永不放弃等优良品质。
通过这次课程设计使我相信只要做,就能做到,增强了我的自信心。
当然我也深深地感到了自己对某些知识的认识不足与缺陷,今后我将通过多看书及多编程序等实际手段入手,希望自己的编程能力能得到一定的提高。
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2