收藏 分销(赏)

文件管理课程设计报告.doc

上传人:a199****6536 文档编号:3905745 上传时间:2024-07-23 格式:DOC 页数:28 大小:63.54KB
下载 相关 举报
文件管理课程设计报告.doc_第1页
第1页 / 共28页
文件管理课程设计报告.doc_第2页
第2页 / 共28页
文件管理课程设计报告.doc_第3页
第3页 / 共28页
文件管理课程设计报告.doc_第4页
第4页 / 共28页
文件管理课程设计报告.doc_第5页
第5页 / 共28页
点击查看更多>>
资源描述

1、操作系统课程设计报告姓 名:xxx_学号:xxxxxxxxxxxx_专 业 年 级:软件2班指 导 教 师:_xx_2016年 3月1日1 概述目的:本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能及内部实现.意义: 本系统是基于linux平台运行在终端上的虚拟二级文件管理系统.模拟真正的文件管理系统,并采用用户登录机制对文件和文件夹进行创建,修改,删除的操作。对于文件夹而言,可以进行创建删除的操作;对于文件而言,可以创建,修改,删除。删除文件夹时,同时删除相应文件夹下的文件。采用用户登录使得用户管理文件更方便,并形成了二级的文件管理模式.主要任务:为DOS系统设计一

2、个简单的二级文件系统.要求做到以下几点:可以实现下列命令:login用户登录dir列文件目录create创建文件delete删除文件open打开文件close关闭文件read读文件write写文件列目录时要列出文件名、物理地址、保护码和文件长度。源文件可以进行读写保护2 系统设计(1)设计思路程序中要求每个用户在登陆后才可对其拥有的文件进行操作,用户对于其他用户的文件无操作权。文件操作包括浏览、创建、删除、打开、关闭、阅读、写入、修改模式.其他操作包括新建用户、帮助、用户登入、用户登出、退出系统。在程序文件夹下有个名为“file”的系统根目录,此目录下包括:一个名为“mfd”的文件,记录所有注

3、册过的帐号及密码;用户文件,以用户名作为文件名,内容为其拥有的文件名及属性;一个名为“keiji”的文件夹.“keiji文件夹中包括:“file。p指针文件,记录所有已用的物理地址;一些以物理地址为名的文件,内容为文件内容。(2)数据结构file结构体系统文件。数据结构:fpaddrint,文件的物理地址、flengthint,文件长度、fmodeint,文件模式0。只读;1.可写;2。可读写;3.保护、fnamechar,文件名;filemode结构体文件状态数据结构:isopenint,文件当前状态,0。关闭;1.打开、modeint,文件模式0。只读;1.可写;2。可读写。(3)初始化u

4、ser结构体用户信息数据结构:unamechar,用户名、upasswordchar,用户密码;userfile结构体用户文件数据结构:unamechar,用户名、ufilefile,用户拥有的文件数组3 系统实现includeinclude#includeconio。h#include#include#defineMaxUser100 /定义最大mdf目录文件#defineMaxDisk5121024 / 模拟最大磁盘空间 512k#definecommandAmount12 / 对文件操作指令数chardiskMaxDisk; / 模拟512k磁盘空间typedefstructdistTa

5、ble/磁盘块结构体intmaxlength;intstart;intuseFlag;distTable*next;diskNode;diskNode*diskHead;structfileTable/文件块结构体charfileName10;intstrat;/文件在磁盘存储空间的起始地址intlength;/文件内容长度intmaxlength;/文件的最大长度charfileKind3;/文件的属性读写方式structtmtimeinfo;boolopenFlag;/判断是否有进程打开了文件/fileTablenext;;/两级目录结构体typedefstructuser_file_di

6、rectory/用户文件目录文件UFD/charfileName10;fileTablefile;user_file_directory*next;UFD;/UFD*headFile;typedefstructmaster_file_directory/主文件目录MFDcharuserName10;charpassword10;UFDuser;MFD;MFDuserTableMaxUser;intused=0;/定义MFD目录中用已有的用户数/文件管理voidfileCreate(charfileName,intlength,charfileKind); /创建文件voidfileWrite(

7、charfileName);/ 写文件voidfileCat(charfileName);/读文件voidfileRen(charfileName,charrename);/ 重命名文件voidfileFine(charfileName);/查询文件voidfileDir(charUserName);/ 显示某一用户的所有文件voidfileClose(charfileName);/ 关闭以打开的文件voidfileDel(charfileName);/删除文件voidchmod(charfileName,charkind); /修改文件的读写方式intrequestDist(int&star

8、tPostion,intmaxLength);/磁盘分配查询voidinitDisk();/ 初始化磁盘voidfreeDisk(intstartPostion);/磁盘空间释放voiddiskShow();/显示磁盘使用情况/用户管理voiduserCreate();intlogin();intuserID=1;/用户登录的ID号,值为1时表示没有用户登录intmain()charordercommandAmount10;strcpy(order0,create”);strcpy(order1,rm”);strcpy(order2,”cat”);strcpy(order3,”write”);

9、strcpy(order4,”fine”);strcpy(order5,”chmod);strcpy(order6,”ren”);strcpy(order7,dir”);strcpy(order8,”close”);strcpy(order9,return);strcpy(order10,”exit”);strcpy(order11,”df”);charcommand50,command_str110,command_str210,command_str35,command_str43;inti,k,j;intlength;initDisk();/初始化磁盘for(i=0;i); gets(c

10、ommand);intselect;for(i=0;commandi!=&commandi!=0;i+)/command_str1字符串存储命令的操作类型command_str1i=commandi;k=i;command_str1k=0;for(i=0;icommandAmount;i+)if(!strcmp(command_str1,orderi))select=i;break;if(i=commandAmount) printf(”您输入的命令有误,请重新输入n”);continue;for(i=k+1,k=0;commandi!=commandi!=0;i+,k+)/commmand_

11、str2字符串存储文件名或用户名command_str2k=commandi;command_str2k=0;k=i;switch(select)case0:for(i=k+1,k=0;commandi!=;i+,k+)command_str3k=commandi;command_str3k=0;k=i;j=1;length=0;/初始化文件长度for(i=strlen(command_str3)-1;i=0;i)/把字符串转换为十进制length+=(command_str3i48)j; j=10;for(i=k+1,k=0;commandi!=&commandi!=0;i+,k+)comm

12、and_str4k=commandi;command_str4k=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;commandi!=&commandi!=0;i+,k+)command_str3k=commandi;

13、command_str3k=0;chmod(command_str2,command_str3);break;case6:for(i=k+1,k=0;commandi!=0;i+,k+)command_str3k=commandi;command_str3k=0;fileRen(command_str2,command_str3);break;case7:fileDir(command_str2);break;case8:fileClose(command_str2);break;case9:UFDp;for(p=userTableuserID.user-next;p!=NULL;p=pnex

14、t)/退出用户之前关闭所有打的文件if(pfile-openFlag)p-file-openFlag=false;system(cls”);userID=-1;break;case10:exit(0);break; case11:diskShow();break;return0;voiduserCreate()charc;charuserName10;inti;if(usedMaxUser)printf(”请输入用户名:”);for(i=0;c=getch();i+)if(c=13)break;elseuserNamei=c;printf(”c”,c);userNamei=0;for(i=0;

15、iused;i+)if(!strcmp(userTablei。userName,userName)) printf(n);printf(”该用户名已存在,创建用户失败n”);system(”pause”);return;strcpy(userTableused。userName,userName);printf(n”);printf(”请输入密码:);for(i=0;c=getch();i+)if(c=13)break;elseuserTableused。passwordi=c;printf(”);userTableuserID.passwordi=0;printf(n”);printf(创建

16、用户成功n”);used+;system(pause”);elseprintf(”创建用户失败,用户已达到上限n”);system(”pause);fflush(stdin); intlogin()charname10,psw10;charc;inti,times;printf(请输入用户名:”);for(i=0;c=getch();i+)if(c=13)break;elsenamei=c;printf(c,c); namei=0;for(i=0;iused;i+)if(!strcmp(userTablei。userName,name))break; if(i=used) printf(”n您

17、输入的用户名不存在n”);system(”pause”);return1; for(times=0;times3;times+)memset(psw,0,sizeof(psw);printf(”n请输入密码:);for(i=0;c=getch();i+)if(c=13)break;elsepswi=c;printf(*);printf(n”);for(i=0;imaxlength=MaxDisk;diskHeaduseFlag=0;diskHeadstart=0;diskHeadnext=NULL;intrequestDist(int&startPostion,intmaxLength)int

18、flag=0;/标记是否分配成功diskNodep,*q,*temp;p=diskHead;while(p)if(p-useFlag=0&pmaxlengthmaxLength)startPostion=pstart;q=(diskNode*)malloc(sizeof(diskNode);qstart=pstart;qmaxlength=maxLength;quseFlag=1;q-next=NULL;diskHead-start=p-start+maxLength;diskHead-maxlength=p-maxlength-maxLength;flag=1;temp=p;if(diskH

19、ead-next=NULL)diskHeadnext=q;elsewhile(tempnext)temp=tempnext;temp-next=q;break;p=pnext;returnflag;voidfileCreate(charfileName,intlength,charfileKind)/inti,j;time_trawtime;intstartPos;UFD*fileNode,*p;for(p=userTableuserID.user-next;p!=NULL;p=p-next)if(!strcmp(pfile-fileName,fileName)printf(”文件重名,创建文

20、件失败n);system(”pause”);return; if(requestDist(startPos,length)fileNode=(UFD)malloc(sizeof(UFD));fileNodefile=(fileTable*)malloc(sizeof(fileTable);/这一步必不可少,因为fileNode里面的指针也需要申请地址,否则fileNodefile指向会出错strcpy(fileNode-filefileName,fileName);strcpy(fileNodefilefileKind,fileKind);fileNodefile-maxlength=leng

21、th;fileNodefilestrat=startPos;fileNode-file-openFlag=false;time(&rawtime);fileNode-file-timeinfo=localtime(rawtime); fileNode-next=NULL;if(userTableuserID。user-next=NULL)userTableuserID。usernext=fileNode;elsep=userTableuserID。usernext;while(pnext)p=pnext;pnext=fileNode;printf(创建文件成功n);system(”pause”

22、);elseprintf(”磁盘空间已满或所创建文件超出磁盘空闲容量,磁盘空间分配失败n”);system(pause);voidfreeDisk(intstartPostion)diskNodep;for(p=diskHead;p!=NULL;p=pnext)if(pstart=startPostion)break;puseFlag=false;voidfileDel(charfileName)UFDp,q,temp;q=userTableuserID.user;p=qnext;while(p) if(!strcmp(pfile-fileName,fileName))break;elsep=

23、pnext;q=q-next; if(p) if(p-fileopenFlag!=true)/先判断是否有进程打开该文件temp=p;qnext=p-next;freeDisk(temp-file-strat);/磁盘空间回收free(temp);printf(”文件删除成功n”);system(”pause);elseprintf(该文件已被进程打开,删除失败n);system(”pause”);elseprintf(”没有找到该文件,请检查输入的文件名是否正确n);system(”pause”);voidfileCat(charfileName)intstartPos,length;int

24、k=0;UFD*p,q;q=userTableuserID。user;for(p=qnext;p!=NULL;p=pnext)if(!strcmp(pfile-fileName,fileName))break;if(p) startPos=p-filestrat;length=p-file-length;pfileopenFlag=true;/文件打开标记printf(”*n);for(inti=startPos;kfilefileName); system(”pause”);elseprintf(”没有找到该文件,请检查输入的文件名是否正确n);system(”pause”);voidfil

25、eWrite(charfileName)UFD*p,q;q=userTableuserID。user;inti,k,startPos;for(p=q-next;p!=NULL;p=pnext)if(!strcmp(p-filefileName,fileName)break; if(p) if(!strcmp(p-filefileKind,”r)/判断文件类型printf(”该文件是只读文件,写入失败n”);system(”pause”);return;charstr500;printf(”pleaseinputcontent:n”);gets(str);startPos=p-file-stra

26、t;p-file-openFlag=true;/文件打开标记pfilelength=strlen(str);if(pfilelengthpfilemaxlength)printf(”写入字符串长度大于该文件的总长度,写入失败n”);system(”pause”);return; for(i=startPos,k=0;k(int)strlen(str);i+,k+)diski=strk;printf(”文件写入成功,请用close命令将该文件关闭n);system(”pause);elseprintf(没有找到该文件,请检查输入的文件名是否正确n”);system(pause”);voidfil

27、eFine(charfileName)UFD*p,q;q=userTableuserID。user;for(p=qnext;p!=NULL;p=pnext)if(!strcmp(pfile-fileName,fileName))break; if(p) printf(”*n);printf(文件名:sn”,p-file-fileName);printf(文件长度:dn”,pfilemaxlength);printf(”文件在存储空间的起始地址:%dn,p-file-strat);printf(”文件类型:%sn”,pfile-fileKind);printf(创建时间:sn,asctime(pfiletimeinfo);printf(*n);system(pause”);elseprintf(没有找到该文件,请检查输入的文件名是否正确n”);system(”pause”);voidchmod(charfileName,charkind)UFD*p,*q;q=userTableuserID.user;for(p=qnext;p!=NULL;p=pn

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 学术论文 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服