版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、中北大学操作系统课程设计说 明 书学 院、系:软件学院专 业:软件工程学 生 姓 名:学 号:0921010414设 计 题 目:基于linux的模拟文件系统的设计与实现 起 迄 日 期: 2011年12月22日- 2012年1月7日指 导 教 师:2012 年 1月 7 日1 需求分析 所要实现的功能: (1) 设计一个10个用户的文件系统。每个用户最多可以保存10个文件,一次运行用户可打开多个文件。(2) 程序采用二级文件目录。(即设置主目录(mfd)和用户文件目录(ufd)。另外,可打开文件设置指针。(3) 为了方便实现,对文件的读写作了简化。在执行读写命令时,只需改读写指针。并不进行实
2、际的读写操作。(4) 实现的基本功能主要包括:改变目录(cd),创建目录(md),显示目录(dir),删除目录(rd),打开全部文件(openall),打开单个文件(open),建立一个文件(create),删除一个文件(delete),写文件(write),读文件(read),改文件的保护码(change),退出(exit)等。考虑特殊情况如:各个命令对全路径和相对路径的支持、目录不存在时,给出错误信息、不能用cd进入文件、命令之中不能有空格(如 ex it,给出错误提示)、相对路径的解析、路径中的空格剔除、新建目录或文件时的问题、重名问题、目录或文件的名字长度限制、目录或文件的名字中包含不
3、合法字符(注意空格)、删除目录或文件时的问题、删除不存在的文件或目录给出错误提示、删除目录时目录不为空(如果该目录为空,则可删除,否则给出是否做删除提示,删除操作将该目录下的全部文件和子目录都删除)、进入到某个目录下,却要删除本目录或上级目录、不能用delete删除目录、不能用rd删除文件等都要考虑在内。最终获得的成果就是:在系统中用一个文件来模拟一个磁盘;此系统至少有:create、delete、open、close、read、write等和部分文件属性的功能。实现这个文件系统。能实际演示这个文件系统。基本上是进入一个界面(此界面就是该文件系统的界面)后,可以实现设计的操作要求。2 总体设计
4、 2.1系统活动图 用户管理系统文件目录管理系统新建目录删除目录进入目录打开文件路径控制登陆退出 目录内文件管理系统新建文件读文件写文件 删除 移动登陆退出 注册 登陆 退出 2.2 头文件:#include #include #include 2.3结构体:typedef struct file char name10; struct file *next;file *fp;file;typedef struct contentchar name10;file *filehead;int f_num;struct content *next;content;typedef struct us
5、er char name10; char psw10; content *conhead;int c_num; struct user *next;user;2.4 全局变量和函数:void registe()int login()void menuuser()void foldercreate()void folderdelete()void folderviewallfiles()void folderintofolder()void menufolder()void filecreate()void fileread()void filewrite()void filedelete()v
6、oid filemove()3 详细设计用户管理系统:registe():用户注册login():用户登录目录管理系统:foldercreate():新建目录folderdelete():删除目录folderintofolder():进入目录folderviewallfiles():显示所有目录内的所有文件absolutepathfilecontroller():通过绝对路径直接读文件文件管理系统:filecreate():新建文件filedelete():删除文件filemove():跨目录移动文件fileread():读文件filewrite():写文件3.1 用户管理系统: 截图3-1相
7、关核心代码:/step0void registe()if(user_num=10)printf(has 10 users.you have no access to registern);return;/allocate new memory block for new useruser *add,*last;add=(user *)malloc(sizeof(user);add-next=null;if(user_head=null)user_head=add;elselast=user_head;while(last-next!=null)last=last-next;last-next=
8、add;user_num+;/fulfill the new userchar name10,psw10;user *check;char buffer2;fgets(buffer,2,stdin);unr:printf(now create a new user:nuser name(9,only alphabet and number can be used):n);scanf(%s,name);check=user_head;while(check!=add)if(strcmp(name,check-name)=0)printf(username exist.please re-inpu
9、t:n);goto unr;check=check-next;strcpy(add-name,name);fgets(buffer,2,stdin);printf(password(10):n);fgets(psw,10,stdin);strcpy(add-psw,psw);add-conhead=null;add-c_num=0;/successprintf(successn);return;/step0int login()if(user_head=null)printf(system has no usern);return 0;char buffer2;fgets(buffer,2,s
10、tdin);char name10,psw10;user *check;printf(press # if you wanna quitn);unl:printf(username:n);scanf(%s,name);if(name0=#)return 0;check=user_head;while(check!=null)if(!strcmp(check-name,name)break;elsecheck=check-next;if(check=null)printf(no such user.nplease re-input:n);goto unl;/match passwordfgets
11、(buffer,2,stdin);printf(password:n);fgets(psw,11,stdin);if(strcmp(psw,check-psw)!=0)printf(wrong passwordn);goto unl;printf(nn*welcome back!%s*nn,check-name);cur_user=check;return 1;void main(int argc, char* argv)user_num=0;user_head=null;cur_user=null;int choice;for(;)printf(*main menu*n);printf(1.
12、 new usern);printf(2. loginn);printf(0. exitn);printf(*n);printf(%d user existn,user_num);printf(input your choice:);scanf(%d,&choice);switch(choice)case 1:registe();continue;case 2:if(login()menuuser();continue;case 0:printf(thanks for usingn);exit(0);default:printf(wrong input!n);3.2 目录管理系统: 截图3-2
13、相关核心代码:/step0-1void menuuser()void foldercreate();void folderdelete();void folderviewallfiles();void folderintofolder();void absolutepathfilecontroller();user *current;content *gothrough;current=cur_user;gothrough=current-conhead;for(;)printf(*%ss content*n,cur_user-name);printf(1.create a foldern);
14、printf(2.get in to a foldern);printf(3.delete a foldern);printf(4.view all filesn);printf(5.read a file directly by absolute pathn);printf(6.log outn);printf(0.shut down file_systemn);printf(view all your folders below:%d folders totaln,current-c_num);if(current-conhead=null)printf(|nno folder.n);el
15、segothrough=current-conhead;while(gothrough!=null)printf(|n%sn,gothrough-name);gothrough=gothrough-next;printf(*);printf(ninput your choice:n);int choice;scanf(%d,&choice);switch(choice)case 1:foldercreate();continue;case 2:folderintofolder();continue;case 3:folderdelete();continue;case 4:folderview
16、allfiles();continue;case 5:absolutepathfilecontroller();continue;case 6:printf(nthanks for usingnn);return;case 0:printf(nthanks for usingn);cur_user=null;cur_con=null;exit(0);default:printf(wrong input!n);/step1void foldercreate()user *user;user=cur_user;/allocate new memory block for new foldercon
17、tent *add,*last;add=(content *)malloc(sizeof(content);add-next=null;if(user-conhead=null)user-conhead=add;elselast=user-conhead;while(last-next!=null)last=last-next;last-next=add;user-c_num+;add-filehead=null;add-f_num=0;/fulfill the new folder namechar name10;content *check;char buffer2;fgets(buffe
18、r,2,stdin);con_r:printf(now create a new folder:nfolder name(9,only alphabet and number can be used):n);scanf(%s,name);check=user-conhead;while(check!=add)if(strcmp(name,check-name)=0)printf(folder name exist.please re-input:n);goto con_r;check=check-next;/check legality of the nameint i=0;for(;i=97
19、&namei=48&namei=65&namei=90)/uppercontinue;elseif(namei=0)break;elseprintf(is a illegal input!nplease re-input:n,namei);goto con_r;strcpy(add-name,name);printf(donenn);return;/step1void folderdelete()if(cur_user-conhead=null)printf(no foldernn);return;content *front,*current;char name10;printf(press
20、 # if you wanna quitn);con_d:printf(folder name:n);scanf(%s,name);if(name0=#)return;/seek folder namecurrent=cur_user-conhead;while(current!=null)if(!strcmp(current-name,name)break;elsecurrent=current-next;if(current=null)printf(no such folder.nplease re-input:n);goto con_d;/if has any fileswhile(cu
21、rrent-filehead!=null)char buffer2;fgets(buffer,2,stdin);printf(folder not empty!if you sure you wanna delete?(y/n)n);char judge;scanf(%c,&judge);if(judge=n|judge=y|judge=n|judge=y)if(judge=n|judge=n)return;elsebreak;elseprintf(please input y or nn);continue;/user recognisechar psw10;printf(input you
22、r user password to recognise:);char buffer2;fgets(buffer,2,stdin);fgets(psw,10,stdin);if(strcmp(cur_user-psw,psw)!=0)printf(wrong password!ndelete function failledn);return;/execute delete operationfront=cur_user-conhead;if(front=current)/if curren is the head filecur_user-conhead=current-next;free(
23、current);printf(has been deletedn1n);return;while(front-next!=current)front=front-next;front-next=current-next;free(current);cur_user-c_num-;printf(has been deletedn2n);return;/step1void folderviewallfiles()printf(nscan all your file:n);content *con;con=cur_user-conhead;int fi_num=0;while(con!=null)
24、printf(|%s-n,con-name);file *fi;fi=con-filehead;while(fi!=null)printf(|%sn,fi-name);printf(|n);fi=fi-next;fi_num+=con-f_num;con=con-next;printf(total:%d folders,%d filesnn,cur_user-c_num,fi_num);return;/step1void folderintofolder()void menufolder();if(cur_user-conhead=null)printf(you has no foldern)
25、;return;printf(now get into a folder:nfolder name(9):n);char name10;char buffer2;fgets(buffer,2,stdin);content *check;printf(type # if you wanna quitn);con_g:printf(folder name:ncd );scanf(%s,name);if(name0=#)return;check=cur_user-conhead;while(check!=null)if(!strcmp(check-name,name)break;elsecheck=
26、check-next;if(check=null)printf(no such folder.nplease re-input:n);goto con_g;/successcur_con=check;menufolder();return;/step void absolutepathfilecontroller()printf(n_n);printf(format:/n);printf(_n);char name28;printf(press # if you wanna quitn);absolute:printf(absolute file path:n);scanf(%s,name);
27、if(name0=#)return;char folder_name10;char file_name14;/analyse the absolute path/get folder nameif(name0=/)printf(no folder name!please re-input:n);goto absolute;int i=0,j=0;while(namei!=/&i=9)if(namei=0)printf(wrong formatn);goto absolute;folder_namei=namei;i+;folder_namei=0;i+;/get file nameif(nam
28、ei=0)printf(no ,please re-inputn);goto absolute;while(namei+j!=0&jconhead;while(folder_checker!=null)if(!strcmp(folder_checker-name,folder_name)break;elsefolder_checker=folder_checker-next;if(folder_checker=null)printf(no such folder.nplease re-input:n);goto absolute;/seek filefile *file_checker;fil
29、e_checker=folder_checker-filehead;while(file_checker!=null)if(!strcmp(file_checker-name,file_name)break;elsefile_checker=file_checker-next;if(file_checker=null)printf(no such file.nplease re-input:n);goto absolute;/read the filechar fullname20=pro/;strcat(fullname,file_name);printf(=ndetails:nn);fil
30、e_checker-fp=fopen(fullname,r);char ch;while(ch!=eof)putchar(ch=getc(file_checker-fp);printf(n=n);fclose(file_checker-fp);return;3.2 文件管理系统: 截图3-3相关核心代码:/step1-2void menufolder()void filecreate();void fileread();void filewrite();void filedelete();void filemove();file *gothrough;content *current;curr
31、ent=cur_con;gothrough=current-filehead;char buffer2;int choice;for(;)fgets(buffer,2,stdin);printf(nfolder:%sn,current-name);printf(1.create a new filen);printf(2.read a filen);printf(3.write to a filen);printf(4.delete a filen);printf(5.move a filen);printf(6.back to user-menun);printf(0.shut down f
32、ile_systemnn);printf(view all your files below:%d files totaln,current-f_num);if(current-filehead=null)printf(|nno file.n);elsegothrough=current-filehead;while(gothrough!=null)printf(|n%sn,gothrough-name);gothrough=gothrough-next;printf();printf(ninput your choice:n);choice=-1;scanf(%d,&choice);swit
33、ch(choice)case 1:filecreate();continue;case 2:fileread();continue;case 3:filewrite();continue;case 4:filedelete();continue;case 5:filemove();continue;case 6:printf(nnow in your ufd:nn);cur_con=null;return;case 0:printf(nthanks for usingn);cur_user=null;cur_con=null;exit(0);default:printf(wrong input
34、!n);/step2void filecreate()content *cur_content;cur_content=cur_con;/allocate new memory block for new files indexfile *add,*last;add=(file *)malloc(sizeof(file);add-next=null;add-fp=null;if(cur_content-filehead=null)cur_content-filehead=add;elselast=cur_content-filehead;while(last-next!=null)last=l
35、ast-next;last-next=add;cur_content-f_num+;/fulfill the new folder namechar name10;file *check;char buffer2;fgets(buffer,2,stdin);file_r:printf(now create a new file:nfile name(9,only alphabet and number can be used):n);scanf(%s,name);check=cur_content-filehead;while(check!=add)if(strcmp(name,check-n
36、ame)=0)printf(file name exist.please re-input:n);goto file_r;check=check-next;/check legality of the nameint i=0;for(;i=97&namei=48&namei=65&namei=90)/uppercontinue;elseif(namei=0)break;elseprintf(is a illegal input!nplease re-input:n,namei);goto file_r;strcpy(add-name,name);char fullname20=pro/;str
37、cat(fullname,name);add-fp=fopen(fullname,w);if(add-fp=null)printf(error when create a file in desknpease contact system managern);goto file_r;fclose(add-fp);printf(donenn);return;/step2void fileread()if(cur_con-filehead=null)printf(no filenn);return;printf(nnow read a file:n);file *current;char name
38、10;printf(press # if you wanna quitn);file_r:printf(file name:n);scanf(%s,name);if(name0=#)return;/seek file namecurrent=cur_con-filehead;while(current!=null)if(!strcmp(current-name,name)break;elsecurrent=current-next;if(current=null)printf(no such file.nplease re-input:n);goto file_r;char fullname2
39、0=pro/;strcat(fullname,name);printf(=ndetails:nn);current-fp=fopen(fullname,r);char ch;while(ch!=eof)putchar(ch=getc(current-fp);printf(n=n);fclose(current-fp);return;/step2void filewrite()if(cur_con-filehead=null)printf(no filenn);return;printf(nnow read a file:n);file *current;char name10;printf(p
40、ress # if you wanna quitn);file_r:printf(file name:n);scanf(%s,name);if(name0=#)return;/seek file namecurrent=cur_con-filehead;while(current!=null)if(!strcmp(current-name,name)break;elsecurrent=current-next;if(current=null)printf(no such file.nplease re-input:n);goto file_r;char fullname20=pro/;strc
41、at(fullname,name);printf(=ntype details:(tpye in # to finish the text)nn);current-fp=fopen(fullname,a+);char ch;ch=getchar();while(ch!=#)putc(ch,current-fp);ch=getchar();fclose(current-fp);printf(=);return;/step2void filedelete()if(cur_con-filehead=null)printf(no filenn);return;file *front,*current;
42、char name10;printf(press # if you wanna quitn);file_d:printf(file name:n);scanf(%s,name);if(name0=#)return;/seek file namecurrent=cur_con-filehead;while(current!=null)if(!strcmp(current-name,name)break;elsecurrent=current-next;if(current=null)printf(no such file.nplease re-input:n);goto file_d;/exec
43、ute delete operationfront=cur_con-filehead;if(front=current)/if curren is the head filecur_con-filehead=current-next;free(current);printf(has been deletedn1n);return;while(front-next!=current)front=front-next;front-next=current-next;free(current);cur_con-f_num-;printf(has been deletedn2n);return;/st
44、ep2void filemove()printf(n=nnow move a file from folder %s to another foldern=n,cur_con-name);/move indexcontent *target_con,*current_con;if(cur_con-filehead=null)printf(no filenn);return;file *front_f,*current_f,*tar_f;char name10;printf(press # if you wanna quitn);file_m:printf(file name:n);scanf(%s,name);if(name0=#)return;/seek file namecurrent_f=cur_con-filehead;while(current_f!=null)if(!strcmp(current_f-name,name)break;elsecurrent_f=current_f-next;if(current_f=null)printf(no such file.nplease re-input:n);goto file_m;/get target folder valuec
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 住宅小区外墙改造协议
- 矿泉水厂保温系统安装协议
- 网络短视频副导演招聘协议
- 装饰装修劳务协议
- 市场调研门头租赁合同
- 污水处理工程劳务合同模板
- 创业学校租赁合同
- 花艺作品销售顾问聘用协议
- 建筑工程施工合同:生态保护工程
- 花园租赁协议模板
- 艾灸基础理论知识单选题100道及答案解析
- 晨会安全讲话稿范文大全集
- 汽车美容装潢技术电子教案 2.2-汽车内部清洗护理
- 2023年中国铁塔招聘笔试真题
- 江苏省苏州市2024-2025学年高一上学期11月期中英语试题(无答案)
- DB11∕T 2103.4-2023 社会单位和重点场所消防安全管理规范 第4部分:大型商业综合体
- 职业教育国家在线课程申报书
- 2025届高考语文复习:小说情节概括+课件
- DL-T5434-2021电力建设工程监理规范
- (高清版)TDT 1055-2019 第三次全国国土调查技术规程
- 天堂旅行团读书分享
评论
0/150
提交评论