操作系统课程设计报告-设计、实现一个模拟的文件系统_第1页
操作系统课程设计报告-设计、实现一个模拟的文件系统_第2页
操作系统课程设计报告-设计、实现一个模拟的文件系统_第3页
操作系统课程设计报告-设计、实现一个模拟的文件系统_第4页
操作系统课程设计报告-设计、实现一个模拟的文件系统_第5页
已阅读5页,还剩30页未读 继续免费阅读

下载本文档

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

文档简介

1、文 华 学 院2021 2021 学年度第 2 学期?操作系统课程设计?考查试卷A卷课程性质:必修 使用范围:本科考查时间:2021年3月2 日 考查方式: 开卷考试类型论文大作业调研报告其它总分课程设计阅卷老师签名试 题:要 求: 独立完成,3000-8000字不含附件。目录一、课程设计任务及要求.3 1.1设计任务.3 1.2设计要求.3二、算法及数据结构.3 2.1主要数据结构.3 2.2用户管理模块.5 2.2.1初始化用户函数.52系统用户的输出函数.62.2.3用户的查找函数.6 2.3创立文件函数.6 2.4删除文件函数.8 2.5翻开文件函数.9 3.6读文件函数.11 3.7

2、写文件函数.11 3.8关闭文件函数.12 3.9显示文件函数.13 3.9.1显示用户文件.13显示已翻开的文件.13三、程序设计与实现.18 4.1 程序流程图.18 4.2 程序说明.18 4.3 实验结果.19四、参考文献.21六、收获、体会和建议.22 七、附录源程序清单.23 一、课程设计任务及要求1.1 设计任务设计、实现一个模拟的文件系统1.2 设计要求建立文件存储介质的管理机制建立目录采用一级目录结构文件系统功能显示目录、创立、删除、翻开、关闭、读、写文件操作接口显示目录、创立、删除、翻开、关闭、读、写独立完成课程设计内容文本的课程设计报告,内容包括调试记录和程序清单(附注释

3、)。二、算法及数据结构/* *定义文件数据结构 */ typedef struct file char file_name20 ; bool file_protect3 ; bool open_file_protect3 ; /仅在文件翻开时有效 int read , write ; /定义为读写指针 int file_length ; struct file *next ; File ; /* *用户与文件的映射 */ typedef struct x_map char userName20 ; File *file ; struct x_map *next ; Map ; /* *定义主文

4、件目录 */ typedef struct mfd Map *head , *tail ; MFD ; /* *翻开文件目录 */ typedef struct afd File *head , *tail ; int max_open ; int current_open ; AFD ; 主文件目录MFD和用户文件目录UFD翻开文件目录AFD2.2.1初始化用户函数 void initUser(MFD *mfd) /初始化两个不同用户 for(int i = 1 ; i = 2 ; i+) Map *m ; m = (Map*)malloc(sizeof(Map) ; if(m = NULL

5、) exit(0) ; coutm-userName ; m-file = NULL ; m-next = NULL ; if(mfd-head = NULL) mfd-head = mfd-tail = m ; else mfd-tail-next = m ; mfd-tail = m ; 初始化两个不同用户,把输入用户的用户名下的目录指针、文件指针初始化void displayUser(MFD *mfd) Map *m = NULL ; m = mfd-head; coutuser : ;while(m) coutuserNamenext ; couthead ; while(m) if(

6、strcmp(userName , m-userName) = 0) return m ; m = m-next ; return NULL ; 进行用户的查找,找到那么返回用户映射指针bool createFile(Map *user , char file_name , bool file_protect3 , int file_length) File *file ; file = (File*)malloc(sizeof(File) ; if(file = NULL) return false ; /进行文件的初始化 strcpy(file-file_name , file_name)

7、 ; file-file_protect0 = file_protect0 ; file-file_protect1 = file_protect1 ; file-file_protect2 = file_protect2 ; file-file_length = file_length ; file-read = file-write = 0 ; file-next = NULL ; if(user-file = NULL) user-file = file ; else File *op , *preOp = NULL ; op = user-file ; /查找是否存在同名文件 whil

8、e(op) if(strcmp(op-file_name , file-file_name) = 0) coutThe file name file_name is already exit ! next ; preOp-next = file ; 输入文件名,文件权限及文件长度,将文件的名称、读写权限、长度等进行初始化,然后查找是否存在同名文件,存在同名文件时那么输出该文件已存在并报错bool deleteFile(Map *user , char file_name , AFD *afd) File *file = NULL , *prefile = NULL , *temp ; file

9、 = afd-head ; /在翻开文件中查找 while(file) if(strcmp(file_name , file-file_name) = 0) coutfile_namenext ; file = user-file ; /在文件中进行查找 while(file) if(strcmp(file_name , file-file_name) = 0) if(file = user-file) temp = file ; user-file = file-next ; else temp = file ; prefile-next = file-next ; delete temp

10、; return true ; prefile = file ; file = file-next ; if(prefile-next = NULL) coutuser userName has not the file file_namefile ; while(file) if(strcmp(file-file_name , file_name) = 0) break ; file = file-next ; if(file) File *xfile ; xfile = (File*)malloc(sizeof(File) ; if(xfile = NULL) return false ;

11、 *xfile = *file ; /根据文件的权限进行翻开权限的赋值 if(xfile-file_protect0 = open_file_protect0) xfile-open_file_protect0 = open_file_protect0 ; else coutno read priority ! file_protect1 = open_file_protect1) xfile-open_file_protect1 = open_file_protect1 ; else coutno write priority ! file_protect2 = open_file_prot

12、ect2) xfile-open_file_protect2 = open_file_protect2 ; else coutno excute priority ! next = NULL ; if(afd-head = NULL) afd-head = afd-tail = xfile ; afd-current_open += 1 ; else if(afd-current_open max_open) afd-tail-next = xfile ; afd-tail = xfile ; afd-current_open += 1 ; else coutThe open file is

13、too many ! endl ; return false ; else coutthe file_name is not exit !head ; while(file) if(strcmp(file-file_name , file_name) = 0) if(file-open_file_protect0) file-read+ ; return true ; Else coutno read priority ! nnext ; coutno such file ! head ; while(file) if(strcmp(file-file_name , file_name) =

14、0) if(file-open_file_protect1) file-write+ ; return true ; else coutno write priority ! nnext ; coutno such file ! head ; while(file) if(strcmp(file-file_name , file_name) = 0) if(file = afd-head) if(file = afd-tail) temp = file ; afd-head = afd-tail = NULL ; else temp = file ; afd-head = file-next

15、; else if(file = afd-tail) temp = file ; preFile-next = NULL ; afd-tail = preFile ; else temp =file ; preFile-next = file-next ; delete temp ; return true ; preFile = file ; file = file-next ; coutThe file is not exit ! endl ; return false ; 输入要关闭的文件名,在翻开文件链表中查找该文件是否存在,假设没有那么输出提示该文件不存在并报错,假设存在那么继续运行

16、,进行删除操作。void displayUserFile(Map *user) coutThe fileList of userNamefile ; while(file) coutfile_name file_protect0 file_protect1 file_protect2 file_lengthnext ; 输出该用户下的文件链表,并输出对应文件的读、写、执行的权限信息和文件长度信息void displayOpenFile(AFD *afd , Map *user) coutThe open file of userName : head ; while(file) coutfil

17、e_name file_protect0 file_protect1 file_protect2 file_length ; coutreadcout : read writecout : writenext ; 输出该用户下的翻开文件链表、对应文件的读、写、执行的权限信息及文件长度信息和该文件的读、写信息4. 程序设计与实现4.1 程序流程图用户登陆开始初始化用户目录界面分析命令创立文件删除文件翻开文件读文件写文件关闭文件退出系统结束4.2 程序说明该程序是在虚拟机中的Linux系统下的C+程序,用系统自带的编译软件编译,在控制台上编译、调试运行通过。4.3 实验结果在控制台上编译运行程序,

18、输入初始化的两个用户名,选择一个用户名进入目录界面,输入命令。输入命令create创立文件,输出提示文件名、文件权限、文件长度,输入相应的文件信息,创立成功那么输出当前用户的文件链表 。输入命令delete删除文件,输出提示please input the files name you want to delete:,输入要删除的文件名,删除成功那么输出当前用户的文件链表。输入命令open翻开文件,输出提示“please input the files name you want to open :输入要翻开的文件名和相应的权限,翻开文件成功那么输出当前用户的翻开文件链表。输入命令read读文

19、件,输出提示“please input the files name you want to read:,输入要读的文件名,读成功那么读指针加一并输出当用户的翻开文件链表。输入命令write写文件,输出提示“please input the files name you want to write:,输入要写的文件名,写成功那么写文件指针加一并输出当前用户的翻开文件链表。输入命令close关闭文件,输出提示“please input the files name you want to close:,输入要关闭的文件名,关闭成功那么输出当前用户的翻开文件链表。参考文献计算机操作系统实验指导Li

20、nux版郑然、庞丽萍著。人民邮电出版社2021计算机操作系统第2版庞丽萍、阳富民著。人民邮电出版社2021收获、体会和建议本次课程设计是一次将书本知识应用到实践考验。经过此次设计,将课本和课堂所学的一些知识运用到程序中还是需要一定的努力,自学一些相关的知识。在课程设计过程中,我学到了很多人生的哲理,懂得怎么样去制定方案,怎么样去实现这个方案,并掌握了在执行过程中怎么样去克服心理上的不良情绪,提高了自己解决问题的能力,知道了应该耐心的去解决程序中的问题和缺乏。遇到问题时,应该认真去查阅资料,学习不懂的知识。通过课程设计,对自己学习Linux操作系统有用的软件及对操作系统中文件管理系统的了解,更深

21、一步掌握了操作系统的一些概念。在设计的过程中遇到问题,可以说得是困难重重,难免会遇到过各种各样的问题,同时在设计的过程中发现了自己的缺乏之处,对以前所学过的知识理解得不够深刻,掌握得不够牢固,通过在网上查询资料以及参考书本上的列题等,完成了此次课程设计。附录源程序清单/*模拟文件管理*/#include#include#include#include using namespace std ;/*定义文件数据结构*/typedef struct file char file_name20 ; bool file_protect3 ; bool open_file_protect3 ; /仅在文

22、件翻开时有效 int read , write ; /定义为读写指针 int file_length ; struct file *next ; File ;/*用户与文件的映射*/typedef struct x_map char userName20 ; File *file ; struct x_map *next ; Map ;/*定义主文件目录*/typedef struct mfd Map *head , *tail ; MFD ;/*翻开文件目录*/typedef struct afdFile *head , *tail ;int max_open ;int current_op

23、en ; AFD ;/*进行用户的初始化*/void initUser(MFD *mfd) ;/*进行系统用户的输出*/void displayUser(MFD *mfd) ;/*进行用户的查找,找到那么返回用户映射指针*/Map * queryUser(char userName , MFD *mfd) ;/*进行文件的创立操作*成功那么返回true , 否那么返回false*/bool createFile(Map *user , char file_name , bool file_protect3 , int file_length) ;/*进行文件删除操作*/bool deleteF

24、ile(Map *user , char file_name , AFD *afd) ;/*进行文件翻开操作*/bool openFile(Map *user , char file_name , AFD *afd , bool open_file_protect) ;/*进行读操作*/bool readFile(AFD *afd , char file_name) ;/*进行文件的写操作*/bool writeFile(AFD *afd , char file_name) ;/*关闭文件*/bool closeFile(AFD *afd , char file_name) ;/*进行用户文件

25、的显示*/void displayUserFile(Map *user) ;/*显示翻开的文件*/void displayOpenFile(AFD *afd , Map *user) ;/*测试主函数*/int main() MFD *mfd ; mfd = (MFD*)malloc(sizeof(MFD) ; if(mfd = NULL) exit(0) ; mfd-head = mfd-tail = NULL ; initUser(mfd) ; displayUser(mfd) ; char userName20 ; while(true) coutuserName ; Map *user

26、 ; user = queryUser(userName , mfd) ; if(user = NULL) coutNo such user ! endl; else /为用户初始化翻开文件目录 AFD *afd ; afd = (AFD*)malloc(sizeof(AFD) ; if(afd = NULL) coutThe memory is not enough ! head = afd-tail = NULL ; afd-max_open = 5 ; afd-current_open = 0 ; char command20 ; char file_name20 ; bool file

27、_protect3 ; bool open_file_protect3 ; int file_length ; cout*endl; /cout0.初始化-endl; cout1.创立文件-createendl; cout2.删除文件-deleteendl; cout3.翻开文件-openendl; cout4.读文件-readendl; cout5.写文件-writeendl; cout6.关闭文件-closeendl; coutendl; coutendl; coutendl; coutendl; coutendl; coutendl; while(true) coutuserName ;

28、 cincommand ; /输入命令进行操作 if(strcmp(command , create) = 0) coutfile_namefile_protect0file_protect1file_protect2file_length ; createFile(user , file_name , file_protect , file_length) ; displayUserFile(user) ; else if(strcmp(command , delete) = 0) coutfile_name ; deleteFile(user , file_name , afd) ; di

29、splayUserFile(user) ; else if(strcmp(command , open) = 0) coutfile_nameopen_file_protect0open_file_protect1open_file_protect2 ; openFile(user , file_name , afd , open_file_protect) ; displayOpenFile(afd , user) ; else if(strcmp(command , close) = 0) coutfile_name ; closeFile(afd , file_name) ; displ

30、ayOpenFile(afd , user) ; else if(strcmp(command , read) = 0) coutfile_name ; readFile(afd , file_name) ; displayOpenFile(afd , user) ; else if(strcmp(command , write) = 0) coutfile_name ; writeFile(afd , file_name) ; displayOpenFile(afd , user) ; else if(strcmp(command , exit) = 0) break ; else cout

31、No such command command endl ; return 0 ;void initUser(MFD *mfd) /初始化2个不同用户 for(int i = 1 ; i = 2 ; i+) / Map *m ; m = (Map*)malloc(sizeof(Map) ; if(m = NULL) exit(0) ; coutm-userName ; m-file = NULL ; m-next = NULL ; if(mfd-head = NULL) mfd-head = mfd-tail = m ; else mfd-tail-next = m ; mfd-tail =

32、m ; void displayUser(MFD *mfd) Map *m = NULL ; m = mfd-head; coutuser : ; while(m) coutuserNamenext ; couthead ; while(m) if(strcmp(userName , m-userName) = 0) return m ; m = m-next ; return NULL ;bool createFile(Map *user , char file_name , bool file_protect3 , int file_length) File *file ; file =

33、(File*)malloc(sizeof(File) ; if(file = NULL) return false ; /进行文件的初始化 strcpy(file-file_name , file_name) ; file-file_protect0 = file_protect0 ; file-file_protect1 = file_protect1 ; file-file_protect2 = file_protect2 ; file-file_length = file_length ; file-read = file-write = 0 ; file-next = NULL ; i

34、f(user-file = NULL) user-file = file ; else File *op , *preOp = NULL ; op = user-file ; /查找是否存在同名文件 while(op) if(strcmp(op-file_name , file-file_name) = 0) coutThe file name file_name is already exit ! next ; preOp-next = file ; void displayUserFile(Map *user) coutThe fileList of userNamefile ; whil

35、e(file) coutfile_name file_protect0 file_protect1 file_protect2 file_lengthnext ; bool deleteFile(Map *user , char file_name , AFD *afd)File *file = NULL , *prefile = NULL , *temp ;file = afd-head ;/在翻开文件中查找while(file) if(strcmp(file_name , file-file_name) = 0) coutfile_namenext ;file = user-file ;/

36、在文件中进行查找while(file) if(strcmp(file_name , file-file_name) = 0) if(file = user-file) temp = file ; user-file = file-next ; else temp = file ; prefile-next = file-next ; delete temp ; return true ; prefile = file ; file = file-next ;if(prefile-next = NULL) coutuser userName has not the file file_namef

37、ile ;while(file) if(strcmp(file-file_name , file_name) = 0) break ; file = file-next ;if(file) File *xfile ; xfile = (File*)malloc(sizeof(File) ; if(xfile = NULL) return false ; *xfile = *file ; /根据文件的权限进行翻开权限的赋值 if(xfile-file_protect0 = open_file_protect0) xfile-open_file_protect0 = open_file_protect0 ; else coutno read priority ! file_protect1 = open_file_protect1) xfile-open_file_protect1 = open_file_protect1 ; else coutno write priority ! file_protect2 = open_file_protect2) xfile-open_file_protect2 = open_file_protect2 ; else coutno excute priority ! n

温馨提示

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

评论

0/150

提交评论