没有合适的资源?快使用搜索试试~ 我知道了~
二级文件系统C语言代码
4星 · 超过85%的资源 需积分: 14 45 下载量 64 浏览量
2009-12-29
17:36:34
上传
评论 4
收藏 103KB DOC 举报
温馨提示
试读
20页
实现一个简单多用户文件系统设计,可完成用户登录,列文件目录,创建文件,删除文件,打开文件,读写文件等功能
资源推荐
资源详情
资源评论
实验九 文件系统设计
1.目的和要求
本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统
的内部功能和内部实现。
2.实验内容
为 DOS 系统设计一个简单的二级文件系统。要求做到以下几点:
① 可以实现下列几条命令
LOGIN 用户登陆
DIR 列文件目录
CREATE 创建文件
DELETE 删除文件
OPEN 打开文件
CLOSE 关闭文件
READ 读文件
WRITE 写文件
② 列目录时要列出文件名,物理地址,保护码和文件长度。
③ 源文件可以进行读写保护。
3.实验环境
①PC 兼容机
②Windows、DOS 系统
③TC 语言
4.实验提示
① 首先应确定文件系统的数据结构:主目录、子目录及活动文件等。主目
录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。
② 用户创建的文件,可以编号存储于磁盘上。如:file0,file1,file2…并以编
号作为物理地址,在目录中进行登记。
5.实验参考代码
参考程序见下(本程序需要在 c:下建一个名为 osfile 的目录及一个名为 file
的子目录):
// le.cpp : 定义控制台应用程序的入口点。
//
#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);
system("cls"); /*clear screen*/
LoginF(); /*user login*/
system("cls");
if(loginsuc==1) /*Login Successfully*/
{while (1)
{wgetchar=0;
if (choiceend==1)
{printf("\n\nC:\\%s>",strupr(dirname));} //strupr将所有小写字母转换成大写
else printf("Bad command or file name.\nC:\\%s>",strupr(username));
gets(choice);
strcpy(choice,ltrim(rtrim(strlwr(choice)))); //strlwr将所有大写字母转换成小写
if (strcmp(choice,"dir")==0) choice1=1;
else if(strcmp(choice,"creat")==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,"modify")==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:choiceend=1;OpenF();if (!wgetchar) getchar();break;
case 6:choiceend=1;CloseF();if (!wgetchar) getchar();break;
case 7:choiceend=1;ReadF();if (!wgetchar) getchar();break;
case 8:choiceend=1;WriteF();if (!wgetchar) getchar();break;
case 9:printf("\nYou have exited this system.");
QuitF();exit(0);break;
case 10:choiceend=1;system("cls");break;
case 11:CdF();choiceend=1;break;
case 20:help();choiceend=1;break;
default:choiceend=0;
}
}
}
else printf("\nAccess denied.");
}
void help(void)
{
printf("\nThe Command List\n");
printf("\nCd Attrib Creat Modify 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;
剩余19页未读,继续阅读
资源评论
- jneo6662013-02-16呃,VS运行不起。
- 尘岳2012-07-14DEVC++自动识别为C++程序,VS运行不起。
渺万里层云啦啦
- 粉丝: 20
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功