ImageVerifierCode 换一换
格式:DOCX , 页数:28 ,大小:20.80KB ,
资源ID:13794002      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-13794002.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(操作系统课程设计模拟一个简单二级文件管理系统.docx)为本站会员(b****1)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

操作系统课程设计模拟一个简单二级文件管理系统.docx

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

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

3、的文件,内容为文件内容.2 数据结构file结构体系统文件数据结构:fpaddrint,文件的物理地址、flengthint,文件长度、fmodeint,文件模式 0.只读;1.可写;2.可读写;3.保护、 fnamechar,文件名;filemode结构体文件状态数据结构:isopenint,文件当前状态,0.关闭;1.打开、modeint,文件模式 0.只读;1.可写;2.可读写;3.初始化;user结构体用户信息数据结构:unamechar,用户名、upasswordchar,用户密码;userfile结构体用户文件数据结构:unamechar,用户名、ufilefile,用户拥有的文件

4、数组.代码:#include #include #include #include #include #define MaxUser 100 /定义最大MDF主目录文件 #define MaxDisk 512*1024 /模拟最大磁盘空间 #define commandAmount 12 /对文件操作的指令数 /存储空间管理有关结构体和变量 char diskMaxDisk; /模拟512K的磁盘存储空间 typedef struct distTable /磁盘块结构体 int maxlength; int start; int useFlag; distTable *next; diskNo

5、de; diskNode *diskHead; struct fileTable /文件块结构体 char fileName10; int strat; /文件在磁盘存储空间的起始地址 int length; /文件内容长度 int maxlength; /文件的最大长度 char fileKind3; /文件的属性读写方式 struct tm *timeinfo; bool openFlag; /判断是否有进程打开了该文件 /fileTable *next; ; /两级目录结构体 typedef struct user_file_directory /用户文件目录文件UFD /char fi

6、leName10; fileTable *file; user_file_directory *next; UFD; /UFD *headFile; typedef struct master_file_directory /主文件目录MFD char userName10; char password10; UFD *user; MFD; MFD userTableMaxUser; int used=0; /定义MFD目录中用已有的用户数 /文件管理 void fileCreate(char fileName,int length,char fileKind); /创建文件 void fil

7、eWrite(char fileName); /写文件 void fileCat(char fileName); /读文件 void fileRen(char fileName,char rename); /重命名文件 void fileFine(char fileName); /查询文件 void fileDir(char UserName); /显示某一用户的所有文件 void fileClose(char fileName); /关闭已打开的文件 void fileDel(char fileName); /删除文件 void chmod(char fileName,char kind);

8、 /修改文件的读写方式 int requestDist(int &startPostion,int maxLength); /磁盘分配查询 void initDisk(); /初始化磁盘 void freeDisk(int startPostion); /磁盘空间释放 void diskShow(); /显示磁盘使用情况 /用户管理 void userCreate(); int login(); int userID=-1; /用户登录的ID号,值为-1时表示没有用户登录 int main() char ordercommandAmount10; strcpy(order0,create);

9、strcpy(order1,rm); strcpy(order2,cat); strcpy(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); char command50,command_str110,command_str210,command_str35,command_st

10、r43; int i,k,j; int length; initDisk(); /初始化磁盘 for(i=0;inext=NULL; while(1) printf(*n); printf( 1、Creat usern); printf( 2、loginn); printf(*n); printf(Please chooce the function key:); int choice; scanf(%d,&choice); if(choice=1) userCreate(); else if(choice=2) userID=login(); else printf(您的输入有误,请重新选择

11、n); while(userID!=-1) fflush(stdin); printf(n); printf( create-创建 格式:create a1 1000 rw,将创建名为a1,长度为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,将文

12、件a1的权限改为只读方式n); printf( 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(please imput your command:); gets(command); int select;

13、 for(i=0;commandi!= &commandi!=0;i+) /command_str1字符串存储命令的操作类型 command_str1i=commandi; k=i; command_str1k=0; for(i=0;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,length,command_s

14、tr4);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; chmod(command_str2,command_str3);break; case 6:

15、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-next;p!=NULL;p=p-next) /退出用户之前关闭所有打的文件 if(p-file-openFlag) p-file-op

16、enFlag=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(usedMaxUser) printf(请输入用户名:); for(i=0;c=getch();i+) if(c=13) break; else userNamei=c; printf(%c,c); userNamei=0; for(i=0;iused;i+) if(!strcmp(us

17、erTablei.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; else userTableused.passwordi=c; printf(*); userTableuserID.passwordi=0; printf(n); printf(创建用户成功n); used+;

18、system(pause); else printf(创建用户失败,用户已达到上限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;iused;i+) if(!strcmp(userTablei.userName,name) break; if(i=used) printf(n

19、您输入的用户名不存在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; else pswi=c; printf(*); printf(n); for(i=0;imaxlength=MaxDisk; diskHead-useFlag=0; diskHead-start=0; diskHead-next=NULL; int requestDist(int &startPosti

20、on,int maxLength) int flag=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=

21、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; 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

22、-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

23、-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(userTableuserID.user-next=NULL) userTableuserID.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; for(p=diskHead;p!=

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2