操作系统文件系统的主函数的C语言实现

这是操作系统文件系统的主函数的C语言实现
int main()
{
	char a[100];
	char code[14][10];
	char name[12];
	int i,flag;

	startsys();
	print();
	show();
	/*将命令全部保存在CODE数组中*/
	strcpy(code[0],"halt");
	strcpy(code[1],"create");
	strcpy(code[2],"open");
	strcpy(code[3],"close");
	strcpy(code[4],"write");
	strcpy(code[5],"read");
	strcpy(code[6],"del");
	strcpy(code[7],"mkdir");
	strcpy(code[8],"rmdir");
	strcpy(code[9],"dir");
	strcpy(code[10],"cd");
	strcpy(code[11],"back");
	strcpy(code[12],"list");
	strcpy(code[13],"root");

	while(1)
	{
		scanf("%s",a);
		for(i=0;i<14;i++)
		{
			if(!strcmp(code[i],a))
				break;
		}

		switch(i)
		{
		case 0: //*--退出文件系统--//
			my_exitsys();
			return 0;
		case 1: //*--创建文件--//
			scanf("%s",name);
			flag = my_create(name);
			if(flag==-1)
			{
				printf("Error: \n The namelength is too long !\n");
			}
			else if(flag==-2)
			{
				printf("Error: \n The direct item is already full !\n");
			}
			else if(flag==-3)
			{
				printf("Error: \n The number of openfile is too much !\n");
			}
			else if(flag==-4)
			{
				printf("Error: \n The name is already in the direct !\n");
			}
			else
			{
				printf("Successfully create a file! \n");
			}
			show();
			break;

		case 2://--打开文件--//
			scanf("%s",name);
			fd = my_open(name);
			if(fd == -1)
			{
				printf("Error: \n The open file not exit! \n");
			}
			else if(fd == -2)
			{
				printf("Error: \n The file have already opened! \n");
			}
			else if(fd == -3)
			{
				printf("Error: \n The number of open file is too much! \n");
			}
			else if(fd == -4)
			{
				printf("Error: \n It is a direct,can not open for read or write! \n");
			}
			else
			{
				printf("Successfully opened! \n");
			}
			show();
			break;

		case 3://--关闭文件--//
			scanf("%s",name);
			flag = my_close(name);
			if(flag == -1)
			{
				printf("Error:\n The file is not opened ! \n");
			}
			else
			{
				printf("Successfully closed! \n");
			}
			show();
			break;

		case 4:/*--写文件--*/
			if(openfilelist[fd].attribute == 0)
			{
				printf("Error:\n The file is not opened ! \n");
			}
			else
			{
				flag = my_write(fd);
				if(flag == 1)
				{
					printf("Successfully write! \n");
				}
				else
				{
					printf("Error:\n The disk size is not enough! \n");
				}
			}
			show();
			break;

		case 5:/*--读文件--*/
			if(fd ==-1)
			{
				printf("Error:\n The file is not opened ! \n");
			}
			else
			{
				flag = my_read(fd);
			}
			show();
			break;

		case 6://*--删除文件--
			scanf("%s",name);
			flag = my_rm(name);
			if(flag == -1)
			{
				printf("Error:\n The file not exit! \n");
			}
			else if(flag == -2)
			{
				printf("Error:\n The file is opened,please first close it ! \n");
			}
			else
			{
				printf("Successfully delete! \n");
			}
			show();
			break;

		case 7://*--创建子目录--/
			scanf("%s",name);
			flag = my_mkdir(name);
			if(flag == -1)
			{
				printf("Error:\n The length of name is to long! \n");
			}
			else if(flag == -2)
			{
				printf("Error:\n The direct item is already full ! \n");
			}
			else if(flag == -3)
			{
				printf("Error:\n The name is already in the direct ! \n");
			}
			else if(flag == -4)
			{
				printf("Error:\n // can not in the name of a direct ! \n");
			}
			else if(flag == -5)
			{
				printf("Error: \n The disk space is full!\n");
			}
			else if(flag == -6)
			{
				printf("Error: \n '..' or '.' can not as the name of the direct!\n");
			}
			else if(flag == 1)
			{
				printf("Successfully make dircet! \n");
			}
			show();
			break;

		case 8://*--删除子目录--/
			scanf("%s",name);
			flag = my_rmdir(name);
			if(flag == -1)
			{
				printf("Error:\n The direct is not exist! \n");
			}
			else if(flag == -2)
			{
				printf("Error:\nThe direct has son direct ,please first remove the son dircct!\n");
			}
			else if(flag == -3)
			{
				printf("Error:\n The remove is not direct ! \n");
			}
			else if(flag == 1)
			{
				printf("Successfully remove dircet! \n");
			}
			show();
			break;

		case 9://*--显示当前子目录--/
			my_ls();
			show();
			break;
		case 10:/*--更改当前目录--*/
			scanf("%s",name);
			flag = my_cd(name);
			if(flag == -1)
			{
				printf("Error:\n The opened is not direct!\n");
			}
			else if(flag == -2)
			{
				printf("Error:\n! The opened is not direct\n");
			}
			else if(flag == -3)
			{
				printf("Error:\nThe '//' is too much !\n");
			}
			show();
			break;
		case 11:
			flag = my_back();
			if(flag == -1)
				printf("Error:\n is root directory !\n");
			else
				printf("back Successfully!\n");
			show();
			break;
		case 12:
			list();
			show();
			break;
		case 13:
			rootprint();
			show();
			break;
		default:
			printf("\n Error!\n The command is wrong! \n");
			show();
		}
	}
}

共两个不同设计例子,都含详细的文档资料。 任务2.设计一个简单的二级文件系统 设计要求: 在任一OS下,建立一个大文件,把它假象成硬盘,在其中实现一个简单的模拟文件系统。 编写一管理程序对此空间进行管理,要求: 1. 实现盘块管理 2. 实现文件的读写操作 3. 每组最多2人,小组内要有明确分工,课程设计报告中设计部分可以相同,个人实现部分不同 参考建议: 将模拟硬盘的文件空间划分为目录区,文件区;采用位示图进行空间管理,盘块的分配使用显示链接(FAT表)的方式。 设计技术参数(数据结构)参考: #define MaxSize 100 #define Disk 512 //每个盘块大小为512bit #define NumDisk 2048 //有2048个盘块,既可分配空间为 1M /*************目录和文件的结构定义***********************/ struct DirectoryNode { char name[9]; /*目录或文件的名字*/ int type; /*0代表目录,1代表普通文件*/ struct DirectoryNode *next; /*指向下一个兄弟结点的指针*/ struct DirectoryNode *preDirFile; /*指向父结点的指针*/ struct DirectoryNode *subFile; /*指向第一个子结点的指针*/ int size; /*如果是文件则表示文件的大小*/ int first; /*起始盘块号*/ int last; /*末尾盘块号*/ int order; /*备用*/ }; //连续分配 struct FileSys { int VacTable[NumDisk]; //空闲表,0为空闲,1为被用 struct DirectoryNode root; //根目录 struct DirectoryNode Directory[NumDisk]; } *filesys; typedef struct { struct DirectoryNode *DirFile; char name[9]; }DataType; //包含一个指向目录的指针和名字 typedef struct { //队列结构的实现 DataType data[MaxSize]; int front,rear; //分别表示队列的头结点和尾结点 }Tp; void InitQueue(Tp *sq) //队列初始化 int EnAddQueue(Tp *sq,DataType data) //在队列中增加元素 DataType EnDelQueue(Tp *sq) //从队列中删除一个元素 int Empty(Tp *sq) //判断队列是否为空,返回0表示队列为空 ①.Dir:显示目录内容命令,显示当前目录下的文件和子目录。 ②.Md:创建目录操作。 ③.Create:创建文件,在当前目录下创建一个文件。 ④. all:显示从根目录开始的所有目录和文件及其层次结点。 ⑤.Cd:改变目录。 ⑥.Del:删除文件操作。 ⑦. Rd:删除目录操作,删除当前目录下的子目录。 ⑧. Ren:重命名函数 ⑨. Exit:退出命令
操作系统课程设计 【设计题目】 二级文件系统设计 【开发语言及实现平台或实验环境】 C++/VC++ 【设计目的】 (1)本实验的目的是通过一个简单多用户文件系统的设计,加深理解文件系统的内部功能和内部实现。 (2)结合数据结构、程序设计、计算机原理等课程的知识,设计一个二级文件系统,进一步理解操作系统。 (3)通过分对实际问题的分析、设计、编程实现,提高学生实际应用、编程的能力 【设计要求】 理解二级目录的文件系统的组织;掌握常用的数据结构;系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件;使用文件来模拟外存,进行数据结构设计和操作算法的设计,实现一个文件系统实现基本的文件操作(为了简便文件系统,不考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容)。要求: 1、 对程序的每一部分要有详细的设计分析说明 2、 程序执行的每个步骤要有具体的提示内容或输出 3、 源代码格式规范,注释不少于四分之一 4、 设计合适的测试用例,对得到的运行结果要有分析, 5、 设计中遇到的问题,设计的心得体会 6、 提交完整程序代码、课程设计报告及相关文档 【设计原理】 对采用二级文件目录的文件系统工作的机理了如指掌,对文件系统的相关操作要掌握。 【设计内容】 一、 任务 为Linux系统设计一个简单的二级文件系统。要求做到以下几点: 1.可以实现下列几条命令: login 用户登录 dir 列目录 create 创建文件 delete 删除文件 open 打开文件 close 关闭文件 read 读文件 write 写文件 cd 进出目录 2.列目录时要列出文件名,物理地址,保护码和文件长度 3.源文件可以进行读写保护 二、 程序设计 1. 设计思想 本文件系统采用两级目录,其中第一级对应于用户账号,第二级对应于用户帐号下的文件。另外,为了简便文件系统未考虑文件共享,文件系统安全以及管道文件与设备文件等特殊内容。 首先应确定文件系统的数据结构:主目录、子目录及活动文件等。主目录和子目录都以文件的形式存放于磁盘,这样便于查找和修改。 用户创建的文件,可以编号存储于磁盘上。如:file0,file1,file2…并以编号作为物理地址,在目录中进行登记。 2. 主要数据结构和部分代码
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值