操作系统课程设计模拟一个简单二级文件管理系统_第1页
操作系统课程设计模拟一个简单二级文件管理系统_第2页
操作系统课程设计模拟一个简单二级文件管理系统_第3页
操作系统课程设计模拟一个简单二级文件管理系统_第4页
操作系统课程设计模拟一个简单二级文件管理系统_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、evaluation of scientific development. nature security type-nature security is to maintenance people of health value for target, through strengthening security based management, and risk management, and equipment management and technology supervision, ensure production in the people, and real, and sy

2、stem, and system, elements security reliable, and harmony unified, full control various against factors, achieved thought no slack, and management no empty document, and equipment no hidden, and system no blocked, and unit zero non-stopped. quality and efficiency-quality benefit is to adhere to the

3、enterprise "survival, profit and development" business truth, adhere to the "all activity is economic activity, all costs can be controlled, money should not be wasted" management philosophy, management analysis, to improve management quality, improve cost control capacity and ma

4、rket competitiveness. innovation of science and technology-science and technology innovation is to play the role of science and technology as the primary productive force, active use of new technologies, new materials, new processes, new equipment, increase investment in science and technology, stre

5、ngthening scientific and technological training, speeding up transforming scientific and technological achievements, forming a number of proprietary technology, enhancing core competitiveness. resource-saving-the-resources saving enterprise was to reduce coal consumption, water consumption, electric

6、ity at the core, enhance the operation of lean management to realize low consumption, high efficiency, reduce production costs. second is to strengthen the business, financial, material, information and the optimization of organization and management, saving the internal transaction costs. harmoniou

7、s development of harmonious development-is to construct a "foreign" environment for development. "xing" refers to the "internal security firm and internal management of the internal management measures are effective, harmonious". "foreign currency" means "

8、;enterprise coordinating development of homeopathy, well, get along with the neighbors better." (b) xx 2013 five enterprises building intrinsic safety power company goals are: unplanned outage 0 times. class of disorders 0, 0 is equivalent forced outage rate. no personal injury accident, materi

9、al and equipment accidents do not occur, no fire, no environmental pollution accident. enterprise integrated to achieve zero cases of violation, zero accidents, zero. quality goal is: when generating capacity 7.5 billion-kilowatt, sales of over 7.11 billion kwh, total profits of 306.6 million yuan,

10、. bfs+、pi、mis、scm information systems infrastructure, fully integrated information system to realize information resources sharing; to expand the breadth and depth of the portal system, information system of enterprise management assistant role to play; to improve the day-to-day operation and mainte

11、nance operation record of promoting causes and transfer system; to strengthen the training模拟一个简单二级文件管理系统设计目的:通过具体的文件存储空间的管理、文件的物理结构、目录结构和文件操作的实现,加深对文件系统内部功能和实现过程的理解。设计内容:模拟一个简单二级文件管理系统 一、实验内容描述1 实验目标本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能及内部实现.2 实验要求为dos系统设计一个简单的二级文件系统.要求做到以下几点:可以实现下列命令:login 用户登录dir

12、列文件目录create 创建文件delete 删除文件open 打开文件close 关闭文件read 读文件write 写文件列目录时要列出文件名、物理地址、保护码和文件长度.源文件可以进行读写保护.二、程序主要内容1设计思路程序中要求每个用户在登陆后才可对其拥有的文件进行操作,用户对于其他用户的文件无操作权.文件操作包括浏览、创建、删除、打开、关闭、阅读、写入、修改模式.其他操作包括新建用户、帮助、用户登入、用户登出、退出系统.在程序文件夹下有个名为“file”的系统根目录,此目录下包括:一个名为“mfd”的文件,记录所有注册过的帐号及密码;用户文件,以用户名作为文件名,内容为其拥有的文件名

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

14、asswordchar,用户密码;userfile结构体用户文件数据结构:unamechar,用户名、ufilefile,用户拥有的文件数组.代码:#include <stdio.h> #include <stdlib.h> #include <conio.h> #include <time.h> #include <string.h> #define maxuser 100 /定义最大mdf主目录文件 #define maxdisk 512*1024 /模拟最大磁盘空间 #define commandamount 12 /对文件操作

15、的指令数 /存储空间管理有关结构体和变量 char diskmaxdisk; /模拟512k的磁盘存储空间 typedef struct disttable /磁盘块结构体 int maxlength; int start; int useflag; disttable *next; disknode; disknode *diskhead; struct filetable /文件块结构体 char filename10; int strat; /文件在磁盘存储空间的起始地址 int length; /文件内容长度 int maxlength; /文件的最大长度 char filekind3

16、; /文件的属性读写方式 struct tm *timeinfo; bool openflag; /判断是否有进程打开了该文件 /filetable *next; ; /两级目录结构体 typedef struct user_file_directory /用户文件目录文件ufd /char filename10; filetable *file; user_file_directory *next; ufd; /ufd *headfile; typedef struct master_file_directory /主文件目录mfd char username10; char passwor

17、d10; ufd *user; mfd; mfd usertablemaxuser; int used=0; /定义mfd目录中用已有的用户数 /文件管理 void filecreate(char filename,int length,char filekind); /创建文件 void filewrite(char filename); /写文件 void filecat(char filename); /读文件 void fileren(char filename,char rename); /重命名文件 void filefine(char filename); /查询文件 void

18、filedir(char username); /显示某一用户的所有文件 void fileclose(char filename); /关闭已打开的文件 void filedel(char filename); /删除文件 void chmod(char filename,char kind); /修改文件的读写方式 int requestdist(int &startpostion,int maxlength); /磁盘分配查询 void initdisk(); /初始化磁盘 void freedisk(int startpostion); /磁盘空间释放 void disksho

19、w(); /显示磁盘使用情况 /用户管理 void usercreate(); int login(); int userid=-1; /用户登录的id号,值为-1时表示没有用户登录 int main() char ordercommandamount10; strcpy(order0,"create"); strcpy(order1,"rm"); strcpy(order2,"cat"); strcpy(order3,"write"); strcpy(order4,"fine"); strcp

20、y(order5,"chmod"); strcpy(order6,"ren"); strcpy(order7,"dir"); strcpy(order8,"close"); strcpy(order9,"return"); strcpy(order10,"exit"); strcpy(order11,"df"); char command50,command_str110,command_str210,command_str35,command_str43

21、; int i,k,j; int length; initdisk(); /初始化磁盘 for(i=0;i<maxuser;i+) /初始化用户ufd目录文件的头指针 usertablei.user=(ufd *)malloc(sizeof(ufd); usertablei.user->next=null; while(1) printf("*n"); printf(" 1、creat usern"); printf(" 2、loginn"); printf("*n"); printf("pl

22、ease chooce the function key:>"); int choice; scanf("%d",&choice); if(choice=1) usercreate(); else if(choice=2) userid=login(); else printf("您的输入有误,请重新选择n"); while(userid!=-1) fflush(stdin); printf("n"); printf(" create-创建 格式:create a1 1000 rw,将创建名为a1,长

23、度为1000字节可读可写的文件n"); printf(" rm-删除 格式:rm a1,将删除名为a1的文件n"); printf(" cat-查看文件内容 格式:cat a1,显示a1的内容n"); printf(" write-写入 格式:write a1n"); printf(" fine-查询 格式:fine a1 ,将显示文件 a1的属性n"); printf(" chmod-修改 格式:chmod a1 r,将文件a1的权限改为只读方式n"); printf("

24、ren-重命名 格式:ren a1 b1 ,将a1改名为b1n"); printf(" dir-显示文件 格式:dir aaa,将显示aaa用户的所有文件n"); printf(" df-显示磁盘空间使用情况 格式:dfn"); printf(" close-关闭文件 格式:close a1,将关闭文件a1n"); printf(" return-退出用户,返回登录界面n"); printf(" exit-退出程序n"); printf("n"); printf(&

25、quot;please imput your command:>"); gets(command); int select; for(i=0;commandi!=' '&&commandi!='0'i+) /command_str1字符串存储命令的操作类型 command_str1i=commandi; k=i; command_str1k='0' for(i=0;i<commandamount;i+) if(!strcmp(command_str1,orderi) select=i; break; if(i

26、=commandamount) printf("您输入的命令有误,请重新输入n"); continue; for(i=k+1,k=0;commandi!=' '&&commandi!='0'i+,k+) /commmand_str2字符串存储文件名或用户名 command_str2k=commandi; command_str2k='0' k=i; switch(select) case 0:for(i=k+1,k=0;commandi!=' 'i+,k+) command_str3k=comm

27、andi; command_str3k='0' k=i; j=1; length=0; /初始化文件长度 for(i=strlen(command_str3)-1;i>=0;i-) /把字符串转换为十进制 length+=(command_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,le

28、ngth,command_str4);break; case 1:filedel(command_str2);break; case 2:filecat(command_str2);break; case 3: filewrite(command_str2);break; case 4:filefine(command_str2);break; case 5:for(i=k+1,k=0;commandi!=' '&&commandi!='0'i+,k+) command_str3k=commandi; command_str3k='0&#

29、39; chmod(command_str2,command_str3);break; case 6:for(i=k+1,k=0;commandi!='0'i+,k+) command_str3k=commandi; command_str3k='0' fileren(command_str2,command_str3);break; case 7:filedir(command_str2);break; case 8:fileclose(command_str2);break; case 9:ufd *p; for(p=usertableuserid.user

30、->next;p!=null;p=p->next) /退出用户之前关闭所有打的文件 if(p->file->openflag) p->file->openflag=false; system("cls"); userid=-1;break; case 10:exit(0);break; case 11:diskshow();break; return 0; void usercreate() char c; char username10; int i; if(used<maxuser) printf("请输入用户名:&q

31、uot;); for(i=0;c=getch();i+) if(c=13) break; else usernamei=c; printf("%c",c); usernamei='0' for(i=0;i<used;i+) if(!strcmp(usertablei.username,username) printf("n"); printf("该用户名已存在,创建用户失败n"); system("pause"); return; strcpy(usertableused.username,u

32、sername); printf("n"); printf("请输入密码:"); for(i=0;c=getch();i+) if(c=13) break; else usertableused.passwordi=c; printf("*"); usertableuserid.passwordi='0' printf("n"); printf("创建用户成功n"); used+; system("pause"); else printf("创建用户

33、失败,用户已达到上限n"); system("pause"); fflush(stdin); int login() char name10,psw10; char c; int i,times; printf("请输入用户名:"); for(i=0;c=getch();i+) if(c=13) break; else namei=c; printf("%c",c); namei='0' for(i=0;i<used;i+) if(!strcmp(usertablei.username,name) br

34、eak; if(i=used) printf("n您输入的用户名不存在n"); system("pause"); return -1; for(times=0;times<3;times+) memset(psw,'0',sizeof(psw); printf("n请输入密码:"); for(i=0;c=getch();i+) if(c=13) break; else pswi=c; printf("*"); printf("n"); for(i=0;i<used;i

35、+) if(!strcmp(psw,usertablei.password) printf("用户登录成功n"); system("pause"); break; if(i=used) printf("您输入的密码错误,您还有%d次输入机会n",2-times); if(times=2) exit(0); else break; fflush(stdin); return i; void initdisk() diskhead=(disknode *)malloc(sizeof(disknode); diskhead->maxl

36、ength=maxdisk; diskhead->useflag=0; diskhead->start=0; diskhead->next=null; int requestdist(int &startpostion,int maxlength) int flag=0; /标记是否分配成功 disknode *p,*q,*temp; p=diskhead; while(p) if(p->useflag=0&&p->maxlength>maxlength) startpostion=p->start; q=(disknode *

37、)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=t

38、emp->next; temp->next=q; break; p=p->next; return flag; void filecreate(char filename,int length,char filekind) /int i,j; time_t rawtime; int startpos; ufd *filenode,*p; for(p=usertableuserid.user->next;p!=null;p=p->next) if(!strcmp(p->file->filename,filename) printf("文件重名,

39、创建文件失败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-&g

40、t;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) usertableuseri

41、d.user->next=filenode; else p=usertableuserid.user->next; while(p->next) p=p->next; p->next=filenode; printf("创建文件成功n"); system("pause"); else printf("磁盘空间已满或所创建文件超出磁盘空闲容量,磁盘空间分配失败n"); system("pause"); void freedisk(int startpostion) disknode *p

42、; for(p=diskhead;p!=null;p=p->next) if(p->start=startpostion) break; p->useflag=false; void filedel(char filename) ufd *p,*q,*temp; q=usertableuserid.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->ope

43、nflag!=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"); void filecat(char file

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论