.文件系统
①下列几条命令
LOGIN 用户登陆
DIR 列文件目录
CREATE 创建文件
DELETE 删除文件
OPEN 打开文件
CLOSE 关闭文件
READ 读文件
WRITE 写文件
②列目录时要列出文件名,物理地址,保护码和文件长度。
③源文件可以进行读写保护。
①首先应确定文件系统的数据结构:主目录、子目录及活动文件等。主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。
②用户创建的文件,可以编号存储于磁盘上。如:file0,file1,file2…并以编号作为物理地址,在目录中进行登记。
程序见下(本程序需要在c:下建一个名为osfile的目录及一个名为file的子目录):
#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(default);*/
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 main()
{int i,j,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.*/
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();
if((fp_mfd=fopen("c:\\osfile\\mfd","rb"))==NULL)
{fp_mfd=fopen("c:\\osfile\\mfd","wb");
fclose(fp_mfd);
}
for(i=0;i<MAX;i++) fpaddrno[i]=0;
textattr(BLACK*16|WHITE);
clrscr(); /*clear screen*/
LoginF(); /*user login*/
clrscr();
以上是一部分介绍,如需要完整的资料或者如不符合您的要求,请联系技术人员qq:242219979咨询
上一篇:vc++药品信息管理系统
下一篇:C语言遗传算法在求解TSP问题