首页 模拟一个简单二级文件管理系统

模拟一个简单二级文件管理系统

举报
开通vip

模拟一个简单二级文件管理系统模拟一个简单二级文件管理系统设计目的:通过具体的文件存储空间的管理、文件的物理结构、目录结构和文件操作的实现,加深对文件系统内部功能和实现过程的理解。设计内容:模拟一个简单二级文件管理系统一、实验内容描述1实验目标本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能及内部实现.2实验要求为DOS系统设计一个简单的二级文件系统.要求做到以下几点:①可以实现下列命令:login用户登录dir列文件目录create创建文件delete删除文件open打开文件close关闭文件read读文件write...

模拟一个简单二级文件管理系统
模拟一个简单二级文件管理系统设计目的:通过具体的文件存储空间的管理、文件的物理结构、目录结构和文件操作的实现,加深对文件系统内部功能和实现过程的理解。设计 内容 财务内部控制制度的内容财务内部控制制度的内容人员招聘与配置的内容项目成本控制的内容消防安全演练内容 :模拟一个简单二级文件管理系统一、实验内容描述1实验目标本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能及内部实现.2实验要求为DOS系统设计一个简单的二级文件系统.要求做到以下几点:①可以实现下列命令:login用户登录dir列文件目录create创建文件delete删除文件open打开文件close关闭文件read读文件write写文件②列目录时要列出文件名、物理地址、保护码和文件长度.③源文件可以进行读写保护.二、程序主要内容1设计思路程序中要求每个用户在登陆后才可对其拥有的文件进行操作,用户对于其他用户的文件无操作权.文件操作包括浏览、创建、删除、打开、关闭、阅读、写入、修改模式.其他操作包括新建用户、帮助、用户登入、用户登出、退出系统.在程序文件夹下有个名为“file”的系统根目录,此目录下包括:一个名为“mfd”的文件,记录所有注册过的帐号及密码;用户文件,以用户名作为文件名,内容为其拥有的文件名及属性;一个名为“keiji”的文件夹.“keiji”文件夹中包括:“file.p”指针文件,记录所有已用的物理地址;一些以物理地址为名的文件,内容为文件内容.2数据结构file结构体系统文件数据结构:fpaddrint,文件的物理地址、flengthint,文件长度、fmodeint,文件模式0.只读;1.可写;2.可读写;3.保护、fname[]char,文件名;filemode结构体文件状态数据结构:isopenint,文件当前状态,0.关闭;1.打开、modeint,文件模式0.只读;1.可写;2.可读写;3.初始化;user结构体用户信息数据结构:uname[]char,用户名、upassword[]char,用户密码;userfile结构体用户文件数据结构:uname[]char,用户名、ufile[]file,用户拥有的文件数组........[cpp]viewplaincopyprint?#include#include#include#include#include#defineMaxUser100//定义最大MDF主目录文件#defineMaxDisk512*1024//模拟最大磁盘空间#definecommandAmount12//对文件操作的指令数//存储空间管理有关结构体和变量chardisk[MaxDisk];//模拟512K的磁盘存储空间typedefstructdistTable//磁盘块结构体{intmaxlength;intstart;intuseFlag;distTable*next;}diskNode;diskNode*diskHead;structfileTable//文件块结构体{charfileName[10];intstrat;//文件在磁盘存储空间的起始地址intlength;//文件内容长度intmaxlength;//文件的最大长度charfileKind[3];//文件的属性——读写方式structtm*timeinfo;boolopenFlag;//判断是否有进程打开了该文件//fileTable*next;};//两级目录结构体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;MFDuserTable[MaxUser];intused=0;//定义MFD目录中用已有的用户数//文件管理voidfileCreate(charfileName[],intlength,charfileKind[]);//创建文件voidfileWrite(charfileName[]);//写文件voidfileCat(charfileName[]);//读文件voidfileRen(charfileName[],charrename[]);//重命名文件voidfileFine(charfileName[]);//查询文件voidfileDir(charUserName[]);//显示某一用户的所有文件voidfileClose(charfileName[]);//关闭已打开的文件voidfileDel(charfileName[]);//删除文件voidchmod(charfileName[],charkind[]);//修改文件的读写方式intrequestDist(int&startPostion,intmaxLength);//磁盘分配查询voidinitDisk();//初始化磁盘voidfreeDisk(intstartPostion);//磁盘空间释放voiddiskShow();//显示磁盘使用情况//用户管理voiduserCreate();intlogin();intuserID=-1;//用户登录的ID号,值为-1时 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf 示没有用户登录intmain(){charorder[commandAmount][10];strcpy(order[0],"create");strcpy(order[1],"rm");strcpy(order[2],"cat");strcpy(order[3],"write");strcpy(order[4],"fine");strcpy(order[5],"chmod");strcpy(order[6],"ren");strcpy(order[7],"dir");strcpy(order[8],"close");strcpy(order[9],"return");strcpy(order[10],"exit");strcpy(order[11],"df");charcommand[50],command_str1[10],command_str2[10],command_str3[5],command_str4[3];inti,k,j;intlength;initDisk();//初始化磁盘for(i=0;inext=NULL;}while(1){printf("********************************************/n");printf("1、Creatuser/n");printf("2、login/n");printf("********************************************/n");printf("Pleasechoocethefunctionkey:>");intchoice;scanf("%d",&choice);if(choice==1)userCreate();elseif(choice==2)userID=login();elseprintf("您的输入有误,请重新选择/n");while(userID!=-1){fflush(stdin);printf("———————————————————————————————————————/n");printf("create-创建格式:createa11000rw,将创建名为a1,长度为100 0字 个人自传范文3000字为中华之崛起而读书的故事100字新时代好少年事迹1500字绑架的故事5000字个人自传范文2000字 节可读可写的文件/n");printf("rm-删除格式:rma1,将删除名为a1的文件/n");printf("cat-查看文件内容格式:cata1,显示a1的内容/n");printf("write-写入格式:writea1/n");printf("fine-查询格式:finea1,将显示文件a1的属性/n");printf("chmod-修改格式:chmoda1r,将文件a1的权限改为只读方式/n");printf("ren-重命名格式:rena1b1,将a1改名为b1/n");printf("dir-显示文件格式:diraaa,将显示aaa用户的所有文件/n");printf("df-显示磁盘空间使用情况格式:df/n");printf("close-关闭文件格式:closea1,将关闭文件a1/n");printf("return-退出用户,返回登录界面/n");printf("exit-退出程序/n");printf("————————————————————————————————————————/n");printf("pleaseimputyourcommand:>");gets(command);intselect;for(i=0;command[i]!=''&&command[i]!='/0';i++)//command_str1字符串存储命令的操作类型command_str1[i]=command[i];k=i;command_str1[k]='/0';for(i=0;i=0;i--)//把字符串转换为十进制{length+=(command_str3[i]-48)*j;j*=10;}for(i=k+1,k=0;command[i]!=''&&command[i]!='/0';i++,k++)command_str4[k]=command[i];command_str4[k]='/0';fileCreate(command_str2,length,command_str4);break;case1:fileDel(command_str2);break;case2:fileCat(command_str2);break;case3:fileWrite(command_str2);break;case4:fileFine(command_str2);break;case5:for(i=k+1,k=0;command[i]!=''&&command[i]!='/0';i++,k++)command_str3[k]=command[i];command_str3[k]='/0';chmod(command_str2,command_str3);break;case6:for(i=k+1,k=0;command[i]!='/0';i++,k++)command_str3[k]=command[i];command_str3[k]='/0';fileRen(command_str2,command_str3);break;case7:fileDir(command_str2);break;case8:fileClose(command_str2);break;case9:UFD*p;for(p=userTable[userID].user->next;p!=NULL;p=p->next)//退出用户之前关闭所有打的文件if(p->file->openFlag)p->file->openFlag=false;system("cls");userID=-1;break;case10:exit(0);break;case11:diskShow();break;}}}return0;}voiduserCreate(){charc;charuserName[10];inti;if(usedmaxlength=MaxDisk;diskHead->useFlag=0;diskHead->start=0;diskHead->next=NULL;}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;kfile->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");}}voidfileFine(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){printf("********************************************/n");printf("文件名:%s/n",p->file->fileName);printf("文件长度:%d/n",p->file->maxlength);printf("文件在存储空间的起始地址:%d/n",p->file->strat);printf("文件类型:%s/n",p->file->fileKind);printf("创建时间:%s/n",asctime(p->file->timeinfo));printf("********************************************/n");system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确/n");system("pause");}}voidchmod(charfileName[],charkind[]){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){strcpy(p->file->fileKind,kind);printf("修改文件类型成功/n");system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确/n");system("pause");}}voidfileRen(charfileName[],charname[]){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){while(q->next){if(!strcmp(q->next->file->fileName,name)){printf("您输入的文件名已存在,重命名失败/n");system("pause");return;}q=q->next;}strcpy(p->file->fileName,name);printf("重命名成功/n");system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确/n");system("pause");}}voidfileDir(charuserName[]){UFD*p;inti,k;for(i=0;inext;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");}}
本文档为【模拟一个简单二级文件管理系统】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
个人认证用户
楼上的小胖子
暂无简介~
格式:doc
大小:27KB
软件:Word
页数:20
分类:
上传时间:2023-03-02
浏览量:2