main.c

来自「操作系统实验,文件系统,c语言实现的」· C语言 代码 · 共 144 行

C
144
字号
#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 user user[USERNUM];
FILE *fd;
struct inode *cur_path_inode;
int user_id,file_block;

main()
{
	unsigned short ab_fd1,ab_fd2,ab_fd3,ab_fd4;
	unsigned short bhy_fd1;  
	char *buf;
	int i;
/*	printf("\nDo you want to format the disk? y/n \n");
	if(getchar()=='y')
	{printf("\nFormat Will erase all context on the disk. Are You Sure? y/n\n");getchar();}
	else
		exit(0);
	if(getchar()=='y')
		format();
	else
		exit(0);
		*/


	printf(".....................................................\n");
	printf("command:format \n");
	printf("formatting...\n");
	format();
	printf("installed filesystem\n");
	install();
	printf(".....................................................\n");
	printf("command:list\n");//列出目录
	dirlt(20);
	_dir(); 
	 
	
	/* user_id=0;*/
	printf(".....................................................\n");
	printf("command:mkdir mydir\n");//创建mydir目录
	mkdir("mydir");
	printf(".....................................................\n");
	printf("command:list\n");//再次列出目录
	dirlt(2);  
	_dir();  
	printf(".....................................................\n");
	printf("command:chdir mydir\n");//进入mydir目录
	chdir("mydir");
	printf(".....................................................\n");
	printf("command:list\n");
	dirlt(2);   //再次列出目录
	_dir();  
	
	
	file_block=BLOCKSIZ*6+5;
	printf(".....................................................\n");
	printf("command:creat myfile.c\n");//创建myfile.c文件
	ab_fd1=creat(user_id,"myfile.c",01777);
	buf=(char*)malloc(BLOCKSIZ*6+5);
	write(ab_fd1,buf,BLOCKSIZ*6+5);
	close(user_id,ab_fd1);
	free(buf);
	printf(".....................................................\n");
	printf("command:list\n");
	dirlt(2);   //再次列出目录
	_dir();   

/*
	printf("\nin---->mkdir:subdir\n");
	mkdir("subdir");
	chdir("subdir"); 
	dirlt(2); 
	_dir(); 
	
	file_block=BLOCKSIZ*4+20;
	ab_fd2=creat(user_id,"ab_file1.c",01777);
	buf=(char *)malloc(BLOCKSIZ*4+20);
	write(ab_fd2,buf,BLOCKSIZ*4+20);
	close(user_id,ab_fd2);
	free(buf); 
	dirlt(2); 
	_dir();  
	
	printf("\nin---->chdir:..\n");
	chdir(".."); 
	dirlt(2);  
	_dir();  
	printf("\nin---->creat(ab_file2.c)\n");
	file_block=BLOCKSIZ*3+255;
	ab_fd3=creat(user_id,"ab_file2.c",01777);
	buf=(char*)malloc(BLOCKSIZ*3+255); 
	write(ab_fd3,buf,BLOCKSIZ*3+255);
	close(user_id,ab_fd3);
	free(buf); 
	dirlt(2);  
	_dir();  

*/	
	printf(".....................................................\n");
	printf("command:delete myfile.c\n");
	delete("myfile.c");
	printf(".....................................................\n");
	printf("command:list\n");
	dirlt(2);   //再次列出目录
	_dir();   
	
/*	printf("\nin---->creat(ab_file3.c)\n");
	file_block=BLOCKSIZ*8+300;
	ab_fd4=creat(user_id,"ab_fi1e3.c",01777);
	buf=(char *)malloc(BLOCKSIZ *8+300);
	write(ab_fd4,buf,BLOCKSIZ*8+300);
	close(user_id,ab_fd4);
	free(buf);
	
	dirlt(2);  
	_dir();  
	*/
/*	
	printf("\nin---->open(ab_file2.c)\n");
	file_block=BLOCKSIZ*3+100;
	ab_fd3=open(user_id,"ab_file2.c",FAPPEND);
	buf=(char *)malloc(BLOCKSIZ*3+100);
	write(ab_fd3,buf,BLOCKSIZ*3+100);
	close(user_id,ab_fd3);
	free(buf); 
	dirlt(2);  
	_dir();  
	*/
/*
	printf("\nin---->chdir()\n");
	chdir ("..");
	*/
	printf(".....................................................\n");
	printf("command:quit\n");
	halt( );
	/*注意:先删除调试10中的pause();语句。*/ 

}

⌨️ 快捷键说明

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