⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 基于UNIX6的文件系统模拟程序
💻 C
字号:
#include <stdio.h>
#include <stdlib.h>#include "filesys.h"
struct hinode hinode[NHINO];struct dir dir;struct file sys_ofile[SYSOPENFILE];struct filsys filsys;struct pwd pwd[PWDNUM];struct user user[USERNUM];FILE *fd;struct inode *cur_path_inode;int user_id;main(){	unsigned short ab_fd1,ab_fd2,ab_fd3,ab_fd4;	unsigned short bhy_fd1;	char *buf;
//	
/*	//printf("\nDo you want to format the disk\n");	//if(getchar() == 'y')		//printf("\nFormat will erase all context on the disk\nAre You Sure!!\n");	//if(getchar() == 'y')		format();	install();	_dir();	login(2118,"abcd");	user_id = 0;	mkdir("a2118");
	_dir();	chdir("a2118");
	_dir();
	chdir("..");
	_dir();	ab_fd1 = creat(2118,"ab_file0.c",01777);
	//_dir();	buf = (char*)malloc(BLOCKSIZ*6 + 5);	write(ab_fd1,buf,BLOCKSIZ*6 + 5);	close(user_id,ab_fd1);	free(buf);
	_dir();	mkdir("subdir");	chdir("subdir");	ab_fd2 = creat(2118,"file1.c",01777);	buf = (char*)malloc(BLOCKSIZ*4 + 20);	write(ab_fd2,buf,BLOCKSIZ*4 + 20);	close(user_id,ab_fd2);	free(buf);	chdir("..");	ab_fd3 = creat(2118,"ab_file2.c",01777);	buf = (char*)malloc(BLOCKSIZ*10 + 255);	close(ab_fd3);	free(buf);//_dir();	del("ab_file0.c");//_dir();	ab_fd4 = creat(2118,"ab_file3.c",01777);	buf = (char*)malloc(BLOCKSIZ*8 + 300);	write(ab_fd4,buf,BLOCKSIZ*8 + 300);	close(ab_fd4);	free(buf);
	ab_fd3 = open(2118,"ab_file2.c",FAPPEND);	buf = (char*)malloc(BLOCKSIZ*3 + 100);	write(ab_fd3,buf,BLOCKSIZ*3 + 100);	close(ab_fd3);	free(buf);	_dir();	chdir("..");	logout();	halt();	printf("it is end here!!");
*/

/**/
	int i;
	char cmd[6];
	char para[8];

	printf("			**********************		\n");
	printf("			  A simple FILESYS			\n");
	printf("			   --Testing Shell  		\n");
	printf("		   (c)020749@smail.tongji.edu.cn	\n");
	printf("			**********************		\n\n");

	format();
	install();

	printf("\nThe user id is 1111 and the password is 1111 too!\n");

	while(1)//0
	{
		printf("\nFilesys login:");
		if(cmd_login() == 0)
			printf("\nLogin incorrect !");
		else
		{
			user_id=0;
			printf("\n");
			break;
		}
	}
	//printf("\n\n");
	system("cls");
	printf("");
	help();
	//printf("\n\n");

	while(1)
	{
		printf("$");
		scanf("%s",cmd);
		if(!strcmp(cmd,"help"))
		{
			help();
			continue;
		}
		else if(!strcmp(cmd,"exit"))
		{
			halt();
			exit(0);
		}
		else if(!strcmp(cmd,"dir") || !strcmp(cmd,"ls"))
		{
			cmd_ls();
			continue;
		}
		else if(!strcmp(cmd,"cls") || !strcmp(cmd,"clear"))
		{
			system("cls");
			continue;
		}
		else if(Iscmd(cmd))
		{
			scanf("%s",para);
			cmd_cmd(cmd,para);
			printf("\n");
			continue;
		}
		printf("\nCommond not found!\n");
		
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -