文件系统设计 1.文件系统 ①下列几条命令 paper51.com LOGIN 用户登陆 内容来自论文无忧网 www.paper51.com DIR 列文件目录 内容来自论文无忧网 www.paper51.com CREATE 创建文件 内容来自论文无忧网 www.paper51.com DELETE 删除文件 http://www.paper51.com OPEN 打开文件 http://www.paper51.com CLOSE 关闭文件 内容来自www.paper51.com READ 读文件 内容来自论文无忧网 www.paper51.com
WRITE 写文件 paper51.com ②列目录时要列出文件名,物理地址,保护码和文件长度。 copyright paper51.com ③源文件可以进行读写保护。 内容来自论文无忧网 www.paper51.com ①首先应确定文件系统的数据结构:主目录、子目录及活动文件等。主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。 内容来自www.paper51.com
②用户创建的文件,可以编号存储于磁盘上。如:file0,file1,file2…并以编号作为物理地址,在目录中进行登记。 copyright paper51.com
程序见下(本程序需要在c:下建一个名为osfile的目录及一个名为file的子目录): http://www.paper51.com #include"stdio.h" http://www.paper51.com
#include"string.h" http://www.paper51.com #include"conio.h" copyright paper51.com #include"stdlib.h" 内容来自论文无忧网 www.paper51.com #defineMAXNAME 25 /*thelargest length of mfdname,ufdname,filename*/ 内容来自论文无忧网 www.paper51.com #defineMAXCHILD 50 /*the largest child*/ http://www.paper51.com #define MAX(MAXCHILD*MAXCHILD) /*the size of fpaddrno*/ paper51.com typedef struct /*the structure of OSFILE*/ 内容来自www.paper51.com {int fpaddr; /*file physical address*/ 内容来自论文无忧网 www.paper51.com int flength; /*file length*/ 内容来自www.paper51.com int fmode; /*file mode:0-Read Only;1-WriteOnly;2-Read and Write(default);*/ http://www.paper51.com
charfname[MAXNAME]; /*file name*/ 内容来自www.paper51.com } OSFILE; 内容来自www.paper51.com
typedef struct /*the structure ofOSUFD*/ 内容来自www.paper51.com {charufdname[MAXNAME]; /*ufdname*/ 内容来自论文无忧网 www.paper51.com OSFILE ufdfile[MAXCHILD]; /*ufd own file*/ copyright paper51.com }OSUFD; copyright paper51.com
typedef struct /*the structure of OSUFD'LOGIN*/ 内容来自论文无忧网 www.paper51.com
{charufdname[MAXNAME]; /*ufdname*/ 内容来自论文无忧网 www.paper51.com
charufdpword[8]; /*ufd password*/ paper51.com } OSUFD_LOGIN; 内容来自论文无忧网 www.paper51.com
typedef struct /*file open mode*/ paper51.com {intifopen; /*ifopen:0-close,1-open*/ 内容来自www.paper51.com int openmode; /*0-read only,1-write only,2-readand write,3-initial*/ copyright paper51.com
}OSUFD_OPENMODE; http://www.paper51.com OSUFD *ufd[MAXCHILD]; /*ufd and ufd own files*/ 内容来自论文无忧网 www.paper51.com OSUFD_LOGINufd_lp; 内容来自www.paper51.com intucount=0; /*the count of mfd'sufds*/ 内容来自论文无忧网 www.paper51.com intfcount[MAXCHILD]; /*the count ofufd's files*/ 内容来自论文无忧网 www.paper51.com int loginsuc=0;/*whether login successfully*/ http://www.paper51.com charusername[MAXNAME]; /*record loginuser's name22*/ http://www.paper51.com chardirname[MAXNAME];/*record current directory*/ paper51.com
intfpaddrno[MAX]; /*record filephysical address num*/ copyright paper51.com OSUFD_OPENMODEifopen[MAXCHILD][MAXCHILD]; /*record file open/close*/ copyright paper51.com
int wgetchar;/*whether getchar()*/ copyright paper51.com
FILE*fp_mfd,*fp_ufd,*fp_file_p,*fp_file; copyright paper51.com void main() copyright paper51.com {int i,j,choice1; http://www.paper51.com char choice[50]; /*choiceoperation:dir,create,delete,open,delete,modify,read,write*/ copyright paper51.com intchoiceend=1; /*whether choice end*/ 内容来自论文无忧网 www.paper51.com
char *rtrim(char*str); /*remove the trailingblanks.*/ copyright paper51.com char *ltrim(char*str); /*remove the headingblanks.*/ 内容来自论文无忧网 www.paper51.com voidLoginF(); /*LOGIN FileSystem*/ copyright paper51.com
voidDirF(); /*Dir FileSystem*/ paper51.com void CdF(); /*Change Dir*/ 内容来自论文无忧网 www.paper51.com voidCreateF(); /*Create File*/ http://www.paper51.com void DeleteF();/*Delete File*/ copyright paper51.com void ModifyFM();/*Modify FileMode*/ paper51.com voidOpenF(); /*Open File*/ 内容来自www.paper51.com voidCloseF(); /*Close File*/ copyright paper51.com void ReadF();/*Read File*/ copyright paper51.com void WriteF();/*Write File*/ http://www.paper51.com void QuitF();/*Quit FileSystem*/ http://www.paper51.com void help(); 内容来自论文无忧网 www.paper51.com if((fp_mfd=fopen("c:\\osfile\\mfd","rb"))==NULL) 内容来自论文无忧网 www.paper51.com {fp_mfd=fopen("c:\\osfile\\mfd","wb"); paper51.com fclose(fp_mfd); paper51.com } 内容来自论文无忧网 www.paper51.com
for(i=0;i<MAX;i++)fpaddrno[i]=0; copyright paper51.com textattr(BLACK*16|WHITE); 内容来自www.paper51.com clrscr(); /*clear screen*/ 内容来自www.paper51.com LoginF(); /*user login*/ paper51.com
clrscr(); http://www.paper51.com
if(loginsuc==1) /*Login Successfully*/ http://www.paper51.com {while (1) copyright paper51.com {wgetchar=0; 内容来自论文无忧网 www.paper51.com if(choiceend==1) 内容来自论文无忧网 www.paper51.com
{printf("\n\nC:\\%s>",strupr(dirname));} 内容来自www.paper51.com elseprintf("Bad command or file name.\nC:\\%s>",strupr(username)); http://www.paper51.com gets(choice); http://www.paper51.com strcpy(choice,ltrim(rtrim(strlwr(choice)))); 内容来自论文无忧网 www.paper51.com if(strcmp(choice,"dir")==0) choice1=1; http://www.paper51.com
elseif(strcmp(choice,"creat")==0) choice1=2; copyright paper51.com elseif(strcmp(choice,"delete")==0) choice1=3; 内容来自www.paper51.com
elseif(strcmp(choice,"attrib")==0) choice1=4; copyright paper51.com elseif(strcmp(choice,"open")==0) choice1=5; 内容来自www.paper51.com elseif(strcmp(choice,"close")==0) choice1=6; 内容来自论文无忧网 www.paper51.com elseif(strcmp(choice,"read")==0) choice1=7; paper51.com elseif(strcmp(choice,"modify")==0) choice1=8; paper51.com elseif(strcmp(choice,"exit")==0) choice1=9; 内容来自论文无忧网 www.paper51.com elseif(strcmp(choice,"cls")==0) choice1=10; copyright paper51.com elseif(strcmp(choice,"cd")==0) choice1=11; 内容来自www.paper51.com elseif(strcmp(choice,"help")==0) choice1=20; copyright paper51.com
elsechoice1=12; 内容来自论文无忧网 www.paper51.com
switch(choice1) http://www.paper51.com {case1:DirF();choiceend=1;break; copyright paper51.com case2:CreateF();choiceend=1;if(!wgetchar) getchar();break; copyright paper51.com case3:DeleteF();choiceend=1;if(!wgetchar)getchar();break; 内容来自www.paper51.com
case4:ModifyFM();choiceend=1;if(!wgetchar) getchar();break; http://www.paper51.com
case5:choiceend=1;OpenF();if (!wgetchar) getchar();break; paper51.com
case6:choiceend=1;CloseF();if (!wgetchar) getchar();break; copyright paper51.com
case7:choiceend=1;ReadF();if (!wgetchar) getchar();break; paper51.com
case8:choiceend=1;WriteF();if (!wgetchar) getchar();break; paper51.com
case9:printf("\nYou have exited this system."); copyright paper51.com QuitF();exit(0);break; 内容来自www.paper51.com case10:choiceend=1;clrscr();break; 内容来自www.paper51.com case11:CdF();choiceend=1;break; paper51.com case20:help();choiceend=1;break; 内容来自www.paper51.com
default:choiceend=0; http://www.paper51.com
} paper51.com } paper51.com } copyright paper51.com elseprintf("\nAccess denied."); http://www.paper51.com
} copyright paper51.com |