操作系统课程设计二级文件系统

合集下载

计算机操作系统课程设计_简单的二级文件系统

计算机操作系统课程设计_简单的二级文件系统

《操作系统》课程设计题目:设计一个简单二级文件系统专业:计算机科学与技术年级:文计091-1*名:***学号:200990514103指导教师:任满杰时间:2011-2012第二学期2012年9月1日一、设计内容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根目录,为了解决这个问题,又在创建文件的程序里添加了一个判断是否为根目录的语句,可是后来又发现了真个系统存在重命名的问题。

操作系统二级文件管理课程设计

操作系统二级文件管理课程设计

课程:计算机操作系统二级文件系统设计报告系电子信息与计算机科学系专业计算机科学与技术班级文计XXX-X姓名XXX学号XXXXXXXXX指导教师XXX学年学期2011-20122012 年9 月2日一、实验目的通过简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现。

二、实验内容为Linux系统设计一个简单二级文件管理系统三、实验要求可以实现下列命令:login 用户登录dir 列文件目录create 创建文件delete 删除文件open 打开文件close 关闭文件read 读文件write 写文件列目录时要列出文件名、物理地址、保护码和文件长度.源文件可以进行读写保护.四、设计思想采用两级目录,其中第一级对应于用户账号,第二级对应于用户账号下的文件。

实验提示(1)首先应确定文件系统的数据结构:主目录、子目录及活动文件等。

主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。

(2)用户创建的文件,可以编号存储于磁盘上。

入file0,file1,file2…并以编号作为物理地址,在目录中进行登记。

主要数据结构struct fatitem //FAT表struct FCB //文件控制块块结构体struct opentable //文件打开表结构体struct direct //目录结构体1 FAT表的定义:struct fatitem //size 8{int item; //存放文件下一个磁盘的指针char em_disk; //磁盘块是否空闲标志位 0 空闲};2目录和文件控制块的定义:struct direct{/*-----文件控制快信息-----*/struct FCB{char name[9]; // 文件/目录名 10位char property; // 属性 1位目录 0位普通文件int size; // 文件/目录字节数、盘块数)int firstdisk; // 文件/目录起始盘块号int next; // 子目录起始盘块号int sign; // 1是根目录 0不是根目录}directitem[MSD+2];};3文件打开表的定义struct opentable{struct openttableitem{char name[9]; //文件名int firstdisk; //起始盘块号int size; //文件的大小}openitem[MOFN];int cur_size; //当前打文件的数目};主要函数表void initfile(); //初始化磁盘文件void format(); //格式化文件void enter(); //进入文件系统void halt();//退出文件系统函数int create(char *name); //创建文件int open(char *name); //打开文件int close(char *name); //关闭文件int write(int fd,char *buf,int len);int read(int fd,char *buf);int del(char *name); //删除文件int mkdir(char *name); //目录创建函数int rmdir(char *name); //删除目录函数int cd(char *name); //改变当前目录内容void dir(); // 查看当前目录void print(); //打印出void show(); //显示内容运行界面与结果五、心得体会一周的操作系统课程设计,让我受益匪浅。

操作系统课程设计--为linux系统设计一个简单的二级文件系统

操作系统课程设计--为linux系统设计一个简单的二级文件系统

操作系统课程设计报告题目: 为Linux系统设计一个简单的二级文件系统指导老师:时间:2021.8.30一课程设计的目的课程设计目的使学生熟悉文件管理系统的设计方法;加深对所学各种文件操作的了解及其操作方法的特点。

通过模拟文件系统的实现,深入理解操作系统中文件系统的理论知识, 加深对教材中的重要算法的理解。

同时通过编程实现这些算法,更好地掌握操作系统的原理及实现方法,提高综合运用各专业课知识的能力。

二课程设计的要求1.可以实现下列几条命令:login用户登录dir 列目录create创建文件delete 删除文件open 打开文件close 关闭文件read 读文件write 写文件2.列目录时要列出文件名,物理地址,保护码和文件长度3.源文件可以进行读写保护三算法设计本次二级文件系统主要分为五大模块,分别是用户登录模块、新建目录模块、新建文件模块、删除文件模块和读取文件模块。

用户登录成功后才可以进行其他模块的操作。

1 用户登录模块用户登录模块要求用户输入用户,当输入正确后才能进行其他模块操作,否则提示用户名不存在并询问用户是否用此名进行注册。

若用户名未满,则提示注册成功,否则提示用现有注册用户,进行登录,并返回到登录界面。

用户登录模块流程图如图1所示。

图1 用户登录模块流程图2新建文件模块新建文件模块是在用户出入create 指令后进行的,进入后会要求用户输入文件名,并判断文件名是否存在,若没有则在要求用户输入文件读写权限,否则重新输入新的文件名。

新建文件模块流程图如图2所示。

图2 新建文件流程图3 删除文件模块删除文件模块是根据用户鼠标右击时选择到的节点来确定要删除节点的名字与路径,然后判断该节点是目录还是文件。

若是文件则直接删除文件,若是目录则进入该目录再删除其全部文件。

删除文件模块流程图如图4所示。

图4 删除文件模块流程图4读取文件模块读取文件模块,要求用户要在文件打开的前提下,将磁盘中的内容读取到内存中。

操作系统课程设计二级文件系统

操作系统课程设计二级文件系统

#include<stdio.h>#include<string.h>#include<stdlib.h>//#include <time.h>int N=0; //记录用户数目struct MFILE{ //文件表char filename[19];char content[1000];//char filecha_time[18];int fileflag;};struct DIR{ //目录表char dirname[19];MFILE file[100];int filenum;int coflag;//char dircha_time[18];};struct USER{ //用户表char name[5];char password[5];DIR dir[100];int dirnum;} user[10];int check(char* name,char* password,int &userlo);void enter_dir(int userlo);void show_dir(int userlo);int open_dir(int userlo,char* ch1,int &filelo);void create_dir(int userlo,char* ch1);void delete_dir(int userlo,char* ch1);void re_dirname(int userlo,char* ch1,char* ch2);void enter_file(int userlo,int filelo);void show_file(int userlo,int filelo);void open_file(int userlo,char* ch1,int filelo);void close_file(int userlo,char* ch1,int filelo);void read_file(int userlo,char* ch1,int filelo);void create_file(int userlo,char* ch1,char* ch2,int filelo); void delete_file(int userlo,char* ch1,int filelo);void re_filename(int userlo,char* ch1,char* ch2,int filelo);void add_filestr(int userlo,char* ch1,char* ch2,int filelo);//char* nowtime();void main(){FILE *fp=fopen("user.txt","r+");while(!feof(fp)){ //用户文件读入到用户顺序表char name[5];char password[5];fscanf(fp,"%s%s",name,password);strcpy(user[N].name,name);strcpy(user[N].password,password);user[N].dirnum=0;N++;}while(1){char name[19];char password[19];printf("请登录:\n");printf("用户名->");scanf("%s",name);printf("密码->");scanf("%s",password);int userlo; //用户标识if(check(name,password,userlo)==1){enter_dir(userlo);}else printf("用户名或密码错误!\n");}}int check(char* name,char* password,int &userlo){for(int i=0;i<N;i++){if(strcmp(user[i].name,name)==0&&strcmp(user[i].password,password)==0) {userlo=i;printf("登陆成功!\n");printf("输入help获得帮助列表\n");return 1;}elsei++;}return 0;}void enter_dir(int userlo){biaohao:while(1){char action[19];char ch1[19];char ch2[19];printf("->");if(scanf("%s",action)&&strcmp(action,"help")==0){printf("*****************************************\n"); //printf("* help 帮助!*\n");printf("* dir 显示目录!*\n");printf("* open name 打开目录!*\n");printf("* create 目录名创建新目录!*\n");printf("* delete 目录名删除目录! *\n");printf("* rename 旧名称新名称为目录重命名!*\n");printf("* quit 退出登陆!*\n");printf("*****************************************\n"); }else if(strcmp(action,"dir")==0){show_dir(userlo);}else if(strcmp(action,"quit")==0){break;}else if(strcmp(action,"open")==0){scanf("%s",&ch1);int filelo;if(open_dir(userlo,ch1,filelo)==0){printf("目录打开成功!\n");printf("输入help获得帮助列表\n");open_dir(userlo,ch1,filelo);enter_file(userlo,filelo);}elsegoto biaohao;}else if(strcmp(action,"create")==0){scanf("%s",&ch1);create_dir(userlo,ch1);}else if(strcmp(action,"delete")==0){scanf("%s",&ch1);delete_dir(userlo,ch1);}else if(strcmp(action,"rename")==0){scanf("%s%s",&ch1,&ch2);re_dirname(userlo,ch1,ch2);}else{printf("%s不是系统内部命令!\n",action); }}}void show_dir(int userlo){if(user[userlo].dirnum==0){printf("目录为空!\n");return;}printf("目录名\n");for(int i=0;i<user[userlo].dirnum;i++){//printf("%-26s\n",user[userlo].dir[i].dirname);printf(user[userlo].dir[i].dirname);printf(" \n");}}int open_dir(int userlo,char* ch1,int &filelo){for(int i=0;i<user[userlo].dirnum;i++){if(strcmp(user[userlo].dir[i].dirname,ch1)==0){user[userlo].dir[i].coflag=1;filelo=i;return 0;// printf("目录打开成功!\n");//printf("输入help获得帮助列表\n");}}printf("该目录不存在!\n");return 1;}void create_dir(int userlo,char* ch1){for(int i=0;i<user[userlo].dirnum;i++){if(strcmp(user[userlo].dir[i].dirname,ch1)==0){printf("有同名用户存在!\n");return;}}strcpy(user[userlo].dir[user[userlo].dirnum].dirname,ch1);user[userlo].dir[user[userlo].dirnum].coflag=0;user[userlo].dir[user[userlo].dirnum].filenum=0;user[userlo].dirnum++;printf("目录创建成功!\n");}void delete_dir(int userlo,char* ch1){int dflag=-1;for(int i=0;i<user[userlo].dirnum;i++){if(strcmp(user[userlo].dir[i].dirname,ch1)==0){dflag=i;break;}}if(dflag==-1){printf("该目录不存在!\n");}else{for(int j=i;j<user[userlo].dirnum-1;j++){strcpy(user[userlo].dir[j].dirname,user[userlo].dir[j+1].dirname);for(int k=0;k<user[userlo].dir[j+1].filenum;k++){strcpy(user[userlo].dir[j].file[k].filename,user[userlo].dir[j+1].file[k].filename);strcpy(user[userlo].dir[j].file[k].content,user[userlo].dir[j+1].file[k].content);user[userlo].dir[j].file[k].fileflag=user[userlo].dir[j+1].file[k].fileflag;}user[userlo].dir[j].filenum=user[userlo].dir[j+1].filenum;user[userlo].dir[j].coflag=user[userlo].dir[j+1].coflag;}printf("删除成功!\n");user[userlo].dirnum--;}}void re_dirname(int userlo,char* ch1,char* ch2){for(int i=0;i<user[userlo].dirnum;i++){if(strcmp(user[userlo].dir[i].dirname,ch1)==0){for(int j=0;j<user[userlo].dirnum;j++){if(strcmp(user[userlo].dir[j].dirname,ch2)==0){printf("你更换的新目录名已经存在!");return;}}strcpy(user[userlo].dir[i].dirname,ch2);printf("重名名成功!\n");return;}}printf("无此目录!无法重命名!\n");}void enter_file(int userlo,int filelo){while(1){char action[19];char ch1[19];char ch2[19];printf("->");if(scanf("%s",action)&&strcmp(action,"help")==0){printf("---------------------———————————\n");//printf("* help 帮助!*\n");printf("- dir 显示文件列表!-\n");printf("- open 文件名打开文件!-\n");printf("- read 文件名读取文件!-\n");printf("- create 文件名文件内容创建新文件!-\n");printf("- delete 文件名删除文件! -\n");printf("- rename 旧文件名新文件名为文件重命名!-\n");printf("- addstr 文件名更新内容更新文件!-\n");printf("- ... 返回上一层!-\n");//printf("- quit 退出登陆!-\n");printf("----------------------———————————\n");}else if(strcmp(action,"dir")==0){show_file(userlo,filelo);}// else if(strcmp(action,"quit")==0)// {// break;// }else if(strcmp(action,"...")==0){break;}else if(strcmp(action,"open")==0){scanf("%s",&ch1);open_file(userlo,ch1,filelo);}else if(strcmp(action,"close")==0){scanf("%s",&ch1);close_file(userlo,ch1,filelo);}else if(strcmp(action,"read")==0){scanf("%s",&ch1);read_file(userlo,ch1,filelo);}else if(strcmp(action,"create")==0){//scanf("%s%s",&ch1,&ch2);scanf("%s\n",&ch1);scanf("%s",&ch2);create_file(userlo,ch1,ch2,filelo);}else if(strcmp(action,"delete")==0){scanf("%s",&ch1);delete_file(userlo,ch1,filelo);}else if(strcmp(action,"rename")==0){scanf("%s%s",&ch1,&ch2);re_filename(userlo,ch1,ch2,filelo);}else if(strcmp(action,"addstr")==0){scanf("%s%s",&ch1,&ch2);add_filestr(userlo,ch1,ch2,filelo);}else{printf("%s不是系统内部命令!\n",action);return;}}}void show_file(int userlo,int filelo){if(user[userlo].dir[filelo].filenum==0){printf("无文件!\n");return;} printf("文件名\n");for(int i=0;i<user[userlo].dir[filelo].filenum;i++){printf("%-26s",user[userlo].dir[filelo].file[i].filename);//printf("%-26s\n",user[userlo].dir[filelo].file[i].filecha_time);}}void open_file(int userlo,char* ch1,int filelo){for(int i=0;i<user[userlo].dir[filelo].filenum;i++){if(strcmp(user[userlo].dir[filelo].file[i].filename,ch1)==0){if(user[userlo].dir[filelo].file[i].fileflag==1){printf("该文件已经打开!\n");return;}else{user[userlo].dir[filelo].file[i].fileflag=1;printf("打开成功!\n");return;}}}printf("该文件不存在!\n");}void close_file(int userlo,char* ch1,int filelo){for(int i=0;i<user[userlo].dir[filelo].filenum;i++){if(strcmp(user[userlo].dir[filelo].file[i].filename,ch1)==0){ if(user[userlo].dir[filelo].file[i].fileflag==0){printf("该文件未打开!\n");return;}else{user[userlo].dir[filelo].file[i].fileflag=0;return;}}}printf("你要关闭的文件文件不存在!\n");}void read_file(int userlo,char* ch1,int filelo){for(int i=0;i<user[userlo].dir[filelo].filenum;i++){if(strcmp(user[userlo].dir[filelo].file[i].filename,ch1)==0){ if(user[userlo].dir[filelo].file[i].fileflag==0){printf("请先打开该文件,然后在读取!\n");return;}else{printf("%s\n",user[userlo].dir[filelo].file[i].content);return;}}}printf("该文件不存在!");return;}void create_file(int userlo,char* ch1,char* ch2,int filelo){for(int i=0;i<user[userlo].dir[filelo].filenum;i++){if(strcmp(user[userlo].dir[filelo].file[i].filename,ch1)==0){printf("有同名文件存在!\n");return;}}printf("输入内容\n");//strcpy(user[userlo].dir[filelo].file[user[userlo].dir[filelo].filenum].filecha_time,nowtime());strcpy(user[userlo].dir[filelo].file[user[userlo].dir[filelo].filenum].filename,ch1);strcpy(user[userlo].dir[filelo].file[user[userlo].dir[filelo].filenum].content,ch2);user[userlo].dir[filelo].file[user[userlo].dir[filelo].filenum].fileflag=0;user[userlo].dir[filelo].filenum++;printf("文件创建成功\n");}void delete_file(int userlo,char* ch1,int filelo){int mflag=-1;for(int i=0;i<user[userlo].dir[filelo].filenum;i++){if(strcmp(user[userlo].dir[filelo].file[i].filename,ch1)==0){mflag=i;break;}}if(mflag==-1){printf("该文件不存在!\n");}else{if(user[userlo].dir[filelo].file[mflag].fileflag==1){printf("删除前请先关闭文件");return;}else{for(int j=i;j<user[userlo].dir[filelo].filenum-1;j++){strcpy(user[userlo].dir[filelo].file[j].filename,user[userlo].dir[filelo].file[j+1].filename); //strcpy(user[userlo].dir[filelo].file[j].filecha_time,user[userlo].dir[filelo].file[j+1].filecha_time);strcpy(user[userlo].dir[filelo].file[j].content,user[userlo].dir[filelo].file[j+1].content);user[userlo].dir[filelo].file[j].fileflag=user[userlo].dir[filelo].file[j+1].fileflag;}printf("删除成功!\n");user[userlo].dir[filelo].filenum--;}}}void re_filename(int userlo,char* ch1,char* ch2,int filelo){for(int i=0;i<user[userlo].dir[filelo].filenum;i++){if(strcmp(user[userlo].dir[filelo].file[i].filename,ch1)==0){for(int j=0;j<user[userlo].dir[filelo].filenum;j++){if(strcmp(user[userlo].dir[filelo].file[j].filename,ch2)==0){printf("你要更换的新文件名已经存在!\n");return;}}strcpy(user[userlo].dir[filelo].file[i].filename,ch2);//strcpy(user[userlo].dir[filelo].file[i].filecha_time,nowtime());printf("重名名成功!\n");return;}}printf("无此文件!无法重命名!\n");}void add_filestr(int userlo,char* ch1,char* ch2,int filelo){for(int i=0;i<user[userlo].dir[filelo].filenum;i++){if(strcmp(user[userlo].dir[filelo].file[i].filename,ch1)==0){if(user[userlo].dir[filelo].file[i].fileflag==0){printf("请先打开文件再进行更新!\n");return;}else{strcat(user[userlo].dir[filelo].file[i].content,ch2);//strcpy(user[userlo].dir[filelo].file[i].filecha_time,nowtime());printf("更新成功!\n");return;}}}printf("无此文件!无法更新!\n");}//char* nowtime(){// time_t t = time(0);// char tmp[64];// strftime( tmp, sizeof(tmp), "%Y/%m/%d %X",localtime(&t) ); // return (char*)tmp;//}。

操作系统二级文件管理课程设计

操作系统二级文件管理课程设计

操作系统课程设计课程设计名称:二级文件管理系统专业班级:学生姓名:学号:指导教师:时间:一览表实验目的实验内容实验要求设计思路主要数据结构表主要函数表数据结构代码功能函数代码心得体会实验目的:通过简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现。

实验内容:为Linux系统设计一个简单二级文件管理系统实验要求:可以实现下列命令(至少四个):login 用户登录dir 列文件目录create 创建文件delete 删除文件open 打开文件close 关闭文件read 读文件write 写文件列目录时要列出文件名、物理地址、保护码和文件长度.源文件可以进行读写保护.设计思想:第一级目录对应于用户账号,第二级对应于用户的文件。

主要数据结构struct diskblock //磁盘块struct fileblock //文件块结构体struct user_dir//用户文件目录文件struct main_dir //主文件目录1磁盘块的定义:struct diskblock //磁盘块{ int maxlength; //长度int start; //开始地址int useFlag; //是否使用标志diskblocke *next;//指向下一块地址}diskNode; //diskNode *diskHead;2 文件块的定义:struct fileblock //文件块结构体{char fileName[10]; //保存文件名字int strat; //起始地址int length; //内容长度int maxlength; //最大长度char fileKind[3]; //文件的属性——读写方式bool openFlag; //判断是否打开文件fileblocke *next; //指向下一个文件};3用户目录文件struct user_dir//用户文件目录文件{char fileName[10];//文件名字fileblock* file; //指向文件的指针user_file_directory *next; //};user_dir *headFile; //目录头指针4 主文件目录struct main_dir //主文件目录{char userName[10];//用户名char password[10];//用户名user_dir *user; //指向用户的目录};主要函数表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 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 diskShow(); //显示磁盘使用情况void userCreate();//用户管理int login();//创建用户void userCreate(){char c;char userName[10];int i;if(used<MaxUser){printf("请输入用户名:");for(i=0;c=getch();i++){if(c==13) break;elseuserName[i]=c;printf("%c",c);}userName[i]='\0';for(i=0;i<used;i++){if(!strcmp(userTable[i].userName,userName)){printf("\n");printf("该用户名已存在,创建用户失败\n");system("pause");//暂停return;}}strcpy(userTable[used].userName,userName);printf("\n");printf("请输入密码:");for(i=0;c=getch();i++){if(c==13) break;elseuserTable[used].password[i]=c;printf("*");}userTable[userID].password[i]='\0';printf("\n");printf(" 创建用户成功请登录\n");used++;//system("pause");}else{printf("创建用户失败,用户已达到上限\n");//system("pause");}//fflush(stdin);}int login()//用户登录模块{char name[10],psw[10];char c;int i,times;printf("请输入用户名:");for(i=0;c=getch();i++){if(c==13) break;elsename[i]=c;printf("%c",c);}name[i]='\0';for(i=0;i<used;i++){if(!strcmp(userTable[i].userName,name))break;}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;elsepsw[i]=c;printf("*");}printf("\n");for(i=0;i<used;i++){if(!strcmp(psw,userTable[i].password)){printf(" 用户登录成功请选择操作\n");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->maxlength=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 *)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=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=userTable[userID].user->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName)){printf("文件重名,创建文件失败\n");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->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(userTable[userID].user->next==NULL)// 通过主目录向用户表里加上这一文件信息userTable[userID].user->next=fileNode;else{p=userTable[userID].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!=NULL;p=p->next){if(p->start==startPostion)break;}p->useFlag=false;}void fileDel(char fileName[])// 删除文件{UFD *p,*q,*temp;q=userTable[userID].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->openFlag!=true) //先判断是否有进程打开该文件{temp=p;q->next=p->next;freeDisk(temp->file->strat); //磁盘空间回收free(temp);printf("文件删除成功\n");system("pause");}else{printf("该文件已被进程打开,删除失败\n");}}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");}}void fileCat(char fileName[])//{int startPos,length;int k=0;UFD *p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){startPos=p->file->strat;length=p->file->length;p->file->openFlag=true; //文件打开标记for(int i=startPos;k<length;i++,k++){if(i%50==0) printf("\n"); //一行大于50个字符则换行printf("%c",disk[i]);}printf("\n\n*****************************************************\n");printf("%s已被read进程打开,请用close命令将其关闭\n",p->file->fileName);}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}void fileWrite(char fileName[])//(写文件){UFD *p,*q;q=userTable[userID].user;//登陆后该userid已经记录值int i,k,startPos;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){if(!strcmp(p->file->fileKind,"r")) //判断文件类型{printf("该文件是只读文件,写入失败\n");return;}char str[500];printf("请输入要写入内容:\n");gets(str);startPos=p->file->strat;p->file->openFlag=true; //文件打开标记p->file->length=strlen(str);if(p->file->length>p->file->maxlength){printf("写入字符串长度大于该文件的总长度,写入失败\n");return;}for(i=startPos,k=0;k<(int)strlen(str);i++,k++)disk[i]=str[k];printf("文件写入成功,请用close命令将该文件关闭\n");system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");}}void fileFine(char fileName[])//(查询文件){UFD *p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){printf("********************************************\n");printf("文件名:%s\n",p->file->fileName);printf("文件长度:%d\n",p->file->maxlength);printf("文件在存储空间的起始地址:%d\n",p->file->strat);printf("文件类型:%s\n",p->file->fileKind);printf("创建时间:%s\n",asctime(p->file->timeinfo));printf("********************************************\n");system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}void chmod(char fileName[],char kind[])//(改变文件的读写方式){UFD *p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){strcpy(p->file->fileKind,kind);printf("修改文件类型成功\n");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}void fileRen(char fileName[],char name[])//(重命名文件){UFD *p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){while(q->next){if(!strcmp(q->next->file->fileName,name)){printf("您输入的文件名已存在,重命名失败\n");system("pause");return;}q=q->next;}strcpy(p->file->fileName,name);printf("重命名成功\n");system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}void fileDir(char userName[]) //显示某一用户的所有文件{UFD *p;int i,k;for(i=0;i<MaxUser;i++){if(!strcmp(userTable[i].userName,userName)){k=i;break;}}if(i==MaxUser){printf("没有找到该用户,请检查输入用户名是否正确\n");system("pause");return;}else{p=userTable[k].user->next;printf("********************************************************************************\n");printf("文件名文件长度文件在磁盘的起始地址文件类型创建时间\n");for(;p!=NULL;p=p->next)printf("%s%d%d%s%s",p->file->fileName,p->file->maxlength,p->file->strat,p->file->fileKind,asctime(p->file->timeinfo));printf("********************************************************************************\n");system("pause");}}void diskShow()//显示磁盘使用情况{diskNode *p;int i=0,unusedDisk=0;printf("***************************************************************************\n");printf(" 盘块号起始地址容量(bit) 是否已被使用\n");for(p=diskHead;p!=NULL;p=p->next,i++){if(p->useFlag==false) unusedDisk+=p->maxlength;printf(" %d %d %d %d \n",i,p->start,p->maxlength,p->useFlag);}printf("***************************************************************************\n");printf("磁盘空间总容量:512*1024bit 已使用:%dbit 末使用:%dbit\n\n",MaxDisk-unusedDisk,unusedDisk);system("pause");}void fileClose(char fileName[])//关闭文件{UFD *p,*q;q=userTable[userID].user;for(p=q->next;p!=NULL;p=p->next){if(!strcmp(p->file->fileName,fileName))break;}if(p){p->file->openFlag=false;printf("%s文件已关闭\n",p->file->fileName);system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");}}心得体会在前面的实验中,已经积累了文件操作的逻辑,在反复修改和重新设计好数据结构后,写下了初步的操作函数,在完成了这些初步函数后,写好了主体框架,但在运行时发现了许多设计上的缺陷,常常出现没有考虑到的情况,程序的健壮性很低,在测试中不断地丰富函数和适当的修改数据结构使其适用于特殊情况,最后在测试无误后,开始添加其他的功能函数,使之能完成更多的功能。

操作系统课程设计文件管理二级文件系统

操作系统课程设计文件管理二级文件系统

本文档分别包含linux和windows两套程序目录一、课程设计的目的..........................二、课程设计的内容及要求...................内容..........................................要求..........................................三、实现原理.................................四、关键算法实现流程图 .....................流程图........................................关键算法......................................五、软件运行环境及限制 .....................六.结果输出及分析..........................七.心得体会.................................八.参考文献.................................一.课程设计的目的本课程设计是学习完《计算机操作系统》课程后,进行的一次全面的综合训练,通过课程设计,让我更好地掌握操作系统的原理及实现方法,加深对操作系统基础理论和重要算法的理解,加强了我的动手能力。

二.课程设计的内容及要求内容:为LINUX 设计一个简单的二级文件系统。

要求做到以下几点:1、可以实现下列几条命令(至少4条)。

Login 用户登录Dir 列文件目录Create 创建文件Delete 删除文件Open 打开文件Close 关闭文件Read 读文件Write 写文件2、列目录时要列出文件名、物理地址、保护码和文件长度。

3、源文件可以进行读写保护。

从课程设计的目的出发,通过设计工作的各个环节,达到以下教学要求:1、鼓励并优先个人独立选题设计,可从下面设计题目中选择,也可以自拟相关题目;如要合作,每组最多两名同学,且设计文档不能相同;2、可以在我们实验课最后布置的实验设计基础上进行完善和改进,但不能相同。

操作系统课程设计--二级文件系统(java)

操作系统课程设计--二级文件系统(java)

操作系统课程设计报告二级文件系统(java)姓名:李爱军班级:计091-2学号:200925501211指导教师:翟一鸣日期:2012-08-30目录一、实验目的 (3)二、实验内容 (3)三、实验过程 (3)四、设计思路 (4)五、实现的功能 (5)六、实验感悟 (5)附录:程序主要代码 (5)一、实验目的通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能及内部实现。

二、实验内容为linux系统设计一个简单的二级文件系统。

要求做到以下几点:1、可以实现下列几条命令(至少4条);login 用户登陆dir 列文件目录create 创建文件delete 删除文件open 打开文件close 关闭文件read 读文件write 写文件2、列目录时要列出文件名、物理地址、保护码和文件长度;3、源文件可以进行读写保护。

三、实验过程1、程序流程登录输入用户名用户存在进入目录管理注册否是用户登录流程 列文件目录流程2、主要类介绍(1)、public class Systems 文件系统的主类(2)、public class MyFile 自定义的文件结构体类(3)、public class MyDirectory 自定义的目录的结构体类(4)、public class SuperBlock implements Serializable 超级快结构体类 (5)、public class INode implements Serializable, Comparable<INode> 自定义INode 节点实体类(6)、public class FileTools 自定义数据文件的读写工具类四、设计思路1、一个磁盘的有扇区(超级块)、索引块区(Inode 节点区)、存储区(数据块区)2、扇区中主要是存储磁盘的总大小、空闲Inode 节点、使用的Inode 节点、已使用空间、列出目录文件读取文件展示文件完成是否当前用户文件否是空闲空间。

二级文件管理课程设计报告书

二级文件管理课程设计报告书

操作系统二级文件管理课程设计课程设计名称:二级文件管理系统专业班级:学生姓名:学号指导老师:一、设计目的通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能及内部实现。

二、设计内容为linux系统设计一个简单的二级文件系统。

要求做到以下几点:(1)可以实现下列几条命令(至少4条);login 用户登陆dir 列文件目录create 创建文件delete 删除文件open 打开文件close 关闭文件read 读文件write 写文件rename 重命名(2)列目录时要列出文件名、物理地址、保护码和文件长度;(3)源文件可以进行读写保护。

三、程序设计1、在内存中开辟一个虚拟磁盘空间作为文件存储器,在其上实现一个多用户多目录的文件系统。

2、文件物理结构可采用显式链接或其他方法。

3、磁盘空闲空间的管理可选择位示图或其他方法。

如果采用位示图来管理文件存储空间,并采用显式链接分配方式,则可以将位示图合并到FAT中。

4、文件目录结构采用多用户多级目录结构,每个目录项包含文件名、物理地址、长度等信息,还可以通过目录项实现对文件的读和写的保护。

5、设计一个较实用的用户界面,方便用户使用。

要求提供以下相关文件操作:用户登录、创建目录、删除目录、创建文件、删除文件、读文件、写文件、重命名、退出。

四、源代码1、FileSystem.h#define DIR_LENGTH 1024 //路径最长可达100字节#define MAX_WRITE 1024*128 //写入文字可达128k字节#define MEM_D_SIZE 1024*1024 //1M磁盘空间#define DISKSIZE 1024 //磁盘块的大小1K#define MSD 5 //最大子目录数5#define DISK_NUM MEM_D_SIZE/DISKSIZE //磁盘块数目1024=1M/1K #define FATSIZE DISK_NUM*sizeof(struct FatItem) //FAT表大小1024*8=8K#define MOFN 5 //最大文件打开数5#define ROOT_DISK_NO FATSIZE/DISKSIZE+1 //根目录起始盘块号9#define ROOT_DISK_SIZE sizeof(struct Direct) //根目录大小196#define LOGIN 15#define NAME_LONG 1#define NOT_EXSIT -1#define NOT_OPEN -1#define DIR_FULL -2#define OPEN_FULL -3#define ALREADY -4#define NOT_R_W -4#define DISK_FULL -5#define NOT_EXIT -1struct FatItem // size 8{ int item; //存放文件下一个磁盘的指针char em_disk; //磁盘块是否空闲标志位, 0 空闲};struct Direct{ struct FCB{ char name[8]; //文件/目录名8位char property; //属性1位目录0位普通文件int size; //文件/目录字节数、盘块数)int firstDisk; //文件/目录起始盘块号int next; //子目录起始盘块号int sign; //1是根目录0不是根目录}directItem[MSD+2]; //最大子目录 5};struct OpenTable{ struct OpenTableItem{ char name[9]; //文件名int firstdisk; //起始盘块号int size; //文件的大小char open_flag; //文件打开标志:'1':打开。

操作系统课程设计简单的二级文件系统

操作系统课程设计简单的二级文件系统

《操作系统》课程设计题目:设计一个简单二级文件系统专业:计算机科学与技术年级:文专计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根目录,为了解决这个问题,又在创建文件的程序里添加了一个判断是否为根目录的语句,可是后来又发现了真个系统存在重命名的问题。

操作系统的课程设计Linux二级文件资料系统设计完整篇.doc

操作系统的课程设计Linux二级文件资料系统设计完整篇.doc

操作系统的课程设计Linux二级文件资料系统设计1操作系统课程设计报告专业:软件工程学号:姓名:马提交日期:2017/1/10【设计目的】1、通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现2、结合数据结构、程序设计、计算机原理等课程的知识,设计一个二级文件系统,进一步理解操作系统3、通过对实际问题的分析、设计、编程实现,提高学生实际应用、编程的能力【设计内容】为Linux系统设计一个简单的二级文件系统。

要求做到以下几点:1.可以实现下列几条命令:login 用户登录dir 列目录create 创建文件delete 删除文件open 打开文件close 关闭文件read 读文件write 写文件cd 进出目录2.列目录时要列出文件名,物理地址,保护码和文件长度3.源文件可以进行读写保护【实验环境】C++DevCpp【设计思路】本文件系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件。

另外,为了简便文件系统未考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容。

首先应确定文件系统的数据结构:主目录、子目录及活动文件等。

主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。

用户创建的文件,可以编号存储于磁盘上。

如:file0,file1,file2…并以编号作为物理地址,在目录中进行登记。

结构体:typedef struct /*the structure of OSFILE*/{int fpaddr; /*file physical address*/int flength; /*file length*/int fmode; /*file mode:0-Read Only;1-Write Only;2-Read and Write; 3-Protect;*/char fname[MAXNAME]; /*file name*/} OSFILE; //存放重要信息typedef struct /*the structure of OSUFD*/{char ufdname[MAXNAME]; /*ufd name*/OSFILE ufdfile[MAXCHILD]; /*ufd own file*/}OSUFD; //用户下面的文件typedef struct /*the structure of OSUFD'LOGIN*/{char ufdname[MAXNAME]; /*ufd name*/char ufdpword[8]; /*ufd password*/} OSUFD_LOGIN;typedef struct /*file open mode*/{int ifopen; /*ifopen:0-close,1-open*/int openmode; /*0-read only,1-write only,2-read and write,3-initial*/ }OSUFD_OPENMODE;主要的函数说明:void LoginF(); /*LOGIN FileSystem用户登录*/void DirF(); /*Dir FileSystem列目录*/void CdF(); /*Change Dir改变目录*/void CreateF(); /*Create File创建文件*/void DeleteF(); /*Delete File删除文件*/void ModifyFM(); /*Modify FileMode修改*/void OpenF(); /*Open File打开文件*/void CloseF(); /*Close File关闭文件*/void ReadF(); /*Read File读文件*/void WriteF(); /*Write File写文件*/void QuitF(); /*Quit FileSystem离开文件系统*/void help();其他重要函数:void clrscr() //清屏int ExistD(char *dirname) /*Whether DirName Exist,Exist-i,Not Exist-0*/ int ExistF(char *filename) /*Whether FileName Exist,Exist-i,Not Exist-0*/ int FindPANo() /*find out physical address num*/void SetPANo(int RorW) /*Set physical address num,0-read,1-write*/void InputPW(char *password) /*input password,use '*' replace*/char *ltrim(char *str) /*remove the heading blanks.去除左空白*/char *rtrim(char *str) /*remove the trailing blanks.去除右空白*/int WriteF1() /*write file相当于置换文件*/程序流程说明:整体流程:各部分功能流程:Open:N NY操作系统的课程设计Linux二级文件资料系统设计1第2页【源程序清单】Open:void OpenF() /*Open File*/{printf("\n\nC:\\%s>",strupr(dirname)); //显示当前路径int fcoun, i; //定义两个整形变量char fname[MAXNAME], fmode[25]; //定义两个字符串变量int fmod; //文件模式printf("\nPlease input FileName:");gets(fname); //接收打开文件的文件名ltrim(rtrim(fname)); //去除左右空白if(ExistF(fname){ //不存在printf("\nError.文件名\'%s\'不存在\n", fname);wgetchar=1;} else { //存在i=ExistD(username); //获取用户物理信息for(int a=0; a {if(strcmp(fname, ufd[i]->ufdfile[a].fname)==0) //找到文件{fcoun=a;break;}}ifopen[i][fcoun].ifopen=1; //将文件状态置为打开状态printf("Please input OpenMode(0-Read Only, 1-Write Only, 2-Read and Write,3-Protect):");//打开文件模式gets(fmode); //获取模式fmod=atoi(fmode); //将字符串转换为整型ifopen[i][fcoun].openmode=fmod; //将文件的模式置为OpenModeprintf("\nOpen Successed");wgetchar=1;}}Delete:void DeleteF() /*Delete File*/{printf("\n\nC:\\%s>",strupr(dirname)); //显示路径char fname[MAXNAME], str[50], str1[50]; //定义三个字符串变量int i, k, j;int fpaddrno1; //记录文件物理地址块号if(strcmp(strupr(ltrim(rtrim(dirname))), "")==0){ //判断主目录是否为空printf("\nError.请确认您要删除的是否在用户目录下!\n");wgetchar=1;}if(strcmp(strupr(dirname), strupr(username))!=0){ //判断用户是否在用户目录下printf("\nError.您只能删除修改自己用户目录下的文件哦!\n");wgetchar=1;} else {printf("\nPlease input FileName:");gets(fname); //接收删除的文件名ltrim(rtrim(fname)); //去除文件名的左右空白i=ExistF(fname); //用户文件位置if(i>=0){k=ExistD(username); //获取用户所在存储位置if(ifopen[k][i].ifopen==1){//文件状态处于打开状态,不许删除printf("\n Error.\'%s\' 处于打开状态!请先关闭哟!\n", fname); wgetchar=1;} else {if(ufd[k]->ufdfile[i].fmode==3){ //保护文件,不可删除printf("\nError.\'%s\'处于被保护状态!请先关闭哟!\n", fname);wgetchar=1;} else {fpaddrno1=ufd[k]->ufdfile[i].fpaddr; //获取文件的物理地址块号fpaddrno[fpaddrno1]=0; //回收物理地址块号for(j=i; jufd[k]->ufdfile[j]=ufd[k]->ufdfile[j+1]; //将j+1位置为j}strcpy(str , "c:\\osfile\\file\\");itoa(fpaddrno1, str1, 10); //将整数转化为字符串strcat(str, str1);strcat(str, ".txt"); //连接remove(str); //删除物理文件fcount[k--]; //文件个数减一。

操作系统课程设计--二级文件系统设计

操作系统课程设计--二级文件系统设计

操作系统课程设计报告专业:学号:姓名:提交日期:【设计题目】二级文件系统设计【设计目的】1、本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现。

2、结合数据结构、程序设计、计算机原理等课程的知识,设计一个二级文件系统,进一步理解操作系统。

3、通过分对实际问题的分析、设计、编程实现,提高学生实际应用、编程的能力.【设计内容】一、任务为Linux系统设计一个简单的二级文件系统。

要求做到以下几点:1.可以实现下列几条命令:login 用户登录dir 列目录create 创建文件delete 删除文件open 打开文件close 关闭文件read 读文件write 写文件cd 进出目录2.列目录时要列出文件名,物理地址,保护码和文件长度3.源文件可以进行读写保护二、程序设计设计思想本文件系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件。

另外,为了简便文件系统未考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容。

首先应确定文件系统的数据结构:主目录、子目录及活动文件等。

主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。

用户创建的文件,可以编号存储于磁盘上。

如:file0,file1,file2…并以编号作为物理地址,在目录中进行登记【实验环境】C++/VC++【设计原理】对采用二级文件目录的文件系统工作的机理了如指掌,对文件系统的相关操作要掌握。

【设计思路】1. 主要数据结构#define MAXNAME 25 /*the largest length of mfdname,ufdname,filename*/#define MAXCHILD 50 /*the largest child每个用户名下最多有50个文件*/#define MAX (MAXCHILD*MAXCHILD) /*the size of fpaddrno*/typedef struct/*the structure of OSFILE定义主文件*/{int fpaddr; /*file physical address*/int flength; /*file length*/int fmode; /*file mode:0-Read Only;1-Write Only;2-Read and Write; 3-Protect;*/ char fname[MAXNAME]; /*file name*/} OSFILE;typedef struct/*the structure of OSUFD定义用户文件目录*/{char ufdname[MAXNAME]; /*ufd name*/OSFILE ufdfile[MAXCHILD]; /*ufd own file*/}OSUFD;typedef struct/*the structure of OSUFD'LOGIN定义登陆*/{char ufdname[MAXNAME]; /*ufd name*/char ufdpword[8]; /*ufd password*/} OSUFD_LOGIN;typedef struct/*file open mode定义操作方式*/{int ifopen; /*ifopen:0-close,1-open*/int openmode; /*0-read only,1-write only,2-read and write,3-initial*/}OSUFD_OPENMODE;2.主要函数void LoginF(); /*LOGIN FileSystem*/void DirF(); /*Dir FileSystem*/void CreateF(); /*Create File*/void DeleteF(); /*Delete File*/void ModifyFM(); /*Modify FileMode*/void OpenF(); /*Open File*/void CloseF(); /*Close File*/void ReadF(); /*Read File*/void WriteF(); /*Write File*/void QuitF(); /*Quit FileSystem*/void CdF(); /*Change Dir*/void help();3.程序流程设计总体功能程序结构图打开命令的程序流程图删除命令的程序流程图关闭命令的程序流程图写命令的程序流程图【源程序清单】#include "stdio.h"#include "string.h"#include "conio.h"#include "stdlib.h"#define MAXNAME 25 /*the largest length of mfdname,ufdname,filename*/#define MAXCHILD 50 /*the largest child*/#define MAX (MAXCHILD*MAXCHILD) /*the size of fpaddrno*/typedef struct /*the structure of OSFILE*/{int fpaddr; /*file physical address*/int flength; /*file length*/int fmode; /*file mode:0-Read Only;1-Write Only;2-Read and Write; 3-Protect;*/ char fname[MAXNAME]; /*file name*/} OSFILE;typedef struct /*the structure of OSUFD*/{char ufdname[MAXNAME]; /*ufd name*/OSFILE ufdfile[MAXCHILD]; /*ufd own file*/}OSUFD;typedef struct /*the structure of OSUFD'LOGIN*/{char ufdname[MAXNAME]; /*ufd name*/char ufdpword[8]; /*ufd password*/} OSUFD_LOGIN;typedef struct /*file open mode*/{int ifopen; /*ifopen:0-close,1-open*/int openmode; /*0-read only,1-write only,2-read and write,3-initial*/}OSUFD_OPENMODE;OSUFD *ufd[MAXCHILD]; /*ufd and ufd own files*/OSUFD_LOGIN ufd_lp;int ucount=0; /*the count of mfd's ufds*/int fcount[MAXCHILD]; /*the count of ufd's files*/int loginsuc=0; /*whether login successfully*/char username[MAXNAME]; /*record login user's name22*/char dirname[MAXNAME];/*record current directory*/int fpaddrno[MAX]; /*record file physical address num*/OSUFD_OPENMODE ifopen[MAXCHILD][MAXCHILD]; /*record file open/close*/ int wgetchar; /*whether getchar()*/FILE *fp_mfd,*fp_ufd,*fp_file_p,*fp_file;void LoginF(); /*LOGIN FileSystem*/void DirF(); /*Dir FileSystem*/void CdF(); /*Change Dir*/void CreateF(); /*Create File*/void DeleteF(); /*Delete File*/void ModifyFM(); /*Modify FileMode*/void OpenF(); /*Open File*/void CloseF(); /*Close File*/void ReadF(); /*Read File*/void WriteF(); /*Write File*/void QuitF(); /*Quit FileSystem*/void help();char *rtrim(char *str); /*remove the trailing blanks.*/char *ltrim(char *str); /*remove the heading blanks.*/void InputPW(char *password); /*input password,use '*' replace*/void SetPANo(int RorW); /*Set physical address num*/int ExistD(char *dirname); /*Whether DirName Exist,Exist-i,Not Exist-0*/int WriteF1(); /*write file*/int ExistF(char *filename); /*Whether FileName Exist,Exist-i,Not Exist-0*/int FindPANo(); /*find out physical address num*/void clrscr(){system("cls");}void main(){int i,choice1;char choice[50]; /*choice operation:dir,create,delete,open,delete,modify,read,write*/ int choiceend=1; /*whether choice end*/char *rtrim(char *str); /*remove the trailing blanks.*/char *ltrim(char *str); /*remove the heading blanks.*/if((fp_mfd=fopen("c:\\osfile\\mfd.txt","rb"))==NULL){fp_mfd=fopen("c:\\osfile\\mfd.txt","wb");fclose(fp_mfd);}for(i=0;i<MAX;i++) fpaddrno[i]=0;//textattr(BLACK*16|WHITE);clrscr(); /*clear screen*/LoginF(); /*user login*/clrscr();if(loginsuc==1) /*Login Successfully*/{while (1){wgetchar=0;if (choiceend==1)printf("\n\nC:\\%s>",strupr(dirname));elseprintf("Bad command or file name.\nC:\\%s>",strupr(username));gets(choice);strcpy(choice,ltrim(rtrim(strlwr(choice))));if (strcmp(choice,"dir")==0) choice1=1;else if(strcmp(choice,"create")==0) choice1=2;else if(strcmp(choice,"delete")==0) choice1=3;else if(strcmp(choice,"attrib")==0) choice1=4;else if(strcmp(choice,"open")==0) choice1=5;else if(strcmp(choice,"close")==0) choice1=6;else if(strcmp(choice,"read")==0) choice1=7;else if(strcmp(choice,"write")==0) choice1=8;else if(strcmp(choice,"exit")==0) choice1=9;else if(strcmp(choice,"cls")==0) choice1=10;else if(strcmp(choice,"cd")==0) choice1=11;else if(strcmp(choice,"help")==0) choice1=20;else choice1=12;switch(choice1){case 1:DirF();choiceend=1;break;case 2:CreateF();choiceend=1;if(!wgetchar) getchar();break;case 3:DeleteF();choiceend=1;if(!wgetchar)getchar();break;case 4:ModifyFM();choiceend=1;if(!wgetchar) getchar();break;case 5:OpenF();choiceend=1;if (!wgetchar) getchar();break;case 6:CloseF();choiceend=1;if (!wgetchar) getchar();break;case 7:ReadF();choiceend=1;if (!wgetchar) getchar();break;case 8:WriteF();choiceend=1;if (!wgetchar) getchar();break;case 9:printf("\nYou have exited this system.");QuitF();exit(0);break;case 10:clrscr();choiceend=1;break;case 11:CdF();choiceend=1;break;case 20:help();choiceend=1;break;default:choiceend=0;}}}elseprintf("\nAccess denied.");}void help(void){printf("\nThe Command List\n");printf("\nCd Attrib Create write Read Open Cls Delete Exit Close\n");}char *rtrim(char *str) /*remove the trailing blanks.*/{int n=strlen(str)-1;while(n>=0){if(*(str+n)!=' '){*(str+n+1)='\0';break;}else n--;}if (n<0) str[0]='\0';return str;}char *ltrim(char *str) /*remove the heading blanks.*/{strrev(str);rtrim(str);strrev(str);return str;}void LoginF() /*LOGIN FileSystem*/{char loginame[MAXNAME],loginpw[9],logincpw[9],str[50];int i,j,flag=1;char a[25];int findout; /*login user not exist*/while(1){findout=0;printf("\n\nLogin Name:");gets(loginame);ltrim(rtrim(loginame));fp_mfd=fopen("c:\\osfile\\mfd.txt","rb");for(i=0;fread(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd)!=0;i++) if (strcmp(strupr(ufd_lp.ufdname),strupr(loginame))==0){findout=1;strcpy(logincpw,ufd_lp.ufdpword);}fclose(fp_mfd);if (findout==1) /*user exist*/{printf("Login Password:");InputPW(loginpw); /*input password,use '*' replace*/if (strcmp(loginpw,logincpw)==0){strcpy(username,strupr(loginame));strcpy(dirname,username);fp_mfd=fopen("c:\\osfile\\mfd.txt","rb");for(j=0;fread(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd)!=0;j++){strcpy(str,"c:\\osfile\\");strcat(str,ufd_lp.ufdname);strcat(str,".txt");ufd[j]=(OSUFD*)malloc(sizeof(OSUFD));strcpy(ufd[j]->ufdname,strupr(ufd_lp.ufdname));fp_ufd=fopen(str,"rb");fcount[j]=0;for(i=0;fread(&ufd[j]->ufdfile[i],sizeof(OSFILE),1,fp_ufd)!=0;i++,fcount[j]++){ifopen[j][i].ifopen=0;ifopen[j][i].openmode=4;}fclose(fp_ufd);}fclose(fp_mfd);ucount=j;SetPANo(0);printf("\n\nLogin successful! Welcome to this FileSystem\n\n");loginsuc=1;return;}else{printf("\n\n");flag=1;while(flag){printf("Login Failed! Password Error. Try Again(Y/N):");gets(a);ltrim(rtrim(a));if (strcmp(strupr(a),"Y")==0){loginsuc=0;flag=0;}else if(strcmp(strupr(a),"N")==0){loginsuc=0;flag=0;return;}}}}else{printf("New Password(<=8):");InputPW(loginpw); /*input new password,use '*' replace*/printf("\nConfirm Password(<=8):"); /*input new password,use '*' replace*/ InputPW(logincpw);if (strcmp(loginpw,logincpw)==0){strcpy(ufd_lp.ufdname,strupr(loginame));strcpy(ufd_lp.ufdpword,loginpw);fp_mfd=fopen("c:\\osfile\\mfd.txt","ab");fwrite(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd);fclose(fp_mfd);strcpy(username,strupr(loginame));strcpy(dirname,loginame);////////////////////////////////////////////////////////strcpy(str,"c:\\osfile\\");strcat(str,username);strcat(str,".txt");if((fp_ufd=fopen(str,"rb"))==NULL){fp_ufd=fopen(str,"wb");fclose(fp_ufd);}fp_mfd=fopen("c:\\osfile\\mfd.txt","rb");for(j=0;fread(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd)!=0;j++){/////////////////////////////////////strcpy(str,"c:\\osfile\\");strcat(str,ufd_lp.ufdname);strcat(str,".txt");ufd[j]=(OSUFD*)malloc(sizeof(OSUFD));strcpy(ufd[j]->ufdname,strupr(ufd_lp.ufdname));fp_ufd=fopen(str,"rb");for(i=0;fread(&ufd[j]->ufdfile[i],sizeof(OSFILE),1,fp_ufd)!=0;i++,fcount[j]++) {ifopen[j][i].ifopen=0;ifopen[j][i].openmode=4;}fclose(fp_ufd);}fclose(fp_mfd);ucount=j;SetPANo(0);printf("\n\nLogin Successful! Welcome to this System\n\n");loginsuc=1;return;}else{printf("\n\n");flag=1;while(flag){printf("Login Failed! Password Error. Try Again(Y/N):");gets(a);ltrim(rtrim(a));if (strcmp(strupr(a),"Y")==0){loginsuc=0;flag=0;}else if(strcmp(strupr(a),"N")==0){loginsuc=0;flag=0;return;}}}}}}void SetPANo(int RorW) /*Set physical address num,0-read,1-write*/ {int i,j;if (RorW==0){if((fp_file_p=fopen("c:\\osfile\\file\\file_p.txt","rb"))==NULL){fp_file_p=fopen("c:\\osfile\\file\\file_p.txt","wb");fclose(fp_file_p);}fp_file_p=fopen("c:\\osfile\\file\\file_p.txt","rb");///////////////////////////////////////////////////////////////////for(i=0;fread(&j,sizeof(int),1,fp_file_p)!=0;i++)fpaddrno[j]=1;/*for(i=1;i<MAX;i++)if ((i%13)==0)fpaddrno[i]=1;*/}else{fp_file_p=fopen("c:\\osfile\\file\\file_p.txt","wb");/*for(i=1;i<MAX;i++)if((i%13)==0)fpaddrno[i]=0;*/for(i=0;i<MAX;i++)if (fpaddrno[i]==1)fwrite(&i,sizeof(int),1,fp_file_p);}fclose(fp_file_p);}void InputPW(char *password) /*input password,use '*' replace*/ {int j;for(j=0;j<=7;j++){password[j]=getch();if ((int)(password[j])!=13){if((int)(password[j])!=8)putchar('*');else{if (j>0){j--;j--;putchar('\b');putchar(' ');putchar('\b');}else j--;}}else{ password[j]='\0';break;}}password[j]='\0';}void DirF() /*Dir FileSystem*/{int i,j,count=0;char sfmode[25],sfpaddr[25],str[25];clrscr();if (strcmp(strupr(ltrim(rtrim(dirname))),"")!=0){printf("\n\nC:\\%s>dir\n",dirname);printf("\n%14s%16s%14s%10s%18s\n","FileName","FileAddress","FileLength","Type","Fil eMode");j=ExistD(dirname);for(i=0;i<fcount[j];i++){if ((i%16==0)&&(i!=0)){printf("\nPress any key to continue..");getch();clrscr();printf("\n%14s%16s%14s%10s%18s\n","FileName","FileAddress","FileLength","Type","Fil eMode");}/////////////////////////////////////////////////////////itoa(ufd[j]->ufdfile[i].fpaddr,str,10);strcpy(sfpaddr,"file");strcat(sfpaddr,str);if (ufd[j]->ufdfile[i].fmode==0) strcpy(sfmode,"Read Only");else if(ufd[j]->ufdfile[i].fmode==1) strcpy(sfmode,"Write Only");else if(ufd[j]->ufdfile[i].fmode==2)strcpy(sfmode,"Read And Write");else strcpy(sfmode,"Protect");printf("%14s%16s%14d%10s%18s\n",ufd[j]->ufdfile[i].fname,sfpaddr,ufd[j]->ufdfile[i].flen gth,"<FILE>",sfmode);}printf("\n %3d file(s)\n",fcount[j]);}else{printf("\n\nC:\\>dir\n");printf("\n%14s%18s%8s\n","DirName","OwnFileCount","Type");for(i=0;i<ucount;i++){if ((i%16==0)&&(i!=0)){printf("\nPress any key to continue...");getch();clrscr();printf("\n%14s%18s%8s\n","DirName","OwnFileCount","Type");}printf("%14s%18d%8s\n",ufd[i]->ufdname,fcount[i],"<UFD>");count=count+fcount[i];}printf("\n %3d dir(s),%5d file(s)\n",ucount,count);}}int ExistD(char *dirname) /*Whether DirName Exist,Exist-i,Not Exist-0*/{int i;int exist=0;for(i=0;i<ucount;i++)if (strcmp(strupr(ufd[i]->ufdname),strupr(dirname))==0)exist=1;break;}if (exist) return(i);else return(-1);}void CdF() /*Exchange Dir*/{char dname[MAXNAME];printf("\nPlease input DirName (cd..-Previous dir; DirNAME-cd [DirNAME]):");gets(dname);ltrim(rtrim(dname));if (ExistD(dname)>=0) strcpy(dirname,strupr(dname));elseif(strcmp(strupr(dname),"CD..")==0) strcpy(ltrim(rtrim(dirname)),"");else printf("\nError.\'%s\' does not exist.\n",dname);}void CreateF() /*Create File*/{int fpaddrno,flag=1,i;char fname[MAXNAME],str[50],str1[50],a[25];char fmode[25];if (strcmp(strupr(dirname),strupr(username))!=0){printf("\nError. You must create file in your own dir.\n");wgetchar=1;}else{printf("\nPlease input FileName:");gets(fname);ltrim(rtrim(fname));if (ExistF(fname)>=0){printf("\nError. Name \'%s\' has already existed.\n",fname);wgetchar=1;}elseprintf("Please input FileMode(0-Read Only, 1-Write Only, 2-Read and Write,3-Protect):");gets(fmode);ltrim(rtrim(fmode));if((strcmp(fmode,"0")==0)||(strcmp(fmode,"1")==0)||(strcmp(fmode,"2")==0)||(strcmp(fmode ,"3")==0)){fpaddrno=FindPANo();if (fpaddrno>=0){i=ExistD(username);strcpy(ufd[i]->ufdfile[fcount[i]].fname,fname);ufd[i]->ufdfile[fcount[i]].fpaddr=fpaddrno;ufd[i]->ufdfile[fcount[i]].fmode=atoi(fmode);ifopen[i][fcount[i]].ifopen=0;ifopen[i][fcount[i]].openmode=4;strcpy(str,"c:\\osfile\\file\\file");itoa(fpaddrno,str1,10);strcat(str,str1);strcat(str,".txt");fp_file=fopen(str,"wb");fclose(fp_file);fcount[i]++;while(flag){printf("Input text now(Y/N):");gets(a);ltrim(rtrim(a));ufd[i]->ufdfile[fcount[i]-1].flength=0;if(strcmp(strupr(a),"Y")==0){fp_file=fopen(str,"wb+");ufd[i]->ufdfile[fcount[i]-1].flength=WriteF1();flag=0;}else if(strcmp(strupr(a),"N")==0){flag=0;wgetchar=1;}}printf("\n\'%s\' has been created successfully!\n",fname);}else{printf("\nFail!No Disk Space. Please format your disk.\n");wgetchar=1;}}else{printf("\nError. FileMode\'s Range is 0-3\n");wgetchar=1;}}}}int ExistF(char *filename) /*Whether FileName Exist,Exist-i,Not Exist-0*/{int i,j;int exist=0;j=ExistD(dirname);for(i=0;i<fcount[j];i++)if (strcmp(strupr(ufd[j]->ufdfile[i].fname),strupr(filename))==0){exist=1;break;}if (exist) return(i);else return(-1);}int FindPANo() /*find out physical address num*/{int i;for(i=0;i<MAX;i++)if (fpaddrno[i]==0){fpaddrno[i]=1;break;}if (i<MAX) return(i);else return(-1);}int WriteF1() /*write file*/{int length=0;char c;printf("Please input text(\'#\' stands for end):\n");while((c=getchar())!='#'){fprintf(fp_file,"%c",c);if (c!='\n') length++;}fprintf(fp_file,"\n");fclose(fp_file);return(length);}void DeleteF() /*Delete File*/{ char fname[MAXNAME],str[50],str1[50];int i,k,j;int fpaddrno1; //文件物理地址if (strcmp(strupr(ltrim(rtrim(dirname))),"")==0) /*无法删除主目录的文件*/{printf("\nError.Please convert to ufd dir before delete.\n");wgetchar=1;}if (strcmp(strupr(dirname),strupr(username))!=0) /*无法删除不是自己目录的文件*/ {printf("\nError.You can only modify filemode in yourself dir.\n");wgetchar=1;}else{printf("\nPlease input FileName:");gets(fname);//从键盘获取所要删除的文件名ltrim(rtrim(fname));//去掉文件名头尾的空格i=ExistF(fname);//获取文件编号if (i>=0){k=ExistD(username);//获取用户名if(ifopen[k][i].ifopen==1)/*文件打开时无法删除*/{printf("\nError.\'%s\' is in open status. Close it before delete.\n",fname);wgetchar=1;}else{if(ufd[k]->ufdfile[i].fmode==3)/*被保护的文件无法删除*/{printf("\nError.\'%s\' is in protect status. Close it before delete.\n",fname);wgetchar=1;}else{fpaddrno1=ufd[k]->ufdfile[i].fpaddr;//获取文件对应的物理文件名fpaddrno[fpaddrno1]=0;//回收盘块for(j=i;j<fcount[k];j++){ufd[k]->ufdfile[j]=ufd[k]->ufdfile[j+1];//从被删除的文件号开始,数组值全部前移一个}strcpy(str,"d:\\osfile\\file\\file");itoa(fpaddrno1,str1,10);//整数转化成字符串strcat(str,str1); //把str1添加到str结尾处strcat(str,".txt"); //把.txt添加到str结尾处remove(str);//删除物理文件fcount[k]--;//k用户文件数量少1printf("\n \'%s\'is deleted successfully.\n",fname);wgetchar=1;}}}else//所要删除的文件不存在{printf("\nError. \'%s\' dose not exist.\n",fname);wgetchar=1;}}}void ModifyFM() /*Modify FileMode*/{char fname[MAXNAME],str[50];int i,k;char fmode[25]; /*whether delete*/if (strcmp(strupr(dirname),strupr(username))!=0){printf("\nError.You can only modify filemode in yourself dir.\n");wgetchar=1;}else{printf("\nPlease input FileName:");gets(fname);ltrim(rtrim(fname));i=ExistF(fname);if (i>=0){k=ExistD(username);if(ifopen[k][i].ifopen==1){printf("\nError.\'%s\' is in open status. Close it before modify.\n",fname);wgetchar=1;}else{if(ufd[k]->ufdfile[i].fmode==0) strcpy(str,"read only"); /*FileMode*/else if(ufd[k]->ufdfile[i].fmode==1) strcpy(str,"write only");else if(ufd[k]->ufdfile[i].fmode==2) strcpy(str,"read and write");else strcpy(str,"Protect");printf("\'%s\' filemode is %s.\n",fname,strupr(str));printf("Modify to(0-read only,1-write only,2-read and write,3-Protect):");gets(fmode);ltrim(rtrim(fmode));if(strcmp(fmode,"0")==0){ufd[k]->ufdfile[i].fmode=0;printf("\n\'%s\' has been modified to READ ONL Y mode successfully.\n",fname);wgetchar=1;}else if(strcmp(fmode,"1")==0){ufd[k]->ufdfile[i].fmode=1;printf("\n\'%s\' has been modified to WRITE ONL Y mode successfully.\n",fname);wgetchar=1;}else if(strcmp(fmode,"2")==0){ufd[k]->ufdfile[i].fmode=2;printf("\n\'%s\' has been modified to READ AND WRITE mode successfully.\n",fname);wgetchar=1;}else if(strcmp(fmode,"3")==0){ufd[k]->ufdfile[i].fmode=3;printf("\n\'%s\' has been modified to FORBID mode successfully.\n",fname);wgetchar=1;}else{printf("\nError.\'%s\' is not modified.\n",fname);wgetchar=1;}}}else{printf("\nError. \'%s\' dose not exist.\n",fname);wgetchar=1;}}}void OpenF() /*Open File*/{char fname[MAXNAME];int i,k,j;if (strcmp(strupr(dirname),strupr(username))!=0) /*在自己的目录里才能打开*/ {printf("\nError.You can only open in yourself dir.\n");wgetchar=1;}else{k=ExistD(username); //获取用户名for(j=0;j<fcount[k];j++){printf("%15s",ufd[k]->ufdfile[j].fname); //输出文件名}printf("\nPlease input FileName:");gets(fname);//获取所要打开的文件名ltrim(rtrim(fname));//去掉文件名头尾的空格i=ExistF(fname);//获取文件编号if (i>=0){if(ifopen[k][i].ifopen==1)//输入的文件是打开的{printf("\nError.\'%s\' is in open status.\n",fname);wgetchar=1;}else{ifopen[k][i].ifopen=1;//修改为打开的if(ufd[k]->ufdfile[i].fmode==0)/*根据文件的模式设置打开模式*/{ ifopen[k][i].openmode=0;}else if(ufd[k]->ufdfile[i].fmode==1){ifopen[k][i].openmode=1;}else if(ufd[k]->ufdfile[i].fmode==2){ifopen[k][i].openmode=2;}else ifopen[k][i].openmode=3;printf("\n\'%s\' is opened successfully\n",fname);wgetchar=1;}}else//文件不存在{printf("\nError. \'%s\' dose not exist.\n",fname);wgetchar=1;}}}void CloseF() /*Close File*/{char fname[MAXNAME];int i,k,j;if (strcmp(strupr(dirname),strupr(username))!=0) /*不在自己的目录里没法进行*/ {printf("\nError.You can only close file in yourself dir.\n");wgetchar=1;}else{k=ExistD(username); //获取用户名for(j=0;j<fcount[k];j++)/*列出已经打开的文件*/{if(ifopen[k][j].ifopen==1)//如果文件是打开的printf("%15s",ufd[k]->ufdfile[j].fname);}printf("\nPlease input FileName:");gets(fname);//从键盘上读入所要关闭的文件ltrim(rtrim(fname));//去掉文件名头尾的空格i=ExistF(fname);//获取文件编号if (i>=0){ifopen[k][i].ifopen=0;/*关闭文件*/printf("\n \'%s\' closed successfully\n",fname);wgetchar=1;}else//所要关闭的文件不存在{printf("\nError. \'%s\' dose not exist.\n",fname);wgetchar=1;}}}void ReadF() /*Read File*/{int i,k,n=0;char fname[MAXNAME];char str[255],str1[255],c;if (strcmp(strupr(ltrim(rtrim(dirname))),"")==0){printf("\nError.Please convert to ufd dir before read.\n");wgetchar=1;return;}printf("\nCaution:Open file first\n");printf("Opened File(s) List:\n");k=ExistD(dirname);for(i=0;i<fcount[k];i++){if (ifopen[k][i].ifopen==1)if ((ifopen[k][i].openmode==0) ||(ifopen[k][i].openmode==2)){printf("%15s",ufd[k]->ufdfile[i].fname);n++;}if((n%4==0)&&(n!=0)) printf("\n");}printf("\n%d files openned.\n",n);if (n==0) wgetchar=1;if(n!=0){printf("\nPlease input FileName:");gets(fname);ltrim(rtrim(fname));i=ExistF(fname);if(i>=0){if(ifopen[k][i].ifopen==1){if((ifopen[k][i].openmode==0) ||(ifopen[k][i].openmode==2)){itoa(ufd[k]->ufdfile[i].fpaddr,str,10);strcpy(str1,"file");strcat(str1,str);strcpy(str,"c:\\osfile\\file\\");strcat(str,str1);strcat(str,".txt");fp_file=fopen(str,"rb");fseek(fp_file,0,0);printf("\nThe text is:\n\n");printf(" ");while(fscanf(fp_file,"%c",&c)!=EOF)if (c=='\n') printf("\n ");else printf("%c",c);printf("\n\n%d Length.\n",ufd[k]->ufdfile[i].flength);fclose(fp_file);wgetchar=1;}else{printf("\nError.\'%s\' has been opened with WRITE ONLY mode. It isn\'t read.\n",fname);wgetchar=1;}}else{printf("\nError.\'%s\' is in closing status. Please open it before read\n",fname);wgetchar=1;}}else{printf("\nError. \'%s\' does not exist.\n",fname);wgetchar=1;}}}void WriteF() /*Write File*/{int i,k,n=0;int length;char fname[MAXNAME];char str[255],str1[255];if (strcmp(strupr(dirname),strupr(username))!=0) //只能写自己目录下的文件{printf("\nError.Please convert to ufd dir before write.\n");wgetchar=1;return;}printf("\nCaution:Open file first\n");printf("Opened File(s) List:\n");k=ExistD(dirname);//获取目录编号for(i=0;i<fcount[k];i++)/*列出可以写的文件*/{if(ifopen[k][i].ifopen==1)//如果文件是打开的{printf("%15s",ufd[k]->ufdfile[i].fname);n++;}if((n%4==0)&&(n!=0)) printf("\n");}printf("\n%d files openned.\n",n);if (n==0) wgetchar=1;//没有打开的文件if(n!=0){printf("\nPlease input FileName:");gets(fname);//从键盘获取所要写的文件ltrim(rtrim(fname));//去掉文件名头尾的空格i=ExistF(fname);//获取文件编号if(i>=0){if(ifopen[k][i].ifopen==1)//如果文件是打开的{if((ifopen[k][i].openmode==1) ||(ifopen[k][i].openmode==2))//文件是只写,或者是可读可写的{itoa(ufd[k]->ufdfile[i].fpaddr,str,10);//获取文件对应的物理地址strcpy(str1,"file");strcat(str1,str);strcpy(str,"c:\\osfile\\file\\");strcat(str,str1);strcat(str,".txt");fp_file=fopen(str,"ab");//以二进制只写的形式打开,每次将内容添加到文件末尾接着上一次内容length=WriteF1(); //写入并获得长度ufd[k]->ufdfile[i].flength=ufd[k]->ufdfile[i].flength+length;//计算总长度printf("\n\n%d Length.\n",ufd[k]->ufdfile[i].flength);printf("\n\nYou have write file successfully!!");fclose(fp_file);wgetchar=0;}else if(ifopen[k][i].openmode==0)//文件是只读的{printf("\nError.\'%s\' has been opened with READ ONL Y mode. It isn\'t write.\n",fname);wgetchar=1;}else//文件是保护的{printf("\nError.\'%s\' has been opened with PROTECT mode. It isn\'t write.\n",fname);wgetchar=1;}}else //文件是关闭的{printf("\nError.\'%s\' is in closing status. Please open it before write\n",fname);wgetchar=1;。

操作系统课程设计Linux二级文件系统设计

操作系统课程设计Linux二级文件系统设计

操作系统课程设计 - Linux二级文件系统设计1. 介绍本文档旨在描述操作系统课程的设计内容,具体地,是讲解如何设计一个Linux二级文件系统。

本文档将分别从整体架构、数据结构和算法、API设计以及测试等方面进行阐述。

2. 整体架构Linux二级文件系统的整体架构如下图所示:+-----------+ +-----------------------+| | | || VFS | -> | 具体的文件系统实现 || | | |+-----------+ +-----------------------+其中,VFS(Virtual File System)是Linux内核中的虚拟文件系统,为所有文件系统提供了一个统一的访问接口。

具体的文件系统实现则是针对具体的文件系统类型而定制的,例如ext4、NTFS等。

3. 数据结构和算法Linux二级文件系统设计中,最核心的问题是如何组织文件和目录。

在Linux 中,文件和目录都是通过inode(索引节点)来表示的。

每一个inode都包含了文件或目录的属性(如文件类型、访问权限、文件大小等)以及指向文件数据块的指针。

因此,在设计文件系统时,需要考虑如何合理地组织inode,以实现高效的文件访问。

常用的文件组织方式有:•线性组织:将所有的inode按顺序存储在磁盘上,文件数据也按照顺序存储在相邻的磁盘块中。

这种方式的优点是简单直接,缺点则是容易产生磁盘碎片,导致文件访问效率低下。

•索引结构:为文件增加一个索引块,将文件数据块的指针存储在索引块中。

这种方式的优点是磁盘利用率高,易于维护,但对于小文件来说,可能会造成内存浪费。

在具体实现时,需要根据实际的场景来选择不同的数据结构和算法。

例如,对于大型多媒体文件,可以采用多级索引结构,以提高数据访问效率。

4. API设计设计好数据结构和算法后,就需要考虑如何提供统一的API接口给应用程序使用。

一个好的API设计需要考虑多方面的因素,例如易用性、可扩展性、安全性等。

闽 南 师 范 大 学 操作系统课程设计 模拟一个简单二级文件管理系统

闽 南 师 范 大 学 操作系统课程设计     模拟一个简单二级文件管理系统

闽南师范大学操作系统课程设计模拟一个简单二级文件管理系统姓名:学号:系别:计算机学院专业:网络工程年级:指导教师:全秀祥、闫格年月日一、课程设计项目介绍项目介绍:通过研究Linux的文件系统结构,模拟设计一个简单二级文件管理系统,第一级为主目录文件,第二级为用户文件。

磁盘空间分配表,采用链表结构,每个节点保存成模拟磁盘的一个逻辑块的信息,包括块的最大长度,文件占用长度,占用标志。

如果占用标志为0,即该空间可分配给文件。

初始化磁盘空间分配表链表,首先把整个模拟磁盘作为一块,并置占用位为0。

当有进程申请磁盘空间时,从头开始遍历,检查占用位,如果该块可分配,则检查块大小,若块长度大于或等于申请空间大小,则把块的前一部分(等于申请大小)分配给文件,并置标志位为占用。

剩下的大小作为一个新块,作为一个新节点插入到节点的后边,标志位为可用。

这样就实现了模拟磁盘的线性分配。

设计目的:通过具体的文件存储空间的管理、文件的物理结构、目录结构和文件操作的实现,加深对文件系统内部功能和实现过程的理解。

进行操作系统课程设计主要是在学习操作系统课程的基础上,在完成操作系统各部分实验的基础上,对操作系统的整体进行一个人模拟,通过实践加深对各个部分的管理功能的认识,还能进一步分析各个部分之间的联系,最后达到对完整系统的理解。

同时,可以提高运用操作系统知识解决实际问题的能力,锻炼实际的编程能力,创新能力及团队组织、协作开发软件的能力,还能提高调查研究,查阅技术文献,资料以及编写软件设计文档的能力。

通过编程实现这些算法,更好地掌握了操作系统的原理及实现方法,提高综合运用各专业课知识的能力,掌握操作系统结构、实现机理和各种典型算法,系统地了解操作系统地设计和实现思路,并了解操作系统的发展动向和趋势。

最重要的是,能提高自己实际动手操作能力和独立思考能力,让我们受益匪浅。

二、总体设计此二级文件管理系统包含的功能包括:登录到文件管理系统,创建文件,打开文件,关闭文件,删除文件,写文件,读文件,创建目录,删除目录,修改目录表,显示目录信息。

操作系统课程设计为LINUX设计一个简单的二级文件系统

操作系统课程设计为LINUX设计一个简单的二级文件系统

操作系统课程设计为LINUX设计一个简单的二级文件系统一.项目概述本课程设计旨在通过设计一个简单的多用户文件系统,加深学生对文件系统内部功能及内部实现的理解,并提高学生的程序设计能力、算法设计质量与程序设计素质。

二.设计题目为LINUX设计一个简单的二级文件系统,要求实现以下命令:Login用户登录、Dir列文件目录、Create创建文件、Delete删除文件、Open打开文件、Close关闭文件、Read读文件、Write写文件。

列目录时需包括文件名、物理地址、保护码和文件长度。

源文件需进行读写保护。

三.开发语言及实现平台或实验环境本课程设计的开发语言为C语言,实现平台为Linux操作系统。

学生需要在规定时间内完成程序的编写和调试,并书写课程设计报告。

四.时间安排1月17日布置课程设计任务,学生需要自行查阅资料并准备程序。

1月18日至1月20日,学生需要在机房上机调试程序,并书写课程设计报告。

1月21日上午,学生需要提交课程设计报告及相关文档。

每位学生应独立完成各自的任务,每天至少在设计室工作半天。

五.具体要求1.课程设计报告应按统一通用格式书写,具体格式要求请在网络上查阅。

2.指导教师和教研室主任(或责任教师)需要在规定时间内签署相应的文件。

设计目的:本设计旨在开发一款能够实现某种功能的程序,为用户提供便利。

设计内容:5.1.该程序将包括两个主要功能:A和B。

A功能将执行某种操作,而B功能将提供用户界面,使其能够轻松地使用A功能。

5.2.此外,该程序还将包括其他辅助功能,例如C和D。

这些功能将提高程序的可用性和实用性。

任务:该程序的主要任务是为用户提供一种方便、高效的解决方案,使其能够更轻松地实现某种目标。

主程序流程图:程序的主要流程将包括以下步骤:用户打开程序,选择所需的功能,程序执行相应的操作,最终将结果返回给用户。

程序设计:6.1.在程序设计方面,我们将采用一种灵活、可扩展的架构,以便能够轻松地添加新的功能和模块。

操作系统课程设计Linux二级文件系统设计说明

操作系统课程设计Linux二级文件系统设计说明

. .操作系统课程设计报告专业:软件工程学号:姓名:马提交日期:2017/1/10【设计目的】1、通过一个简单多用户文件系统的设计,加深理解文件系统的部功能和部实现2、结合数据结构、程序设计、计算机原理等课程的知识,设计一个二级文件系统,进一步理解操作系统3、通过对实际问题的分析、设计、编程实现,提高学生实际应用、编程的能力【设计容】为Linux系统设计一个简单的二级文件系统。

要求做到以下几点:1.可以实现下列几条命令:login 用户登录dir 列目录create 创建文件delete 删除文件open 打开文件close 关闭文件read 读文件write 写文件cd 进出目录2.列目录时要列出文件名,物理地址,保护码和文件长度3.源文件可以进行读写保护【实验环境】C++DevCpp【设计思路】本文件系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户下的文件。

另外,为了简便文件系统未考虑文件共享,文件系统安全以及管道文件与设备文件等特殊容。

首先应确定文件系统的数据结构:主目录、子目录及活动文件等。

主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。

用户创建的文件,可以编号存储于磁盘上。

如:file0,file1,file2…并以编号作为物理地址,在目录中进行登记。

结构体:typedef struct /*the structure of OSFILE*/{int fpaddr; /*file physical address*/int flength; /*file length*/int fmode; /*file mode:0-Read Only;1-Write Only;2-Read and Write; 3-Protect;*/char fname[MAXNAME]; /*file name*/} OSFILE; //存放重要信息typedef struct /*the structure of OSUFD*/{char ufdname[MAXNAME]; /*ufd name*/OSFILE ufdfile[MAXCHILD]; /*ufd own file*/}OSUFD; //用户下面的文件typedef struct /*the structure of OSUFD'LOGIN*/{char ufdname[MAXNAME]; /*ufd name*/char ufdpword[8]; /*ufd password*/} OSUFD_LOGIN;typedef struct /*file open mode*/{int ifopen; /*ifopen:0-close,1-open*/int openmode; /*0-read only,1-write only,2-read and write,3-initial*/ }OSUFD_OPENMODE;主要的函数说明:void LoginF(); /*LOGIN FileSystem用户登录*/void DirF(); /*Dir FileSystem列目录*/void CdF(); /*Change Dir改变目录*/void CreateF(); /*Create File创建文件*/void DeleteF(); /*Delete File删除文件*/void ModifyFM(); /*Modify FileMode修改*/void OpenF(); /*Open File打开文件*/void CloseF(); /*Close File关闭文件*/void ReadF(); /*Read File读文件*/void WriteF(); /*Write File写文件*/void QuitF(); /*Quit FileSystem离开文件系统*/void help();其他重要函数:void clrscr() //清屏int ExistD(char *dirname) /*Whether DirName Exist,Exist-i,Not Exist-0*/ int ExistF(char *filename) /*Whether FileName Exist,Exist-i,Not Exist-0*/ int FindPANo() /*find out physical address num*/void SetPANo(int RorW) /*Set physical address num,0-read,1-write*/void InputPW(char *password) /*input password,use '*' replace*/char *ltrim(char *str) /*remove the heading blanks.去除左空白*/char *rtrim(char *str) /*remove the trailing blanks.去除右空白*/int WriteF1() /*write file相当于置换文件*/程序流程说明:整体流程:各部分功能流程:Open:N NYDelete:NNYWrite :YYClose :N【源程序清单】Open:void OpenF() /*Open File*/{printf("\n\nC:\\%s>",strupr(dirname)); //显示当前路径 int fcoun, i; //定义两个整形变量 char fname[MAXNAME], fmode[25]; //定义两个字符串变量 int fmod; //文件模式printf("\nPlease input FileName:");gets(fname); //接收打开文件的文件名ltrim(rtrim(fname)); //去除左右空白if(ExistF(fname)<0) //判断文件是否存在{ //不存在printf("\nError.文件名 \'%s\'不存在\n", fname);wgetchar=1;} else { //存在i=ExistD(username); //获取用户物理信息for(int a=0; a < fcount[i]; a++) //遍历用户文件{if(strcmp(fname, ufd[i]->ufdfile[a].fname)==0) //找到文件{fcoun=a;break;}}ifopen[i][fcoun].ifopen=1; //将文件状态置为打开状态printf("Please input OpenMode(0-Read Only, 1-Write Only, 2-Read and Write,3-Protect):");//打开文件模式gets(fmode); //获取模式fmod=atoi(fmode); //将字符串转换为整型ifopen[i][fcoun].openmode=fmod; //将文件的模式置为OpenModeprintf("\nOpen Successed");wgetchar=1;}}Delete:void DeleteF() /*Delete File*/{printf("\n\nC:\\%s>",strupr(dirname)); //显示路径char fname[MAXNAME], str[50], str1[50]; //定义三个字符串变量int i, k, j;int fpaddrno1; //记录文件物理地址块号if(strcmp(strupr(ltrim(rtrim(dirname))), "")==0){ //判断主目录是否为空printf("\nError.请确认您要删除的是否在用户目录下!\n");wgetchar=1;}if(strcmp(strupr(dirname), strupr(username))!=0){ //判断用户是否在用户目录下printf("\nError.您只能删除修改自己用户目录下的文件哦!\n");wgetchar=1;} else {printf("\nPlease input FileName:");gets(fname); //接收删除的文件名ltrim(rtrim(fname)); //去除文件名的左右空白i=ExistF(fname); //用户文件位置if(i>=0){k=ExistD(username); //获取用户所在存储位置if(ifopen[k][i].ifopen==1){//文件状态处于打开状态,不许删除printf("\n Error.\'%s\' 处于打开状态!请先关闭哟!\n", fname);wgetchar=1;} else {if(ufd[k]->ufdfile[i].fmode==3){ //保护文件,不可删除printf("\nError.\'%s\'处于被保护状态!请先关闭哟!\n", fname);wgetchar=1;} else {fpaddrno1=ufd[k]->ufdfile[i].fpaddr; //获取文件的物理地址块号fpaddrno[fpaddrno1]=0; //回收物理地址块号for(j=i; j<fcount[k]; j++) //将文件都向前移动{ufd[k]->ufdfile[j]=ufd[k]->ufdfile[j+1]; //将j+1位置为j}strcpy(str , "c:\\osfile\\file\\");itoa(fpaddrno1, str1, 10); //将整数转化为字符串strcat(str, str1);strcat(str, ".txt"); //连接remove(str); //删除物理文件fcount[k--]; //文件个数减一printf("\n\'%s\'is deleted successfully.\n", fname);wgetchar=1;}}} else {printf("\nError.\'%s\'文件不存在!\n", fname); //文件不存在wgetchar=1;}}}Write:void WriteF() /*Write File*/{printf("\n\nC:\\%s>",strupr(dirname)); //显示用户路径int i, k, m=0; //定义整形变量int length; //定义长度整形变量char fname[MAXNAME]; //定义文件名字符串char str[255], str1[255]; //定义两个字符串变量if(strcmp(strupr(dirname), strupr(username))!=0) { //判断用户是否在用户目录下printf("\nError!请确认您要写的在用户目录下!\n");wgetchar=1;return;}printf("\n请先打开文件!\n");printf("Opened File(s) List:\n");k=ExistD(dirname); //获取用户文件信息 for(i=0; i<fcount[k]; i++) //遍历用户下的文件 {if(ifopen[k][i].ifopen==1) { //文件处于打开状态 printf("%15s", ufd[k]->ufdfile[i].fname);m++;}if(m%4 == 0 && m!=0) //每创建4个文件换一行 printf("\n");}printf("\n%d 文件已经打开啦!\n", m);if(m == 0)wgetchar=1;if(m!=0) //创建文件{printf("\nPlease input FileName:");gets(fname); //接收文件名ltrim(rtrim(fname)); //去除左右空白i=ExistF(fname); //获取文件物理地址if(i>=0) { //文件存在if(ifopen[k][i].ifopen==1) { //文件处于打开状态if(ifopen[k][i].openmode==1 || ifopen[k][i].openmode==2) {//文件权限是只写或读写itoa(ufd[k]->ufdfile[i].fpaddr, str, 10); //获取文件路径strcpy(str1, "file");strcat(str1, str);strcpy(str, "c:\\osfile\\file\\");strcat(str, str1);strcat(str, ".txt"); //文件路径char str2[3];int choice=3;strcpy(str2,"ab");printf("You can choise [0-Covered W] [1-Additonal W]:");//选择追加还是覆盖scanf(" %d", &choice);if(choice == 0) //0-覆盖strcpy(str2, "wb");fp_file=fopen(str, str2); //打开文件length=WriteF1();ufd[k]->ufdfile[i].flength=ufd[k]->ufdfile[i].flength+length;//修改文件长度if(choice == 0)ufd[k]->ufdfile[i].flength=length;printf("\n\nYou have write file successfully!!!");fclose(fp_file); //关闭文件wgetchar=0;} else if(ifopen[k][i].openmode==0) {//文件处于只读状态,不允许写printf("\nError.\'%s\' 文件以只读状态打开,不允许写!\n", fname);wgetchar=1;} else {printf("\nError.\'%s\' 文件处于关闭状态,请先打开!\n", fname);wgetchar=1;}}} else {printf("\nError.\'%s\' 文件不存在!\n", fname); //文件不存在wgetchar=1;}}}Close:void CloseF() /*Close File*/{printf("\n\nC:\\%s>",strupr(dirname)); //显示路径char fname[MAXNAME]; //定义字符串变量int i, k, n=0;if(strcmp(strupr(dirname), strupr(username))!=0) //关闭用户文件需在用户目录下{printf("\nError!请确认您要关闭的是在用户目录下!\n");} else {printf("\n\nOpened File(s) List:\n"); //罗列已处于打开的文件k=ExistD(dirname);for(i=0;i<fcount[k];i++){if (ifopen[k][i].ifopen==1) //文件处于开启状态if ((ifopen[k][i].openmode==0) ||(ifopen[k][i].openmode==2))//只读或者读写状态{printf("%15s",ufd[k]->ufdfile[i].fname);n++;}if((n%4==0)&&(n!=0)) printf("\n");}printf("\n%d 文件已被打开!\n",n);if (n==0) wgetchar=1;printf("\nPlease input FileName:");gets(fname); //接收关闭文件的文件名ltrim(rtrim(fname)); //除去首尾空格i=ExistF(fname); //获取文件物理地址if(i >= 0){k=ExistD(username); //获取用户文件信息if(ifopen[k][i].ifopen==0) //文件处于关闭状态 {printf("\nError!\'%s\'文件已经被关闭!\n", fname);} else { //将文件关闭ifopen[k][i].ifopen=0;ifopen[k][i].openmode=4;printf("\'%s\' has been closed successfully!", fname);}} else {printf("\nError.\'%s\'文件不存在\n", fname);}}}【测试结果】(此部分请同学们自己动手操作)Login:Help:Create:Open:Read:Write:1—additional添加后变为:0—covered覆盖后变为:Close:Attrib:Delete:Dir:Cls:(清屏)Exit:【设计总结】首先通过这次的操作系统课程设计,让我认识到了实际的编程操作并不难,难的是对过程的设计,功能的定义以及最后的程序流程图的设计。

操作系统课程方案二文档管理系统

操作系统课程方案二文档管理系统

青 岛 科 技 大 学操 作 系 统 课 程 设 计学生班级__________________________ 学生学号__________________________ 学生姓名________________________________年 ___月 ___日操作系统课程设计(二级文件管理系统>一、课程设计要求从所给题目中选择一个,分析设计要求,给出解决方案,建立必要的数据结构,设计总体流程<包括界面),详细设计必要的算法,测试结果。

基于Windows 或Linux 操作系统都可以,编程语言不限。

二、设计目的深入了解文件管理系统,初步掌握文件管理系统的实现方法。

三、选择题目设计一个简单的二级文件系统设计内容:编写程序模拟实现一个简单的文件管理系统,设计一个较实用的用户界面,方便用户使用。

设计要求:提供以下相关文件操作: <1)具有login (用户登录>0908010209Angelo 20186 26 计算机092<2)系统初始化<建文件卷、提供登录模块)<3)文件的创建: create<4)文件的打开:open<5)文件的读:read<6)文件的写:write<7)文件关闭:close<8)删除文件:delete<9)创建目录<建立子目录):mkdir<10)列出文件目录:dir<11)退出:loyout四、程序设计(1)开发环境Ubuntu 11.10 GCC<GNU Compiler Collection,GNU编译器套装)C语言编程(2)设计思想文件管理仅针对相应用户,用户注册时,自动分配对应的文件空间,该用户所有的文件保存在该用户空间下。

用户只有对自己空间中的目录或文件具有权限。

文件管理系统,模拟Linux文件管理指令格式,模拟实现ls、cat、rm、cd、mkdir等基础文件管理指令,并具有较明朗的操作界面。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

操作系统课程设计报告专业:计算机信息处理学号:08201328姓名:杨馨雨提交日期:2011-7-14【设计目的】1.课程设计目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现。

2.结合数据结构、程序设计、计算机原理等课程的知识,设计一个二级文件系统,进一步理解操作系统。

3.通过对实际问题的分析、设计、编程实现,提高学生实际应用、编程的能力【设计内容】1、delete删除文件2、open打开文件3、close关闭文件4、write写文件【实验环境】Windows7系统Visualstudio2010【相关知识综述】本文件系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件。

另外,为了简便文件系统未考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容。

首先应确定文件系统的数据结构:主目录、子目录及活动文件等。

主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。

用户创建的文件,可以编号存储于磁盘上。

如:file0,file1,file2…并以编号作为物理地址,在目录中进行登记。

【设计思路】1主要数据结构#define MAXNAME25/*thelargestlengthofmfdname,ufdname,filename*/#define MAXCHILD50/*thelargestchild每个用户名下最多有50个文件*/#define MAX(MAXCHILD*MAXCHILD)/*thesizeoffpaddrno*/typedefstruct/*thestructureofOSFILE定义主文件*/{int fpaddr;/*filephysicaladdress*/int flength;/*filelength*/int fmode;/*filemode:0-ReadOnly;1-WriteOnly;2-ReadandWrite;3-Protect;*/char fname[MAXNAME];/*filename*/}OSFILE;typedefstruct/*thestructureofOSUFD定义用户文件目录*/{char ufdname[MAXNAME];/*ufdname*/OSFILEufdfile[MAXCHILD];/*ufdownfile*/}OSUFD;typedefstruct/*thestructureofOSUFD'LOGIN定义登陆*/{char ufdname[MAXNAME];/*ufdname*/char ufdpword[8];/*ufdpassword*/}OSUFD_LOGIN;typedefstruct/*fileopenmode定义操作方式*/{int ifopen;/*ifopen:0-close,1-open*/int openmode;/*0-readonly,1-writeonly,2-readandwrite,3-initial*/}OSUFD_OPENMODE;2主要函数void LoginF();/*LOGINFileSystem*/void DirF();/*DirFileSystem*/void CreateF();/*CreateFile*/void DeleteF();/*DeleteFile*/void ModifyFM();/*ModifyFileMode*/void OpenF();/*OpenFile*/void CloseF();/*CloseFile*/void ReadF();/*ReadFile*/void WriteF();/*WriteFile*/void QuitF();/*QuitFileSystem*/void CdF();/*ChangeDir*/void help();【主要程序段】1Delete函数voidDeleteF()/*DeleteFile*/{charfname[MAXNAME],str[50],str1[50];inti,k,j;intfpaddrno1;if(strcmp(strupr(ltrim(rtrim(dirname))),"")==0)/*无法删除主目录的文件*/{printf("\.\n");wgetchar=1;}if(strcmp(strupr(dirname),strupr(username))!=0)/*无法删除非自己目录的文件*/{printf("\.\n");wgetchar=1;}else{printf("\nPleaseinputFileName:");gets(fname);fopen==1)/*文件打开时无法删除*/{printf("\nError.\'%s\'.\n",fname);wgetchar=1;}else{if(ufd[k]->ufdfile[i].fmode==3)/*被保护的文件无法删除*/{printf("\nError.\'%s\'.\n",fname);wgetchar=1;}else{fpaddrno1=ufd[k]->ufdfile[i].fpaddr;xt");remove(str);n",fname);wgetchar=1;}}}else'%s\'dosenotexist.\n",fname);wgetchar=1;}}}2Open函数voidOpenF()/*OpenFile*/{charfname[MAXNAME];inti,k,j;if(strcmp(strupr(dirname),strupr(username))!=0)/*在自己的目录里才能打开*/{printf("\.\n");wgetchar=1;}else{k=ExistD(username);for(j=0;j<fcount[k];j++){printf("%15s",ufd[k]->ufdfile[j].fname);}printf("\nPleaseinputFileName:");gets(fname);fopen==1)'%s\'isinopenstatus.\n",fname);wgetchar=1;}else{ifopen[k][i].ifopen=1;mode==0)/*根据文件的模式设置打开模式*/{ifopen[k][i].openmode=0;}elseif(ufd[k]->ufdfile[i].fmode==1){ifopen[k][i].openmode=1;}elseif(ufd[k]->ufdfile[i].fmode==2){ifopen[k][i].openmode=2;}elseifopen[k][i].openmode=3;printf("\n\'%s\'isopenedsuccessfully\n",fname);wgetchar=1;}}else'%s\'dosenotexist.\n",fname);wgetchar=1;}}}3Close函数voidCloseF()/*CloseFile*/{charfname[MAXNAME];inti,k,j;if(strcmp(strupr(dirname),strupr(username))!=0)/*不在自己的目录里没法进行*/{printf("\.\n");wgetchar=1;}else{k=ExistD(username);for(j=0;j<fcount[k];j++)/*列出已经打开的文件*/ {if(ifopen[k][j].ifopen==1)name);}printf("\nPleaseinputFileName:");gets(fname);fopen=0;/*关闭文件*/printf("\n\'%s\'closedsuccessfully\n",fname);wgetchar=1;}else'%s\'dosenotexist.\n",fname);wgetchar=1;}}}4Write函数voidWriteF()/*WriteFile*/{inti,k,n=0;intlength;charfname[MAXNAME],values[1000];charstr[255],str1[255],c;if(strcmp(strupr(ltrim(rtrim(dirname))),"")==0)n");wgetchar=1;return;}printf("\nCaution:Openfilefirst\n");printf("OpenedFile(s)List:\n");k=ExistD(dirname);fopen==1)name);n++;}if((n%4==0)&&(n!=0))printf("\n");}printf("\n%dfilesopenned.\n",n);if(n==0)wgetchar=1;fopen==1)penmode==1)||(ifopen[k][i].o penmode==2))paddr,str,10);xt");fp_file=fopen(str,"ab");length=ufd[k]->ufdfile[i].flengt h+length;n",ufd[k]->ufdfile[i].flength);printf("\n\nYouhavewritefilesuccessfully!!");fclose(fp_file);wgetchar=0;}elseif(ifopen[k][i].openmode==0)'%s\'\'twrite.\n",fname) ;wgetchar=1;}else'%s\'\'twrite.\n",fname);wgetchar=1;}}else'%s\'\n",fname);wgetchar=1;}}else'%s\'doesnotexist.\n",fname);wgetchar=1;}}}【程序流程设计】1总的功能结构图:2部分子模块程序流程图(1)打开命令的程序流程图:(2)关闭命令的程序流程图:(3)写命令的程序流程图:(4)删除命令的程序流程图:【测试结果】1删除文件2打开的文件不能删除3打开文件,其中已经打开的文件不能再次打开3关闭文件4写文件,其中只有打开了文件才能写入5写文件6只读文件和保护文件不能写入7其他函数【参考文献】计算机操作系统,西安电子科技大学出版社,方敏主编, 【源程序清单】#include""#include""#include""#include""#define MAXNAME25/*thelargestlengthofmfdname,ufdname,filename*/#define MAXCHILD50/*thelargestchild每个用户名下最多有50个文件*/#define MAX(MAXCHILD*MAXCHILD)/*thesizeoffpaddrno*/typedefstruct/*thestructureofOSFILE定义主文件*/{int fpaddr;/*filephysicaladdress*/int flength;/*filelength*/int fmode;/*filemode:0-ReadOnly;1-WriteOnly;2-ReadandWrite;3-Protect;*/ char fname[MAXNAME];/*filename*/}OSFILE;typedefstruct/*thestructureofOSUFD定义用户文件目录*/{char ufdname[MAXNAME];/*ufdname*/OSFILEufdfile[MAXCHILD];/*ufdownfile*/}OSUFD;typedefstruct/*thestructureofOSUFD'LOGIN定义登陆*/char ufdname[MAXNAME];/*ufdname*/char ufdpword[8];/*ufdpassword*/}OSUFD_LOGIN;typedefstruct/*fileopenmode定义操作方式*/{int ifopen;/*ifopen:0-close,1-open*/int openmode;/*0-readonly,1-writeonly,2-readandwrite,3-protect*/}OSUFD_OPENMODE;void LoginF();/*LOGINFileSystem*/void DirF();/*DirFileSystem*/void CreateF();/*CreateFile*/void DeleteF();/*DeleteFile*/void ModifyFM();/*ModifyFileMode*/void OpenF();/*OpenFile*/void CloseF();/*CloseFile*/void ReadF();/*ReadFile*/void WriteF();/*WriteFile*/void QuitF();/*QuitFileSystem*/void CdF();/*ChangeDir*/void help();char*rtrim(char*str);/*removethetrailingblanks.*/char*ltrim(char*str);/*removetheheadingblanks.*/void InputPW(char*password);/*inputpassword,use'*'replace*/int ExistD(char*dirname);/*WhetherDirNameExist,Exist-i,NotExist-0*/int WriteF1();/*writefile*/int ExistF(char*filename);/*WhetherFileNameExist,Exist-i,NotExist-0*/void SetPANo(int RorW);/*Setphysicaladdressnum*/int FindPANo();/*findoutphysicaladdressnum*/int ucount=0;/*thecountofmfd'sufds用户数*/int fcount[MAXCHILD];/*thecountofufd'sfiles子文件数*/int loginsuc=0;/*whetherloginsuccessfully登陆成功*/char username[MAXNAME];/*recordloginuser'sname22用户名*/char dirname[MAXNAME];/*recordcurrentdirectory使用的用户目录*/int fpaddrno[MAX];/*recordfilephysicaladdressnum物理地址号,存放自己所创建的所有文件的地址*/int wgetchar;/*whethergetchar()*/OSUFD*ufd[MAXCHILD];/*ufdandufdownfiles*/OSUFD_LOGINufd_lp;;QuitF();exit(0);break;case10:clrscr();choiceend=1;break;case11:CdF();choiceend=1;break;;}char*rtrim(char*str)/*removethetrailingblanks.去掉登陆用户名的尾空格*/int n=strlen(str)-1;while(n>=0){if(*(str+n)!=''){*(str+n+1)='\0';break;}else n--;}if(n<0)str[0]='\0';return str;}char*ltrim(char*str)/*removetheheadingblanks.去掉登陆用户名的头空格*/ {strrev(str);name),strupr(filename))==0){exist=1;break;}if(exist)return(i);elsereturn(-1);}int FindPANo()/*findoutphysicaladdressnum*/{int i;for(i=0;i<MAX;i++)if(fpaddrno[i]==0){fpaddrno[i]=1;break;}if(i<MAX)return(i);elsereturn(-1);}int WriteF1()/*writefile*/{int length=0;char c;printf("Pleaseinputtext(\'#\'standsforend):\n");while((c=getchar())!='#'){fprintf(fp_file,"%c",c);if(c!='\n')length++;}fprintf(fp_file,"\n");fclose(fp_file);return(length);}void LoginF()/*LOGINFileSystem登陆函数*/{char loginame[MAXNAME],loginpw[9],logincpw[9],str[50];xt");ufd[j]=(OSUFD*)malloc(sizeof(OSUFD));fopen=0;ifopen[j][i].openmode=4;}fclose(fp_ufd);}fclose(fp_mfd);ucount=j;SetPANo(0);printf("\n\nLoginsuccessful!WelcometothisFileSystem\n\n");loginsuc=1;return;}else xt");if((fp_ufd=fopen(str,"rb"))==NULL){fp_ufd=fopen(str,"wb");fclose(fp_ufd);}fp_mfd=fopen("d:\\osfile\\","rb");for(j=0;fread(&ufd_lp,sizeof(OSUFD_LOGIN),1,fp_mfd)!=0;j++){strcpy(str,"d:\\osfile\\");strcat(str,;strcat(str,".txt");ufd[j]=(OSUFD*)malloc(sizeof(OSUFD));strcpy(ufd[j]->ufdname,strupr);fp_ufd=fopen(str,"rb");for(i=0;fread(&ufd[j]->ufdfile[i],sizeof(OSFILE),1,fp_ufd)!=0;i++,fcount[j]++)fopen =0;ifopen[j][i].openmode=4;}fclose(fp_ufd);}fclose(fp_mfd);ucount=j;SetPANo(0);printf("\n\nLoginSuccessful!WelcometothisSystem\n\n");loginsuc=1;return;}else");getch();clrscr();printf("\n%14s%16s%14s%10s%18s\n","FileName","FileAddress","FileLength","Type","Fil eMode");}itoa(ufd[j]->ufdfile[i].fpaddr,str,10);mode==0)strcpy(sfmode,"ReadOnly");elseif(ufd[j]->ufdfile[i].fmode==1)strcpy(sfmode,"WriteOnly");elseif(ufd[j]->ufdfile[i].fmode==2)strcpy(sfmode,"ReadAndWrite");else strcpy(sfmode,"Protect");printf("%14s%16s%14d%10s%18s\n",ufd[j]->ufdfile[i].fname,sfpaddr,ufd[j]->ufdfile[i] .flength,"<FILE>",sfmode);}printf("\n%3dfile(s)\n",fcount[j]);}else.");getch();clrscr();printf("\n%14s%18s%8s\n","DirName","OwnFileCount","Type");}printf("%14s%18d%8s\n",ufd[i]->ufdname,fcount[i],"<UFD>");count=count+fcount[i];}printf("\n%3ddir(s),%5dfile(s)\n",ucount,count);}}void CreateF()/*CreateFile*/{int fpaddrno,flag=1,i;char fname[MAXNAME],str[50],str1[50],a[25];char fmode[25];if(strcmp(strupr(dirname),strupr(username))!=0)n");wgetchar=1;}else{printf("\nPleaseinputFileName:");gets(fname);ltrim(rtrim(fname));if(ExistF(fname)>=0){printf("\\'%s\'hasalreadyexisted.\n",fname);wgetchar=1;}else{printf("PleaseinputFileMode(0-ReadOnly,1-WriteOnly,2-ReadandWrite,3-Protect):");gets(fmode);ltrim(rtrim(fmode));if((strcmp(fmode,"0")==0)||(strcmp(fmode,"1")==0)||(strcmp(fmode,"2")==0)||(strcmp( fmode,"3")==0)){fpaddrno=FindPANo();if(fpaddrno>=0)name,fname);paddr=fpaddrno;ufd[i]->ufdfile[fcount[i]].fmode=atoi(fmode);ifopen[i][fcount[i]].ifopen=0;ifopen[i][fcount[i]].openmode=4;strcpy(str,"d:\\osfile\\file\\file");itoa(fpaddrno,str1,10);strcat(str,str1);strcat(str,".txt");fp_file=fopen(str,"wb");fclose(fp_file);fcount[i]++;while(flag){printf("Inputtextnow(Y/N):");gets(a);ltrim(rtrim(a));ufd[i]->ufdfile[fcount[i]-1].flength=0;if(strcmp(strupr(a),"Y")==0){fp_file=fopen(str,"wb+");length=WriteF1();flag=0;}elseif(strcmp(strupr(a),"N")==0){flag=0;wgetchar=1;}}printf("\n\'%s\'hasbeencreatedsuccessfully!\n",fname);}else{printf("\nFail!.\n");wgetchar=1;}}else{printf("\\'sRangeis0-3\n");wgetchar=1;}}}}void DeleteF()/*DeleteFile*/{char fname[MAXNAME],str[50],str1[50];int i,k,j;int fpaddrno1;if(strcmp(strupr(ltrim(rtrim(dirname))),"")==0)/*无法删除主目录的文件*/{printf("\.\n");wgetchar=1;}if(strcmp(strupr(dirname),strupr(username))!=0)/*无法删除非自己目录的文件*/ {printf("\.\n");wgetchar=1;}else{printf("\nPleaseinputFileName:");gets(fname);fopen==1)/*文件打开时无法删除*/{printf("\nError.\'%s\'.\n",fname);wgetchar=1;}else{if(ufd[k]->ufdfile[i].fmode==3)/*被保护的文件无法删除*/{printf("\nError.\'%s\'.\n",fname);wgetchar=1;}else{fpaddrno1=ufd[k]->ufdfile[i].fpaddr;xt");remove(str);n",fname);wgetchar=1;}}}else'%s\'dosenotexist.\n",fname);wgetchar=1;}}}void ModifyFM()/*ModifyFileMode*/{char fname[MAXNAME],str[50];int i,k;char fmode[25];/*whetherdelete*/if(strcmp(strupr(dirname),strupr(username))!=0){printf("\.\n");wgetchar=1;}else{printf("\nPleaseinputFileName:");gets(fname);ltrim(rtrim(fname));i=ExistF(fname);if(i>=0){k=ExistD(username);if(ifopen[k][i].ifopen==1){printf("\nError.\'%s\'.\n",fname);wgetchar=1;}else{if(ufd[k]->ufdfile[i].fmode==0)strcpy(str,"readonly");/*FileMode*/elseif(ufd[k]->ufdfile[i].fmode==1)strcpy(str,"writeonly");elseif(ufd[k]->ufdfile[i].fmode==2)strcpy(str,"readandwrite");else strcpy(str,"Protect");printf("\'%s\'filemodeis%s.\n",fname,strupr(str));printf("Modifyto(0-readonly,1-writeonly,2-readandwrite,3-Protect):");gets(fmode);ltrim(rtrim(fmode));if(strcmp(fmode,"0")==0){ufd[k]->ufdfile[i].fmode=0;printf("\n\'%s\'hasbeenmodifiedtoREADONLYmodesuccessfully.\n",fname);wgetchar=1;}elseif(strcmp(fmode,"1")==0){ufd[k]->ufdfile[i].fmode=1;printf("\n\'%s\'hasbeenmodifiedtoWRITEONLYmodesuccessfully.\n",fname);wgetchar=1;}elseif(strcmp(fmode,"2")==0){ufd[k]->ufdfile[i].fmode=2;printf("\n\'%s\'hasbeenmodifiedtoREADANDWRITEmodesuccessfully.\n",fname);wgetchar=1;}elseif(strcmp(fmode,"3")==0){ufd[k]->ufdfile[i].fmode=3;printf("\n\'%s\'hasbeenmodifiedtoFORBIDmodesuccessfully.\n",fname);wgetchar=1;}else{printf("\nError.\'%s\'isnotmodified.\n",fname);wgetchar=1;}}}else{printf("\nError.\'%s\'dosenotexist.\n",fname);wgetchar=1;}}}void OpenF()/*OpenFile*/{char fname[MAXNAME];int i,k,j;if(strcmp(strupr(dirname),strupr(username))!=0)/*在自己的目录里才能打开*/ {printf("\.\n");wgetchar=1;}else{k=ExistD(username);for(j=0;j<fcount[k];j++){printf("%15s",ufd[k]->ufdfile[j].fname);}printf("\nPleaseinputFileName:");gets(fname);fopen==1)'%s\'isinopenstatus.\n",fname);wgetchar=1;}else{ifopen[k][i].ifopen=1;mode==0)/*根据文件的模式设置打开模式*/{ifopen[k][i].openmode=0;}elseif(ufd[k]->ufdfile[i].fmode==1){ifopen[k][i].openmode=1;}elseif(ufd[k]->ufdfile[i].fmode==2){ifopen[k][i].openmode=2;}else ifopen[k][i].openmode=3;printf("\n\'%s\'isopenedsuccessfully\n",fname);wgetchar=1;}}else'%s\'dosenotexist.\n",fname);wgetchar=1;}}}void CloseF()/*CloseFile*/{char fname[MAXNAME];int i,k,j;if(strcmp(strupr(dirname),strupr(username))!=0)/*不在自己的目录里没法进行*/ {printf("\.\n");wgetchar=1;}else{k=ExistD(username);for(j=0;j<fcount[k];j++)/*列出已经打开的文件*/{if(ifopen[k][j].ifopen==1)name);}printf("\nPleaseinputFileName:");gets(fname);fopen=0;'%s\'dosenotexist.\n",fname);wgetchar=1;}}}void ReadF()/*ReadFile*/{int i,k,n=0;char fname[MAXNAME];char str[255],str1[255],c;if(strcmp(strupr(ltrim(rtrim(dirname))),"")==0)n");wgetchar=1;return;}printf("\nCaution:Openfilefirst\n");printf("OpenedFile(s)List:\n");k=ExistD(dirname);for(i=0;i<fcount[k];i++){if(ifopen[k][i].ifopen==1)name);n++;}if((n%4==0)&&(n!=0))printf("\n");}printf("\n%dfilesopenned.\n",n);if(n==0)wgetchar=1;fopen==1){if((ifopen[k][i].openmode==0)||(ifopen[k][i].openmode==2))paddr,str,10);strcpy(str1,"file");strcat(str1,str);strcpy(str,"d:\\osfile\\file\\");strcat(str,str1);strcat(str,".txt");fp_file=fopen(str,"rb");fseek(fp_file,0,0);printf("\nThetextis:\n\n");printf("");while(fscanf(fp_file,"%c",&c)!=EOF)if(c=='\n')printf("\n");else printf("%c",c);printf("\n\n%dLength.\n",ufd[k]->ufdfile[i].flength);fclose(fp_file);wgetchar=1;}elseif(ifopen[k][i].openmode==1)'%s\'\'tread.\n",fname);wgetchar=1;}else'%s\'\'tread.\n",fname);wgetchar=1;}}else{printf("\nError.\'%s\'\n",fname);wgetchar=1;}}else{printf("\nError.\'%s\'doesnotexist.\n",fname);wgetchar=1;}}}void WriteF()/*WriteFile*/{int i,k,n=0;int length;char fname[MAXNAME],values[1000];char str[255],str1[255],c;if(strcmp(strupr(ltrim(rtrim(dirname))),"")==0)n");wgetchar=1;return;}printf("\nCaution:Openfilefirst\n");printf("OpenedFile(s)List:\n");k=ExistD(dirname);fopen==1)name);n++;}if((n%4==0)&&(n!=0))printf("\n");}printf("\n%dfilesopenned.\n",n);if(n==0)wgetchar=1;fopen==1)penmode==1)||(ifopen[k][i].openmode==2))paddr,str,10);x t");fp_file=fopen(str,"ab");length=ufd[k]->ufdfile[i].flength+length;n",ufd[k]->ufdfile [i].flength);printf("\n\nYouhavewritefilesuccessfully!!");fclose(fp_file);wgetchar=0;}elseif(ifopen[k][i].openmode==0)'%s\'\'twrite.\n",fname);wgetchar=1;}else'%s\'\'twrite.\n",fname);wgetchar=1;}}else'%s\'\n",fname);wgetchar=1;}}else'%s\'doesnotexist.\n",fname);wgetchar=1;}}}void QuitF()/*QuitFileSystem*/{int i,j;char str[50];SetPANo(1);if(fp_mfd!=NULL)fclose(fp_mfd);xt");fp_ufd=fopen(str,"wb");fclose(fp_ufd);fp_ufd=fopen(str,"ab");for(i=0;i<fcount[j];i++)fwrite(&ufd[j]->ufdfile[i],sizeof(OSFILE),1,fp_ufd);fclose(fp_ufd);}}void CdF()/*ExchangeDir更换用户*/{char dname[MAXNAME];printf("\nPleaseinputDirName:");gets(dname);ltrim(rtrim(dname));if(ExistD(dname)>=0)strcpy(dirname,strupr(dname));elseif(strcmp(strupr(dname),"CD..")==0)strcpy(ltrim(rtrim(dirname)),"");else printf("\nError.\'%s\'doesnotexist.\n",dname);}void help(void){printf("\nTheCommandList\n");printf("\nCdAttribCreatewriteReadOpenClsDeleteExitClose\n");}【设计总结】UNIX系统中的文件系统是人们最感兴趣的,也是最成功的一部分。

相关文档
最新文档