(完整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;charuserName[10];inti;if(usedMaxUser){printf(请输入用户名:);for(i=0;c=getch();i++){if(c==13)break;elseuserName[i]=c;printf(%c,c);}userName[i]='\0';for(i=0;iused;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;iused;i++){if(!strcmp(userTable[i].userName,name))break;}if(i==used){printf(\n您输入的用户名不存在\n);system(pause);return-1;}for(times=0;times3;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;iused;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-maxlengthmaxLength){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;klength;i++,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-fi

1 / 13
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功