




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、.操作系统课程设计报告姓 名: xxx _学号: xxxxxxxxxxxx _专 业 年 级: 软件2班 指 导 教 师: _xx_ 2016年 3月1日 1 概述 目的:本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能及内部实现。 意义: 本系统是基于linux平台运行在终端上的虚拟二级文件管理系统。模拟真正的文件管理系统,并采用用户登录机制对文件和文件夹进行创建,修改,删除的操作。对于文件夹而言,可以进行创建删除的操作;对于文件而言,可以创建,修改,删除。删除文件夹时,同时删除相应文件夹下的文件。采用用户登录使得用户管理文件更方便,并形成了二级的文件管理模式。 主
2、要任务:为DOS系统设计一个简单的二级文件系统.要求做到以下几点:可以实现下列命令:login用户登录dir列文件目录create创建文件delete删除文件open打开文件close关闭文件read读文件write写文件列目录时要列出文件名、物理地址、保护码和文件长度.源文件可以进行读写保护2 系统设计 (1)设计思路程序中要求每个用户在登陆后才可对其拥有的文件进行操作,用户对于其他用户的文件无操作权.文件操作包括浏览、创建、删除、打开、关闭、阅读、写入、修改模式.其他操作包括新建用户、帮助、用户登入、用户登出、退出系统.在程序文件夹下有个名为“file”的系统根目录,此目录下包括:一个名为
3、“mfd”的文件,记录所有注册过的帐号及密码;用户文件,以用户名作为文件名,内容为其拥有的文件名及属性;一个名为“keiji”的文件夹.“keiji”文件夹中包括:“file.p”指针文件,记录所有已用的物理地址;一些以物理地址为名的文件,内容为文件内容.(2)数据结构file结构体系统文件.数据结构:fpaddrint,文件的物理地址、flengthint,文件长度、fmodeint,文件模式0.只读;1.可写;2.可读写;3.保护、fnamechar,文件名;filemode结构体文件状态数据结构:isopenint,文件当前状态,0.关闭;1.打开、modeint,文件模式0.只读;1.
4、可写;2.可读写。(3)初始化user结构体用户信息数据结构:unamechar,用户名、upasswordchar,用户密码;userfile结构体用户文件数据结构:unamechar,用户名、ufilefile,用户拥有的文件数组3 系统实现#include#include#include#include#include#defineMaxUser100 /定义最大mdf目录文件#defineMaxDisk 512*1024 / 模拟最大磁盘空间 512k#definecommandAmount12 / 对文件操作指令数chardiskMaxDisk; / 模拟512k磁盘空间typede
5、fstructdistTable/磁盘块结构体intmaxlength;intstart;intuseFlag;distTable*next;diskNode;diskNode*diskHead;structfileTable/文件块结构体charfileName10;intstrat;/文件在磁盘存储空间的起始地址intlength;/文件内容长度intmaxlength;/文件的最大长度charfileKind3;/文件的属性读写方式structtm*timeinfo;boolopenFlag;/判断是否有进程打开了文件/fileTable*next;/两级目录结构体typedefstru
6、ctuser_file_directory/用户文件目录文件UFD/charfileName10;fileTable*file;user_file_directory*next;UFD;/UFD*headFile;typedefstructmaster_file_directory /主文件目录MFDcharuserName10;charpassword10;UFD*user;MFD;MFDuserTableMaxUser;intused=0; /定义MFD目录中用已有的用户数/文件管理voidfileCreate(charfileName,intlength,charfileKind); /
7、创建文件voidfileWrite(charfileName);/ 写文件voidfileCat(charfileName);/读文件voidfileRen(charfileName,charrename);/ 重命名文件voidfileFine(charfileName);/查询文件voidfileDir(charUserName);/ 显示某一用户的所有文件voidfileClose(charfileName);/ 关闭以打开的文件voidfileDel(charfileName);/删除文件voidchmod(charfileName,charkind); /修改文件的读写方式intre
8、questDist(int&startPostion,intmaxLength); /磁盘分配查询voidinitDisk();/ 初始化磁盘voidfreeDisk(intstartPostion);/磁盘空间释放voiddiskShow();/显示磁盘使用情况/用户管理voiduserCreate();intlogin();intuserID=-1;/用户登录的ID号,值为-1时表示没有用户登录intmain()charordercommandAmount10;strcpy(order0,create);strcpy(order1,rm);strcpy(order2,cat);strcpy
9、(order3,write);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;inext=N
10、ULL;while(1)printf(*n);printf(1、Creatusern);printf(2、loginn);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,将创建名为a
11、1,长度为1000字节可读可写的文件n);printf(rm-删除格式:rma1,将删除名为a1的文件n);printf(cat-查看文件内容格式:cata1,显示a1的内容n);printf(write-写入格式:writea1n);printf(fine-查询格式:finea1,将显示文件a1的属性n);printf(chmod-修改格式:chmoda1r,将文件al的权限改为只读方式n); printf(ren-重命名格式:rena1b1,将a1改名为b1n);printf(dir-显示文件格式:diraaa,将显示aaa用户的所有文件n);printf(df-显示磁盘空间使用情况格式:
12、dfn);printf(close-关闭文件格式:closea1,将关闭文件a1n);printf(return-退出用户,返回登录界面n);printf(exit-退出程序n);printf(*n);printf(pleaseimputyourcommand:); gets(command);intselect;for(i=0;commandi!=&commandi!=0;i+)/command_str1字符串存储命令的操作类型command_str1i=commandi;k=i;command_str1k=0;for(i=0;i=0;i-)/把字符串转换为十进制length+=(comma
13、nd_str3i-48)*j; j*=10;for(i=k+1,k=0;commandi!=&commandi!=0;i+,k+)command_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;cas
14、e5:for(i=k+1,k=0;commandi!=&commandi!=0;i+,k+)command_str3k=commandi;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_
15、str2);break;case9:UFD*p;for(p=userTableuserID.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;charuserName10;inti;if(usedMaxUser)printf(请输入用户名:);for(i=0;c=getch(
16、);i+)if(c=13)break;else userNamei=c;printf(%c,c); userNamei=0;for(i=0;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.passwor
17、di=c;printf(*);userTableuserID.passwordi=0;printf(n);printf(创建用户成功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(!strc
18、mp(userTablei.userName,name)break; if(i=used) printf(n您输入的用户名不存在n);system(pause);return-1; 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;diskHead-useFlag=0;diskHead-start=0;diskHead-next
19、=NULL;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;di
20、skHead-maxlength=p-maxlength-maxLength;flag=1;temp=p;if(diskHead-next=NULL)diskHead-next=q;elsewhile(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=userTableuserID.user-next;p!=
21、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)
22、;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(userTableuserID.user-next=NULL)userTableuserID.user-next=fileNode;elsep=userTableuserID.u
23、ser-next;while(p-next)p=p-next;p-next=fileNode;printf(创建文件成功n);system(pause);elseprintf(磁盘空间已满或所创建文件超出磁盘空闲容量,磁盘空间分配失败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=userTa
24、bleuserID.user;p=q-next;while(p) if(!strcmp(p-file-fileName,fileName)break;elsep=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);elseprintf(该文件已被进程打开,删除失败n);system(pause);elseprintf(没有找到该文件,请
25、检查输入的文件名是否正确n);system(pause);voidfileCat(charfileName)intstartPos,length;intk=0;UFD*p,*q;q=userTableuserID.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-file
26、Name); system(pause);elseprintf(没有找到该文件,请检查输入的文件名是否正确n);system(pause);voidfileWrite(charfileName)UFD*p,*q;q=userTableuserID.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);ret
27、urn; charstr500;printf(pleaseinputcontent:n);gets(str);startPos=p-file-strat;p-file-openFlag=true;/文件打开标记p-file-length=strlen(str);if(p-file-lengthp-file-maxlength)printf(写入字符串长度大于该文件的总长度,写入失败n);system(pause);return; for(i=startPos,k=0;knext;p!=NULL;p=p-next)if(!strcmp(p-file-fileName,fileName)break
28、; if(p) printf(*n); printf(文件名:%sn,p-file-fileName); printf(文件长度:%dn,p-file-maxlength);printf(文件在存储空间的起始地址:%dn,p-file-strat);printf(文件类型:%sn,p-file-fileKind);printf(创建时间:%sn,asctime(p-file-timeinfo);printf(*n);system(pause);elseprintf(没有找到该文件,请检查输入的文件名是否正确n);system(pause);voidchmod(charfileName,char
29、kind)UFD*p,*q;q=userTableuserID.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);elseprintf(没有找到该文件,请检查输入的文件名是否正确n);system(pause);voidfileRen(charfileName,charname)UFD*p,*q;q=userTableuserID.user;for(p=q
30、-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);elseprintf(没有找到该文件,请检查输入的文件名是否正确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
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年前后顺序测试题及答案
- 2025年科技社区考试题目及答案
- 2025年古建瓦工 考试题及答案
- 2025年解比例试题及答案
- 2025年高空考试题目及答案
- 2025年科学健身知识竞赛题库
- 2025卫生职称康复高级职称(正高)模拟考试题及答案
- 2025年东营市中医院招聘考试试卷附答案
- 2025年有关纪律的面试题及答案
- 2025年形动型的试题及答案
- DB3303-T 052-2022 公务用车 报废和更新程序
- 2022年连云港远程教育党的百年奋斗历史经验答案
- 运动障碍性疾病
- 高考3500英语必备词汇100天突破(直接打印)
- 机动车保险索赔权益人转让协议书
- 建筑基桩检测技术规范JGJ106完整版(完整版)资料
- GB/T 7672.3-2008玻璃丝包绕组线第3部分:155级浸漆玻璃丝包铜扁线和玻璃丝包漆包铜扁线
- 钳工技能考试(高级)钳工题库及答案(完整版)
- 鼻腔冲洗医学课件
- 《风力机理论与设计》全套教学课件
- 化学第一轮专题练习-专题八 化学键分子结构与性质
评论
0/150
提交评论