基于Linux的模拟文件系统的设计与实现
- 格式:doc
- 大小:266.17 KB
- 文档页数:28
文件系统的设计与实现随着计算机技术的发展,文件系统在计算机领域中扮演着至关重要的角色。
文件系统是计算机文件管理的核心,负责文件的存储、读取、修改、删除等操作,影响着计算机系统的性能、稳定性和可靠性。
本文将从文件系统的基本原理、设计要求及其实现架构等方面进行探讨。
一、文件系统的基本原理文件系统的基本原理是在计算机中创建一种逻辑结构,将不同类型的文件以数据块的方式存储在硬盘中。
文件系统通过文件夹及目录树等组织方式,将文件组织成系统中易于管理、存储和使用的形式。
同时,文件系统的实现需要考虑文件读写的速度和可靠性,建立合适的文件缓存机制,以加快读写速度,减少硬盘的读写次数,提高文件系统的效率。
文件系统的逻辑结构包含以下几个方面:1. 文件:文件系统将不同的信息类型编码为不同的文件格式,便于用户使用。
在Unix/Linux操作系统中,采用Inode(索引节点)作为文件的描述符,在Windows操作系统中,采用文件描述符来描述文件信息。
2. 文件夹:文件夹是存储文件的逻辑单位,它可以容纳多个文件或多个子文件夹,并通过目录树的形式整合在一起,给予用户更好的组织文件的方式。
3. 文件系统权限:文件系统提供用户权限控制机制,确保有些系统文件只有管理员才可以访问和修改,有些是所有用户都可以访问。
4. 磁盘分区:文件系统通过磁盘分区和分配技术,将硬盘分成多个逻辑区域,每个区域可以容纳不同大小的文件,确保文件系统的可靠性和稳定性。
二、文件系统的设计要求针对文件系统的基本原理,设计一个高效、可靠的文件系统需要考虑以下的设计要求:1. 高效性:对文件的读写、创建、移动、查找等操作进行优化,减少IO操作次数,提高文件系统读写速度。
2. 可靠性:文件系统的数据存储必须是安全、可靠的,确保文件不会因为磁盘损坏、文件系统崩溃等原因丢失,可进行备份和恢复。
3. 易用性:操作便捷、功能丰富的用户界面,以及快捷的文件搜索、复制、黏贴等操作,使用户可以方便地管理和使用文件。
《操作系统课程设计》实验报告学号:姓名:苏州大学计算机科学与技术学院2014年9月操作系统课程设计实验报告目录目录 (1)一、实验环境 (2)二、实验报告总体要求 (2)实验一编译L INUX内核 (3)实验二观察L INUX行为 (7)实验三进程间通信 (14)操作系统课程设计实验报告一、实验环境Linux平台◆硬件平台:普通PC机硬件环境。
◆操作系统:Linux环境,例如,红旗Linux或Red Hat Linux;启动管理器使用GRUB。
◆编译环境:伴随着操作系统的默认gcc环境。
◆工作源码环境:一个调试的内核源码,版本不低于2.4.20。
二、实验报告总体要求在2013年11月25日前提交实验报告。
实验报告至少要求包含以下内容:1.引言:概述本次实验所讨论的问题,工作步骤,结果,以及发现的意义。
2.问题提出:叙述本篇报告要解决什么问题。
注意不可以抄写实验要求中的表述,要用自己的话重新组织我们这里所提出的问题。
3.解决方案:叙述如何解决自己上面提出的问题,可以用小标题 3.1,3.2…等分开。
这是实验报告的关键部分,请尽量展开来写。
注意,这部分是最终课程设计的基本分的部分。
这部分不完成,本课程设计不会及格。
4.实验结果:按照自己的解决方案,有哪些结果。
结果有异常吗?能解释一下这些结果吗?同别人的结果比较过吗?注意,这部分是实验报告出彩的地方。
本课程设计要得高分,应该在这部分下功夫。
5.结束语:小结并叙述本次课程设计的经验、教训、体会、难点、收获、为解决的问题、新的疑惑等。
6.附录:加了注释的程序清单,注释行数目至少同源程序行数目比1:2,即10行源程序,至少要给出5行注释。
操作系统课程设计实验报告实验一编译Linux内核实验时间6小时实验目的认识Linux内核的组成,掌握配置、编译、安装Linux内核的步骤。
实验目标下载2.6.19或更新的Linux内核,配置该内核使其支持NTFS,并在新的内核中修改其版本为Linux NameTestKernel x.x.x,其中,Name是你的名字(汉语拼音);x.x.x是新内核的版本号,最后在你的机器上编译安装这个新内核。
《操作系统》课程设计题目:设计一个简单二级文件系统专业:计算机科学与技术年级:文专计081—1姓名:张庆龙学号:0126指导教师:翟一鸣时间:2010年7 月15日一、设计内容1、可以实现下列几条命令。
Format 格式化Dir 列文件目录Create 创建文件Delete 删除文件Deldir 删除目录Open 打开文件Close 关闭文件Search 查询文件Copy 拷贝文件Cut 剪切文件二、开发环境Windows操作系统Microsoft Visual C++三、分析设计(一)实验原理通过程序模拟Linux文件系统,用一个二进制文件(FileSystem.disk)来模拟磁盘.设计一个多用户的二级文件系经统、实现一般的创建文件、目录,删除文件、目录,切换目录,打开、关闭文件、读写文件等操作。
文件系统,包含格式化,显示文件(目录),创建文件等几个简单命令的实现,而且能完成超级块的读写,节点的读写等过程. 本文件系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户账号下的文件。
另外,为了简单本文件系统未考虑文件共享、文件系统安全以及管道文件与设备文件等特殊内容。
1.程序执行流程图:2.数据块的分配和回收(二)程序结构设计FileSystem类负责管理磁盘空间和磁盘内存I节点,负责对磁盘空间和磁盘数据进行优化管理。
并提代接口言方法供用户或程序调用。
(三)数据结构int physic[100]; //文件地址缓冲区int style=1; //文件的类型char cur_dir[10]="root"; //当前目录int search_i=0;struct command{char com[10];}cmd[20];struct block{int n; //空闲的盘快的个数int free[50]; //存放空闲盘快的地址int a; //模拟盘快是否被占用}memory[20449];struct block_super{int n; //空闲的盘快的个数int free[50]; //存放进入栈中的空闲块int stack[50]; //存放下一组空闲盘快的地址}super_block;struct node //i结点信息{int file_style; //i结点文件类型int file_length; //i结点文件长度int file_address[100]; //i结点文件的物理地址 char file_message[100];} i_node[640];struct dir //目录项信息{char file_name[10]; //文件名int i_num; //文件的结点号char dir_name[10]; //文件所在的目录} root[640];四. 运行示例及结果分析菜单删除目录文件查询拷贝剪切五、程序实现详细程序请参见源文件, 在此只列举3点1、剪切文件程序片段:void cut(char *tmp,char *newname){int i; //,jchar t[20];_strtime(t);for(i=0;i<640;i++)if(strcmp(newname,root[i].file_name)==0){break;}if(i==640){printf("目录不存在,不能剪切!\n");return;}for(i=0;i<640;i++){if(strcmp(tmp,root[i].file_name)==0){strcpy(root[i].dir_name,newname);strcpy(i_node[root[i].i_num].change_t,t);//printf("剪切成功!\n");//return;}}if(i==640)printf("文件不存在,执行失败!\n");}2.无文件查询程序片段:void search(char* filename){int sign=0;for(search_i=0;search_i<640;search_i++){if(strcmp(root[search_i].file_name,filename)==0) //查询文件中所在目录信息和当前目录信息相同的数据{sign=1;int k=root[search_i].i_num;printf("%s\t",root[search_i].file_name); //文件名printf(" %d\t",i_node[k].file_style); //文件的类型printf(" %d\t\t",i_node[k].file_length); //文件的长度printf("%s\n",root[search_i].dir_name); //文件所在的目录}}if (sign==0){printf("%s\n","未找到该文件!");}}六、心得与体会这次设计中遇到最难的问题就是拷贝功能的实现,由于之前没有接触过拷贝的原理,所以通过和同伴的讨论和试验,终于突发奇想的运用改变文件路径的源代码和创建文件相结合,终于实现了拷贝功能,能够将一个文件从一个目录拷贝到另一目录(即先移动过去然后再在原位置创建一个原文件),可是却无法拷贝到root根目录,为了解决这个问题,又在创建文件的程序里添加了一个判断是否为根目录的语句,可是后来又发现了真个系统存在重命名的问题。
文件管理系统设计与实现一、引言现代社会中,数据量不断增长,如何快速、方便地对数据进行管理,成为了各个领域需要解决的问题。
随着文件管理系统技术的不断发展,各类应用程序需要一个高效可靠的文件管理系统,可以更好地组织、协调和管理数据,从而提高工作效率。
本文将介绍文件管理系统的设计与实现,以期为许多需要使用文件管理系统的人提供一个借鉴和参考。
二、文件管理系统设计文件管理系统旨在解决日常工作中,数据量大,数据类型繁多,数据来源多样化等问题。
为了满足不同应用程序的需求,文件管理系统需要具备以下基本功能:1. 文件存储:文件管理系统需要能够对各类文件进行存储、管理和维护。
不同类型文件的存储方式也有所不同,例如文本文件、图片文件、视频文件等文件需要使用不同的存储方式,以保证文件的完整性和安全性。
2. 文件检索:当用户需要查找某个特定的文件时,应该能够使用文件管理系统提供的检索功能,轻松地找到所需要的文件。
3. 文件备份:为了防止文件出现意外丢失、损坏等情况,文件管理系统需要提供文件备份的功能。
当文件系统出现故障或者用户误删文件时,可以使用备份文件进行恢复操作。
4. 文件权限管理:为了避免未经授权的用户篡改、删除文件,文件管理系统需要提供文件权限控制的功能。
只有具有特定权限的用户才能够访问和修改文件。
5. 文件分享:在团队合作过程中,文件分享是非常重要的功能。
文件管理系统需要提供方便的分享方式,以满足用户的不同需求。
6. 日志记录:当用户对文件进行操作时,文件管理系统需要记录用户操作的详细记录,以便后续审计和追责。
7. 数据加密:对于一些重要性较高的文件,文件管理系统需要提供加密、解密的功能,以保证文件的机密性和安全性。
以上功能是基本的文件管理系统所必须具备的,不同的应用程序也需要根据具体的需求制定其他的特定功能。
三、文件管理系统实现在文件管理系统的实现过程中,首先需要选用一个适合自己需求的平台。
市面上有很多操作系统和服务器软件都可以作为文件管理系统的平台,例如Windows Server、Linux、Mac OS等,每个平台都有其独特的优点和特点。
操作系统课程设计1、(难度系数3)模拟UNIX(linux)文件系统[问题描述]在任一OS下,建立一个大文件,把它假象成一张盘,在其中实现一个简单的模拟UNIX文件系统。
[基本要求]1).在现有机器硬盘上开辟20M的硬盘空间,作为设定的硬盘空间。
2).编写一管理程序对此空间进行管理,以模拟UNIX(或linux)文件系统,具体要求如下:(1)要求盘块大小1k正规文件(2) i 结点文件类型目录文件(共1byte) 块设备管道文件。
物理地址(索引表)共有13个表项,每表项2byte。
文件长度4byte。
联结计数1byte(3)0号块超级块栈长度50空闲盘块的管理:成组链接( UNIX)或位示图法(Linux)(4)每建一个目录,分配4个物理块文件名14byte(5)目录项信息i 结点号2byte(6)结构:0#:超级块1#-20#号为目录区20#-30#号索引节点区(7)功能:1、初始化2、建立文件(需给出文件名,文件长度)3、建立子目录4、打开文件(显示文件所占的盘块)5、删除文件6、删除目录7、显示目录(即显示目录下的信息,包括文件、子目录等)8、显示整个系统信息2、模拟文件系统(难度系数2)[问题描述]在任一OS下,建立一个大文件,把它假象成一张盘,在其中实现一个简单的小型文件系统。
[基本要求]该小型文件系统没有子目录机制,文件连续分配,不考虑分区。
做一个简单的操作界面,提供五条简单的命令:显示文件名dir 、创建文件cf、拷贝文件copy、删除文件del , 文件改名rename 。
进一步增强:上题中的文件系统功能:文件系统不连续分配,可以有子目录机制,(如两级子目录机制)。
3、设计一个请求页式存储管理方案。
(难度系数1)并编写模拟程序实现之。
产生一个需要访问的指令地址流。
它是一系列需要访问的指令的地址。
为不失一般性,你可以适当地(用人工指定地方法或用随机数产生器)生成这个序列,使得 50%的指令是顺序执行的。
中北大学操作系统课程设计说明书学院、系:软件学院专业:软件工程学生姓名:赵巍学号:********** 设计题目:基于Linux的模拟文件系统的设计与实现起迄日期: 2011年12月22日- 2012年1月7日****:**2012 年 1月 7 日1需求分析所要实现的功能:(1)设计一个10个用户的文件系统。
每个用户最多可以保存10个文件,一次运行用户可打开多个文件。
(2)程序采用二级文件目录。
(即设置主目录(MFD)和用户文件目录(UFD))。
另外,可打开文件设置指针。
(3)为了方便实现,对文件的读写作了简化。
在执行读写命令时,只需改读写指针。
并不进行实际的读写操作。
(4)实现的基本功能主要包括:改变目录(CD),创建目录(MD),显示目录(DIR),删除目录(RD),打开全部文件(openall),打开单个文件(open),建立一个文件(create),删除一个文件(delete),写文件(write),读文件(read),改文件的保护码(change),退出(exit)等。
考虑特殊情况如:各个命令对全路径和相对路径的支持、目录不存在时,给出错误信息、不能用cd进入文件、命令之中不能有空格(如 ex it,给出错误提示)、相对路径的解析、路径中的空格剔除、新建目录或文件时的问题、重名问题、目录或文件的名字长度限制、目录或文件的名字中包含不合法字符(注意空格)、删除目录或文件时的问题、删除不存在的文件或目录给出错误提示、删除目录时目录不为空(如果该目录为空,则可删除,否则给出是否做删除提示,删除操作将该目录下的全部文件和子目录都删除)、进入到某个目录下,却要删除本目录或上级目录、不能用delete删除目录、不能用RD删除文件等都要考虑在内。
最终获得的成果就是:①在系统中用一个文件来模拟一个磁盘;②此系统至少有:Create、delete、open、close、read、write等和部分文件属性的功能。
③实现这个文件系统。
④能实际演示这个文件系统。
基本上是进入一个界面(此界面就是该文件系统的界面)后,可以实现设计的操作要求。
2总体设计2.1系统活动图2.2 头文件:#include <stdio.h>#include <stdlib.h>#include <string.h>2.3结构体:typedef struct file{char name[10];struct file *next;FILE *fp;}File;typedef struct content{ char name[10];File *fileHead;int f_num;struct content *next; }Content;typedef struct user{char name[10];char psw[10];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()void FileMove()3.详细设计用户管理系统:registe():用户注册login():用户登录目录管理系统:FolderCreate():新建目录FolderDelete():删除目录FolderIntoFolder():进入目录FolderViewAllFiles():显示所有目录内的所有文件absolutePathFileController():通过绝对路径直接读文件文件管理系统:FileCreate():新建文件FileDelete():删除文件FileMove():跨目录移动文件FileRead():读文件FileWrite():写文件3.1 用户管理系统:截图3-1相关核心代码://step0void registe(){if(user_num>=10){printf("Has 10 users.You have no access to register\n"); 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;else{last=user_head;while(last->next!=NULL)last=last->next;last->next=add;user_num++;//fulfill the new userchar name[10],psw[10];User *check;char buffer[2];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-input:\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("success\n");return;}//step0int login()if(user_head==NULL){printf("system has no user\n");return 0;}char buffer[2];fgets(buffer,2,stdin);char name[10],psw[10];User *check;printf("press \"#\" if you wanna quit\n");unl:printf("username:\n");scanf("%s",name);if(name[0]=='#')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(buffer,2,stdin);printf("password:\n");fgets(psw,11,stdin);if(strcmp(psw,check->psw)!=0){printf("wrong password\n");goto unl;}printf("\n\n*********welcome back!%s*******\n\n",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. New user\n");printf("2. Login\n");printf("0. Exit\n");printf("*************************\n");printf(" %d user exist\n",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 using\n");exit(0);default:printf("wrong input!\n");}}}3.2 目录管理系统:截图3-2相关核心代码://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("*********%s's Content************\n",cur_user->name); printf("1.create a folder\n");printf("2.get in to a folder\n");printf("3.delete a folder\n");printf("4.view all files\n");printf("5.read a file directly by absolute path\n");printf("6.log out\n");printf("0.shut down FILE_SYSTEM\n");printf(" view all your folders below: %d folders total\n",current->c_num);if(current->conHead==NULL)printf(" |\n no folder.\n");else{goThrough=current->conHead;while(goThrough!=NULL){printf(" |\n %s\n",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:FolderViewAllFiles();continue;case 5:absolutePathFileController();continue;case 6:printf("\nThanks for using\n\n");return;case 0:printf("\nThanks for using\n");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 folderContent *add,*last;add=(Content *)malloc(sizeof(Content));add->next=NULL;if(user->conHead==NULL)user->conHead=add;else{last=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 name[10];Content *check;char buffer[2];fgets(buffer,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<=9;i++){if(name[i]>=97&&name[i]<=122)//lowercontinue;elseif(name[i]>=48&&name[i]<=57)//numcontinue;elseif(name[i]>=65&&name[i]<=90)//uppercontinue;elseif(name[i]=='\0')break;else{printf("<%c>is a illegal input!\nplease re-input:\n",name[i]); goto con_r;}}strcpy(add->name,name);printf("DONE\n\n");return;}//step1void FolderDelete(){if(cur_user->conHead==NULL){printf("NO Folder\n\n");return;}Content *front,*current;char name[10];printf("press \"#\" if you wanna quit\n");con_d:printf("folder name:\n");scanf("%s",name);if(name[0]=='#')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(current->fileHead!=NULL){char buffer[2];fgets(buffer,2,stdin);printf("folder not emptyIF 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;else{printf("Please input \"Y\" OR \"N\"\n");continue;}}//user recognisechar psw[10];printf("input your user password to recognise:");char buffer[2];fgets(buffer,2,stdin);fgets(psw,10,stdin);if(strcmp(cur_user->psw,psw)!=0){printf("WRONG PASSWORD!\nDELETE FUNCTION FAILLED\n");return;}//execute delete operationfront=cur_user->conHead;if(front==current) //if curren is the head file{cur_user->conHead=current->next;free(current);printf("Has been deleted\n1\n");return;}while(front->next!=current)front=front->next;front->next=current->next;free(current);cur_user->c_num--;printf("Has been deleted\n2\n");return;}//step1void FolderViewAllFiles(){printf("\nscan all your file:\n");Content *con;con=cur_user->conHead;int fi_num=0;while(con!=NULL){printf("| %s-----------------\n",con->name);File *fi;fi=con->fileHead;while(fi!=NULL){printf("| | %s\n",fi->name);printf("| | |\n");fi=fi->next;}fi_num+=con->f_num;con=con->next;}printf("total:%d Folders,%d Files\n\n",cur_user->c_num,fi_num); return;}//step1void FolderIntoFolder(){void MenuFolder();if(cur_user->conHead==NULL){printf("You has no Folder\n");return;}printf("now get into a Folder:\nFolder name(9):\n");char name[10];char buffer[2];fgets(buffer,2,stdin);Content *check;printf("type \"#\" if you wanna quit\n");con_g:printf("folder name:\ncd ");scanf("%s",name);if(name[0]=='#')return;check=cur_user->conHead;while(check!=NULL){if(!strcmp(check->name,name))break;elsecheck=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:<Folder name>/<File name>\n"); printf("________________________\n");char name[28];printf("press \"#\" if you wanna quit\n"); absolute:printf("absolute file path:\n");scanf("%s",name);if(name[0]=='#')return;char folder_name[10];char file_name[14];//analyse the absolute path//get folder nameif(name[0]=='/'){printf("no folder name!please re-input:\n"); goto absolute;}int i=0,j=0;while(name[i]!='/'&&i<=9){if(name[i]=='\0'){printf("WRONG FORMAT\n");goto absolute;}folder_name[i]=name[i];i++;}folder_name[i]='\0';i++;//get file nameif(name[i]=='\0'){printf("NO <FILE NAME>,PLEASE RE-INPUT\n"); goto absolute;}while(name[i+j]!='\0'&&j<=9){file_name[j]=name[i+j];j++;}file_name[j]='\0';printf("~~~~~~~~~~~~~~~~~~~~~~~~\n");printf("result of analysis:\n");printf("FOLDER NAME:%s\n",folder_name);printf("FILE NAME:%s\n",file_name);printf("~~~~~~~~~~~~~~~~~~~~~~~~\n");//seek folderContent *folder_checker;folder_checker=cur_user->conHead;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;file_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 fullName[20]={"PRO/"};strcat(fullName,file_name);printf("=================================================\ndetails:\n\n"); file_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;current=cur_con;goThrough=current->fileHead;char buffer[2];int choice;for(;;){fgets(buffer,2,stdin);printf("\n~~~~~~~~~~~~~~~~~Folder:%s~~~~~~~~~~~~~~~~~~~~~~~~\n",current->name); printf("1.create a new file\n");printf("2.read a file\n");printf("3.write to a file\n");printf("4.delete a file\n");printf("5.move a file\n");printf("6.back to user-menu\n");printf("0.shut down FILE_SYSTEM\n\n");printf(" view all your files below: %d filestotal\n",current->f_num);if(current->fileHead==NULL)printf(" |\n no file.\n");else{goThrough=current->fileHead;while(goThrough!=NULL){printf(" |\n %s\n",goThrough->name);goThrough=goThrough->next;}}printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");printf("\ninput your choice:\n");choice=-1;scanf("%d",&choice);switch(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:\n\n");cur_con=NULL;return;case 0:printf("\nThanks for using\n");cur_user=NULL;cur_con=NULL;exit(0); default:printf("wrong input!\n");}}}//step2void FileCreate(){Content *cur_content;cur_content=cur_con;//allocate new memory block for new file's indexFile *add,*last;add=(File *)malloc(sizeof(File));add->next=NULL;add->fp=NULL;if(cur_content->fileHead==NULL)cur_content->fileHead=add;else{last=cur_content->fileHead;while(last->next!=NULL)last=last->next;last->next=add;}cur_content->f_num++;//fulfill the new folder namechar name[10];File *check;char buffer[2];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->name)==0){printf("file name exist.please re-input:\n");goto file_r;}check=check->next;}//check legality of the nameint i=0;for(;i<=9;i++){if(name[i]>=97&&name[i]<=122)//lowercontinue;elseif(name[i]>=48&&name[i]<=57)//numcontinue;elseif(name[i]>=65&&name[i]<=90)//uppercontinue;elseif(name[i]=='\0')break;else{printf("<%c>is a illegal input!\nplease re-input:\n",name[i]);goto file_r;}}strcpy(add->name,name);char fullName[20]={"PRO/"};strcat(fullName,name);add->fp=fopen(fullName,"w");if(add->fp==NULL){printf("ERROR WHEN CREATE A FILE IN DESK\nPEASE CONTACT SYSTEM MANAGER\n"); goto file_r;}fclose(add->fp);printf("DONE\n\n");return;}//step2void FileRead(){if(cur_con->fileHead==NULL){printf("NO File\n\n");return;}printf("\nnow read a file:\n");File *current;char name[10];printf("press \"#\" if you wanna quit\n");file_r:printf("file name:\n");scanf("%s",name);if(name[0]=='#')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 fullName[20]={"PRO/"};strcat(fullName,name);printf("=================================================\ndetails:\n\n"); 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 File\n\n");return;printf("\nnow read a file:\n");File *current;char name[10];printf("press \"#\" if you wanna quit\n");file_r:printf("file name:\n");scanf("%s",name);if(name[0]=='#')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 fullName[20]={"PRO/"};strcat(fullName,name);printf("=================================================\nType details:(tpye in \"#\" to finish the text)\n\n");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 File\n\n");return;}File *front,*current;char name[10];printf("press \"#\" if you wanna quit\n");file_d:printf("file name:\n");scanf("%s",name);if(name[0]=='#')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;}//execute delete operationfront=cur_con->fileHead;if(front==current) //if curren is the head file {cur_con->fileHead=current->next;free(current);printf("Has been deleted\n1\n");return;}while(front->next!=current)front=front->next;front->next=current->next;free(current);cur_con->f_num--;printf("Has been deleted\n2\n");return;}//step2void FileMove(){printf("\n=================================\nnow move a file from Folder %s to another Folder\n====================================\n",cur_con->name);//move indexContent *target_con,*current_con;if(cur_con->fileHead==NULL){printf("NO File\n\n");return;}File *front_f,*current_f,*tar_f;char name[10];printf("press \"#\" if you wanna quit\n");file_m:printf("file name:\n");scanf("%s",name);if(name[0]=='#')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 valuechar buffer[2];fgets(buffer,2,stdin);char tar_name[10];printf("\ninput target Folder name:\n");printf("(press \"#\" if you wanna quit)\n");file_tar:printf("target folder name:\n");scanf("%s",tar_name);if(tar_name[0]=='#')return;//seek folder nametarget_con=cur_user->conHead;while(current_con!=NULL){if(!strcmp(target_con->name,tar_name))break;elsetarget_con=target_con->next;}if(target_con==NULL){printf("no such folder..\nplease re-input:\n");goto file_tar;}//seek target insert position then execute move operationtar_f=target_con->fileHead;front_f=cur_con->fileHead;if(tar_f==NULL)//if target folder empty{target_con->fileHead=current_f;if(current_f==front_f)//if moving file is the first file of pre-blong cur_con->fileHead=current_f->next;else //moving file is not the first{while(front_f->next!=current_f)front_f=front_f->next;front_f->next=current_f->next;}current_f->next=NULL;return;}//if target folder is not emptywhile(tar_f->next!=NULL)tar_f=tar_f->next;tar_f->next=current_f;if(current_f==front_f)//if moving file is the first file of pre-blongcur_con->fileHead=current_f->next;else //moving file is not the first{while(front_f->next!=current_f)front_f=front_f->next;front_f->next=current_f->next;}current_f->next=NULL;return;}4.心得体会操作系统课程设计是本课程重要的实践教学环节。