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

合集下载

二级文件管模拟系统课程设计主题功能

二级文件管模拟系统课程设计主题功能

二级文件管理模拟系统课程设计主题功能1. 引言二级文件管理模拟系统是一个模拟操作系统中文件管理功能的软件系统。

本文将详细介绍该模拟系统的设计主题功能,并对其实现细节进行展示和解释。

2. 设计目的二级文件管理模拟系统的设计目的是模拟操作系统中的文件管理功能,使用户能够通过命令行或图形界面对文件进行创建、查找、打开、编辑、保存等操作,实现对文件的有效管理。

3. 主题功能3.1 文件创建与删除用户可以通过命令行或图形界面创建新的文件,并指定文件名和文件类型。

系统会检查文件名的合法性,防止重名文件的存在。

用户还可以选择删除已创建的文件,系统将会确认删除操作以避免误操作。

3.2 文件查找与打开用户可以输入文件名或关键字进行文件查找,系统会根据用户输入的关键字进行文件搜索,并列出搜索结果。

用户可以选择打开搜索到的文件,系统将会读取并显示文件内容。

3.3 文件编辑与保存用户可以在已打开的文件中进行编辑操作,包括插入、删除、修改和替换文本内容等操作。

用户编辑完成后可以选择保存文件,系统将会将文件的修改内容写入文件中。

3.4 文件重命名与复制用户可以选择重命名已创建的文件,系统会提示用户输入新的文件名,并修改文件的名称。

用户还可以选择复制文件,系统将会创建一个与原文件内容相同的新文件。

3.5 文件属性查看与修改用户可以查看文件的属性信息,包括文件名、大小、创建时间等。

用户还可以选择修改文件的属性,如修改文件名或更新文件的创建时间。

3.6 文件夹创建与管理用户可以通过命令行或图形界面创建新的文件夹,并给文件夹命名。

用户还可以对已创建的文件夹进行查看、重命名和删除等操作。

3.7 文件排序与筛选用户可以对文件进行排序操作,按照文件名、文件大小、文件类型或创建时间等进行排序。

用户还可以根据文件名或文件类型等条件对文件进行筛选,以便快速找到目标文件。

4. 实现技术二级文件管理模拟系统的实现可以采用面向对象的方法。

可以使用编程语言如Python、Java或C++来编写模拟系统的程序代码。

操作系统:二级文件夹文件系统的实现(cc++语言)

操作系统:二级文件夹文件系统的实现(cc++语言)

操作系统:⼆级⽂件夹⽂件系统的实现(cc++语⾔)操作系统的⼀个课程设计,实现⼀个⼆级⽂件夹⽂件系统。

⽤disk.txt模拟磁盘,使⽤Help查看⽀持的命令及其操作⽅式,root为超级⽤户(写在disk.txt中)⽂件的逻辑结构:流式⽂件。

物理结构:链接⽂件。

物理空间管理:空暇链法。

⽂件夹结构:⼆级⽂件夹结构。

⽂件夹搜索技术:线性搜索。

FCB:含⽂件相关的所有属性。

物理盘块的设计(disk.txt)以⼀个⽂本⽂件disk.txt模拟硬盘,设定硬盘容量分为100个物理块,每⼀个物理块的⼤⼩512字节(为了測试⽅便,最后68个数据块每⼀个的⼤⼩为256字节),盘块之间⽤(‘\n’)切割。

因此⼀个盘块:512字节数据+1字节(‘\n’)切割符=513字节。

则disk.txt 长度=51300(100×513)+1字节(⽂件结束符)=51301字节。

100块盘块的分布:1#: MFD块,存放MFD信息;2-17#: UFD块,存放UFD信息;18-33#: UOF块,存放UOF信息;其余物理块⽤于存放⽂件内容。

# MFD块的设计硬盘的第1个物理块固定⽤于存放主⽂件⽂件夹MFD。

MFD结构例如以下:typedef struct mfd{username ;//username 14Buserpwd ;//password14Blink; //该⽤户的UFD所在的物理块号(4B)}MFD;每⼀个MFD项占32字节。

因此,1个物理块可存放512/32=16个MFD(⽤户),即本⽂件系统最多可管理16个⽤户。

例如以下表1所看到的:username password⽤户⽂件⽂件夹地址Peter123453Ben Abc5表1 ⽂件系统⽤户⽂件夹信息表2#-17# UFD块的设计2#-17#物理块:固定⽤于存放⽤户⽂件⽂件夹UFD。

假设⼀个⽤户须要⼀个UFD块。

因此,16个⽤户共须要16个UFD块。

UFD结构例如以下:typedef struct {filename //⽂件名称14B;mode; ///⽂件权限0-readonly;1-writeonly;2-read/writelength; ///⽂件长度(以字节数计算)addr;//该⽂件的第1个⽂件块对应的物理块号}UFD;⼀个UFD项设为32 Bytes。

模拟简单二级文件管理系统

模拟简单二级文件管理系统

操作系统课程设计模拟简单二级文件管理系统*名:***学号:系别:计算机学院专业:网络工程年级:16级指导教师:2019年05 月11 日一、课程设计项目介绍(含项目介绍及设计目的)1、设计目的:通过具体的文件存储空间的管理、文件的物理结构、目录结构和文件操作的实现,加深对文件系统内部功能和实现过程的理解。

2、项目介绍:为LINUX 设计一个简单的二级文件系统。

本文件系统采用类似DOS系统的文件管理方式,每次调用该文件系统时,首先申请一定的内存空间,然后对该内存空间进行分配。

将申请到的空间划分为目录区,文件区;采用位示图进行空间管理,盘块的分配使用显示链接(FAT表)的方式。

每次调用该文件系统时自动为其分配空间,并将上次操作的结果从硬盘上调入内存;当结束调用时则将操作的结果重新存入硬盘,以便下次调用。

(每次使用都会自动搜索文件系统,以此确定是否是第一次使用;若是则格式化生成文件系统,否则读取已存在的文件系统。

)本项目通过VC编写简单的二级文件系统的代码,实现文件管理方式,使用者只需要给出相应的文件操作命令就可以分别得到各类文件操作的相应,并且可以选择登陆或注销不同用户。

二、总体设计(含系统的总体结构、原理框图或各模块介绍等)1、系统总体结构图:2、模块介绍(1)、主函数部分:在主函数系统接受输入信息,包括登陆用户和注册用户,登陆完成后选择相应的文件操作,可以选择创建目录、浏览目录、修改目录、创建文件等操作,如果选择错误就会出现相应的提示信息。

(2)、命令解释层函数:在命令解释层函数cmdexp()里加了一些选择和操作功能,增加程序实现的功能,如原来程序只有显示当前目录和文件、创建目录和修改目录的功能,把它拓展到系统所要求的全部功能,并在原有的程序的基础上进行相应的修改,使程序更加完善。

(3)、文件系统格式化函数:该函数首先建立文件,申请空间,在设置成功时将其空间写入filesystem.dat,使filesystem.dat为1M。

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

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

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

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

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

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

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

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

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

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

【设计思路】1 主要数据结构#define MAXNAME 25 /*the largest length ofmfdname,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-WriteOnly;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();【主要程序段】1 Delete函数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("\ convert to ufd dir before delete.\n");wgetchar=1;}if (strcmp(strupr(dirname),strupr(username))!=0) /*无法删除非自己目录的文件*/{printf("\ can only modify filemode in yourself dir.\n");wgetchar=1;}else{printf("\nPlease input FileName:");gets(fname);fopen==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;xt");remove(str);n",fname);wgetchar=1;}}}else\'%s\' dose not exist.\n",fname);wgetchar=1;}}}2 Open函数void OpenF() /*Open File*/{char fname[MAXNAME];int i,k,j;if (strcmp(strupr(dirname),strupr(username))!=0) /*在自己的目录里才能打开*/{printf("\ 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);fopen==1)'%s\' is in openstatus.\n",fname);wgetchar=1;}else{ifopen[k][i].ifopen=1;mode==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 openedsuccessfully\n",fname);wgetchar=1;}}else\'%s\' dose not exist.\n",fname);wgetchar=1;}}}3 Close函数void CloseF() /*Close File*/{char fname[MAXNAME];int i,k,j;if (strcmp(strupr(dirname),strupr(username))!=0) /*不在自己的目录里没法进行*/{printf("\ 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)name);}printf("\nPlease input FileName:");gets(fname);fopen=0;/*关闭文件*/printf("\n \'%s\' closed successfully\n",fname);wgetchar=1;}else\'%s\' dose not exist.\n",fname);wgetchar=1;}}}4 Write函数void WriteF() /*Write File*/{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:Open file first\n");printf("Opened File(s) List:\n");k=ExistD(dirname);fopen==1)name);n++;}if((n%4==0)&&(n!=0)) printf("\n");}printf("\n%d files openned.\n",n);if (n==0) wgetchar=1;fopen==1)penmode==1)||(ifopen[k][i].openmode==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\nYou have write filesuccessfully!!");fclose(fp_file);wgetchar=0;}else if(ifopen[k][i].openmode==0)'%s\' has been opened with READ ONLY mode. It isn\'t write.\n",fname);wgetchar=1;}else'%s\' has been opened with PROTECT mode. It isn\'t write.\n",fname);wgetchar=1;}}else '%s\' is in closing status. Please open it before write\n",fname);wgetchar=1;}}else \'%s\' does not exist.\n",fname);wgetchar=1;}}}【程序流程设计】1总的功能结构图:2部分子模块程序流程图(1)打开命令的程序流程图:(2)关闭命令的程序流程图:(3)写命令的程序流程图:(4)删除命令的程序流程图:【测试结果】1 删除文件2 打开的文件不能删除3 打开文件,其中已经打开的文件不能再次打开3 关闭文件4 写文件,其中只有打开了文件才能写入5 写文件6 只读文件和保护文件不能写入7 其他函数【参考文献】计算机操作系统,西安电子科技大学出版社,方敏主编,部分函数含义引用于【源程序清单】#include""#include""#include""#include""#define MAXNAME 25 /*the largest length ofmfdname,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-WriteOnly;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-protect*/}OSUFD_OPENMODE;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();char *rtrim(char *str); /*remove the trailing blanks.*/char *ltrim(char *str); /*remove the heading blanks.*/void InputPW(char *password); /*input password,use '*' replace*/int ExistD(char *dirname); /*Whether DirNameExist,Exist-i,Not Exist-0*/int WriteF1(); /*write file*/int ExistF(char *filename); /*Whether FileNameExist,Exist-i,Not Exist-0*/void SetPANo(int RorW); /*Set physical address num*/int FindPANo(); /*find out physical address num*/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物理地址号,存放自己所创建的所有文件的地址*/int wgetchar; /*whether getchar()*/OSUFD *ufd[MAXCHILD]; /*ufd and ufd own files*/OSUFD_LOGIN ufd_lp;;QuitF();exit(0);break;case 10:clrscr();choiceend=1;break;case 11:CdF();choiceend=1;break;;}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);name),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 LoginF() /*LOGIN FileSystem登陆函数*/{charloginame[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\nLogin successful! Welcome to this FileSystem\n\n");loginsuc=1;return;}else 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/*user not exist*/{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)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_uf d)!=0;i++,fcount[j]++)fopen=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 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 DirF() /*Dir FileSystem主目录*/{int i,j,count=0;char sfmode[25],sfpaddr[25],str[25];clrscr();if (strcmp(strupr(ltrim(rtrim(dirname))),"")!=0)");getch();clrscr();printf("\n%14s%16s%14s%10s%18s\n","FileName","FileAddres s","FileLength","Type","FileMode");}itoa(ufd[j]->ufdfile[i].fpaddr,str,10);mode==0) strcpy(sfmode,"Read Only");else if(ufd[j]->ufdfile[i].fmode==1)strcpy(sfmode,"Write Only");elseif(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].flength,"<FILE>",sfmode);}printf("\n %3d file(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 %3d dir(s),%5d file(s)\n",ucount,count);}}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)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 alreadyexisted.\n",fname);wgetchar=1;}else{printf("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)||(strc mp(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("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+");length=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;}}}}。

操作系统模拟文件管理大作业

操作系统模拟文件管理大作业

课程设计二:模拟文件管理一.设计目的(1)建立一个简单的模拟文件管理系统。

(2)理解用户界面和操作命令在操作系统中的作用。

二.设计要求需要实现一个命令行操作界面,包含如下命令:1. 创建文件功能:创立一个指定名字的新文件,即在目录中增加一项,不考虑文件内容,但必须能输入文件长度。

2. 删除文件功能:删除指定的文件3. 创建目录功能:在当前路径下创建指定的目录。

4. 删除目录功能:删除当前目录下的指定目录,如果该目录为空,则可删除,否则应提示是否作删除,删除操作将该目录下的全部文件和子目录都删除。

5. 改变目录功能:工作目录转移到指定的目录下,只要求完成改变到当前目录的某一个子目录下的功能,不要求实现相对目录以及绝对目录。

6. 显示目录功能:显示全部目录以及文件,输出时要求先输出接近根的目录,再输出子目录。

对于重名(创建时),文件不存在(删除时),目录不存在(改变目录时)等错误情况,程序应该作出相应处理并给出错误信息。

界面的提示符为#,提示的命令以及调试的方法应和前面的要求一致,可以自己设计更多的命令或者附加功能。

三.环境本实验是在windows xp+vc 6.0 环境下实现的,利用windows SDK 提供的系统接口(API )完成程序功能。

在windows xp 下安装好VC 后进行,VC 是一个集成开发环境,其中包含了windows SDK所有工具,所以就不用单独在安装SDK 了,程序中所用的API是操作系统提供的用来进行应用程序设计的系统功能接口。

要使用这些API,需要包含对这些函数进行说明的SDK 头文件,最常见的就是windows.h 。

一些特殊的API 调用还需要包含其他的头文件。

四.步骤1.打开 VC ,选择菜单项 File->New ,选择 Project 选项卡并建立一个名为 filesys 的 win32 console application 工程。

2. 在工程中创建原文件 filesys.cpp :选择菜单项 Project->Add to Project->File ,此时将打开一个新窗口,在其中输入想要创建的文件名字,这里是 filesys.cpp ,在其中编辑好原文 件并保存。

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

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

操作系统课程设计文件管理系统1. 引言文件管理是操作系统中的一个重要模块,负责对计算机中的文件进行管理和组织。

在操作系统课程设计中,设计一个文件管理系统是一个很有挑战性的任务,需要考虑到文件的创建、打开、读取、写入、删除等功能,并且要确保文件的安全性和可靠性。

本文将详细介绍文件管理系统的设计与实现。

2. 需求分析为了满足用户对文件管理的需要,我们需要对文件管理系统的需求进行分析。

在这个文件管理系统中,用户应该能够执行以下操作:•文件的创建和命名•文件的打开和关闭•文件的读取和写入•文件的删除和修改•文件的搜索和查找除此之外,还要考虑到对文件权限的管理,可以设置不同用户对文件的不同访问权限,以保障文件的安全性。

3. 概要设计概要设计是对文件管理系统的整体架构和功能进行规划和设计。

文件管理系统可以采用层次结构的设计方式,分为用户界面、文件管理模块和存储管理模块。

3.1 用户界面用户界面是用户与文件管理系统进行交互的接口,可以通过命令行或者图形界面来实现。

在用户界面中,用户可以输入相关指令来执行对文件的操作,如创建文件、打开文件、读取文件等。

3.2 文件管理模块文件管理模块是文件管理系统的核心模块,负责对文件进行创建、打开、读取、写入、删除等操作。

在文件管理模块中,需要维护一个文件目录表来记录文件的基本信息,如文件名、文件大小、文件权限等。

还需要考虑到文件的分配和回收,可以使用位示图等方式进行实现。

3.3 存储管理模块存储管理模块负责对文件进行存储和管理,包括磁盘空间的分配和回收。

在存储管理模块中,可以采用文件分配表或者索引节点进行存储方式的选择。

4. 详细设计在详细设计阶段,需要对概要设计中的每个模块进行详细设计,并确定各个模块之间的接口和数据结构。

4.1 用户界面设计用户界面设计可以采用命令行方式进行实现。

用户可以通过命令输入来执行相应的文件管理操作。

可以设计一系列命令,如create用于创建文件,open用于打开文件,read用于读取文件等。

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

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

#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;//}。

操作系统课程设计项目参考

操作系统课程设计项目参考

滴加碘液后
滴加碘液前
12/12/2021
第十二页,共二十三页。
消化(xiāohuà):在消化道内将食物分解成可吸收 (xīshōu)的成分的过程
(包括物理性消化和化学性消化)
吸收(xīshōu):营养物质通过消化道壁进入循环 系统的过程
12/12/2021
第十三页,共二十三页。
消化(xiāohuà)和吸收的过程
12/12/2021
第十九页,共二十三页。
练习(liànxí)
• 2、分析数据,指出(zhǐ chū)哪一部分消化道中消化液最多。
• 在每天摄入800克食物和1200毫升水的情况下, 消化腺大致分泌以下数量消化液。 1500毫升唾液 2000毫升胃液 1500毫升肠液 500毫升胆汁 1500毫升胰液
12/12/2021
第二十二页,共二十三页。
内容 总结 (nèiróng)
第二节。食物中的营养物质是在消化系统中被消化和吸收的。这粒西瓜籽在姗姗的消化道内, 经过了难忘的时光。它先遇到像轧钢机似的上、下尖硬的怪物,差点儿将它压得粉身碎骨。后来它
No 钻进了一条(yī tiáo)又长又窄的迷宫,它在这里走了很久,身边的许多物质都神秘地消失了。走出迷
唾液腺、胃腺(wèixiàn)、肝脏、胰腺、肠腺
1、淀粉在__口__腔__开始消化、蛋白质在____开始胃消化、脂肪在_______开始 消小化肠。
2、胆汁是一种消化液,但不含消化酶,起乳化脂肪的作用。
二、人体消化、吸收的主要器官—— _____小肠 能 训 练解
胰脏:分泌(fēnmì)胰液 肠腺:分泌肠液
肝脏:最大的腺体,分泌胆汁。 胆汁无消化酶,有乳化脂肪 的
作用。
第七页,共二十三页。
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

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

设计内容:模拟一个简单二级文件管理系统一、实验内容描述1 实验目标本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能及内部实现.2 实验要求为DOS系统设计一个简单的二级文件系统.要求做到以下几点:①可以实现下列命令:login 用户登录dir 列文件目录create 创建文件delete 删除文件open 打开文件close 关闭文件read 读文件write 写文件②列目录时要列出文件名、物理地址、保护码和文件长度.③源文件可以进行读写保护.二、程序主要内容1设计思路程序中要求每个用户在登陆后才可对其拥有的文件进行操作,用户对于其他用户的文件无操作权.文件操作包括浏览、创建、删除、打开、关闭、阅读、写入、修改模式.其他操作包括新建用户、帮助、用户登入、用户登出、退出系统.在程序文件夹下有个名为“file”的系统根目录,此目录下包括:一个名为“mfd”的文件,记录所有注册过的帐号及密码;用户文件,以用户名作为文件名,内容为其拥有的文件名及属性;一个名为“keiji”的文件夹.“keiji”文件夹中包括:“file.p”指针文件,记录所有已用的物理地址;一些以物理地址为名的文件,内容为文件内容.2 数据结构file结构体系统文件数据结构:fpaddrint,文件的物理地址、flengthint,文件长度、fmodeint,文件模式0.只读;1.可写;2.可读写;3.保护、fname[]char,文件名;filemode结构体文件状态数据结构:isopenint,文件当前状态,0.关闭;1.打开、modeint,文件模式0.只读;1.可写;2.可读写;3.初始化;user结构体用户信息数据结构:uname[]char,用户名、upassword[]char,用户密码;userfile结构体用户文件数据结构:uname[]char,用户名、ufile[]file,用户拥有的文件数组.代码:#include <stdio.h>#include <stdlib.h>#include <conio.h>#include <time.h>#include <string.h>#define MaxUser 100 //定义最大MDF主目录文件#define MaxDisk 512*1024 //模拟最大磁盘空间#define commandAmount 12 //对文件操作的指令数//存储空间管理有关结构体和变量char disk[MaxDisk]; //模拟512K的磁盘存储空间typedef struct distTable //磁盘块结构体{int maxlength;int start;int useFlag;distTable *next;}diskNode;diskNode *diskHead;struct fileTable //文件块结构体{char fileName[10];int strat; //文件在磁盘存储空间的起始地址int length; //文件内容长度int maxlength; //文件的最大长度char fileKind[3]; //文件的属性——读写方式struct tm *timeinfo;bool openFlag; //判断是否有进程打开了该文件//fileTable *next;};//两级目录结构体typedef struct user_file_directory //用户文件目录文件UFD {//char fileName[10];fileTable *file;user_file_directory *next;}UFD;//UFD *headFile;typedef struct master_file_directory //主文件目录MFD{char userName[10];char password[10];UFD *user;}MFD;MFD userTable[MaxUser];int used=0; //定义MFD目录中用已有的用户数//文件管理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();int userID=-1; //用户登录的ID号,值为-1时表示没有用户登录int main(){char order[commandAmount][10];strcpy(order[0],"create");strcpy(order[1],"rm");strcpy(order[2],"cat");strcpy(order[3],"write");strcpy(order[4],"fine");strcpy(order[5],"chmod");strcpy(order[6],"ren");strcpy(order[7],"dir");strcpy(order[8],"close");strcpy(order[9],"return");strcpy(order[10],"exit");strcpy(order[11],"df");charcommand[50],command_str1[10],command_str2[10],command_str3[5],command_str4[3];int i,k,j;int length;initDisk(); //初始化磁盘for(i=0;i<MaxUser;i++) //初始化用户UFD目录文件的头指针{userTable[i].user=(UFD *)malloc(sizeof(UFD));userTable[i].user->next=NULL;}while(1){printf("********************************************\n");printf(" 1、Creat user\n");printf(" 2、login\n");printf("********************************************\n");printf("Please chooce the function key:>");int choice;scanf("%d",&choice);if(choice==1) userCreate();else if(choice==2) userID=login();else printf("您的输入有误,请重新选择\n");while(userID!=-1){fflush(stdin);printf("———————————————————————————————————————\n");printf(" create-创建格式:create a1 1000 rw,将创建名为a1,长度为1000字节可读可写的文件\n");printf(" rm-删除格式:rm a1,将删除名为a1的文件\n");printf(" cat-查看文件内容格式:cat a1,显示a1的内容\n");printf(" write-写入格式:write a1\n");printf(" fine-查询格式:fine a1 ,将显示文件a1的属性\n");printf(" chmod-修改格式:chmod a1 r,将文件a1的权限改为只读方式\n");printf(" ren-重命名格式:ren a1 b1 ,将a1改名为b1\n");printf(" dir-显示文件格式:dir aaa,将显示aaa用户的所有文件\n");printf(" df-显示磁盘空间使用情况格式:df\n");printf(" close-关闭文件格式:close a1,将关闭文件a1\n");printf(" return-退出用户,返回登录界面\n");printf(" exit-退出程序\n");printf("————————————————————————————————————————\n");printf("please imput your command:>");gets(command);int select;for(i=0;command[i]!=' '&&command[i]!='\0';i++) //command_str1字符串存储命令的操作类型command_str1[i]=command[i];k=i;command_str1[k]='\0';for(i=0;i<commandAmount;i++){if(!strcmp(command_str1,order[i])){select=i;break;}}if(i==commandAmount){printf("您输入的命令有误,请重新输入\n");continue;}for(i=k+1,k=0;command[i]!=' '&&command[i]!='\0';i++,k++) //commmand_str2字符串存储文件名或用户名command_str2[k]=command[i];command_str2[k]='\0';k=i;switch(select){case 0:for(i=k+1,k=0;command[i]!=' ';i++,k++)command_str3[k]=command[i];command_str3[k]='\0';k=i;j=1;length=0; //初始化文件长度for(i=strlen(command_str3)-1;i>=0;i--) //把字符串转换为十进制{length+=(command_str3[i]-48)*j;j*=10;}for(i=k+1,k=0;command[i]!=' '&&command[i]!='\0';i++,k++)command_str4[k]=command[i];command_str4[k]='\0';fileCreate(command_str2,length,command_str4);break;case 1:fileDel(command_str2);break;case 2:fileCat(command_str2);break;case 3:fileWrite(command_str2);break;case 4:fileFine(command_str2);break;case 5:for(i=k+1,k=0;command[i]!=' '&&command[i]!='\0';i++,k++)command_str3[k]=command[i];command_str3[k]='\0';chmod(command_str2,command_str3);break;case 6:for(i=k+1,k=0;command[i]!='\0';i++,k++)command_str3[k]=command[i];command_str3[k]='\0';fileRen(command_str2,command_str3);break;case 7:fileDir(command_str2);break;case 8:fileClose(command_str2);break;case 9:UFD *p;for(p=userTable[userID].user->next;p!=NULL;p=p->next) //退出用户之前关闭所有打的文件if(p->file->openFlag)p->file->openFlag=false;system("cls");userID=-1;break;case 10:exit(0);break;case 11:diskShow();break;}}}return 0;}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");system("pause");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");system("pause");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");}{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");}elseprintf("该文件已被进程打开,删除失败\n");system("pause");}}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}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; //文件打开标记printf("*****************************************************\n");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);system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}void fileWrite(char fileName[]){UFD *p,*q;q=userTable[userID].user;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");system("pause");return;}char str[500];printf("please input content:\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");system("pause");return;}for(i=startPos,k=0;k<(int)strlen(str);i++,k++)disk[i]=str[k];printf("文件写入成功,请用close命令将该文件关闭\n");system("pause");}else{printf("没有找到该文件,请检查输入的文件名是否正确\n");system("pause");}}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");system("pause");}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");system("pause");}}运行结果视图:(略)。

相关文档
最新文档