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

📄 super.c

📁 阿基米德操作系统的源代码
💻 C
字号:

/////////////////////////////////////////////////
#include "general.h"

#include "hd_info_struct.h"
#include "dir_entry.h"
#include "msdos_dir_entry.h"
#include "d_inode.h"
#include "m_inode.h"
#include "buffer_head.h"
#include "fat_cache.h"
#include "file.h"
#include "hd_request_struct.h"
#include "super_block.h"

#include "common_head.h"
///////////////////////////////////////////////////////////////////////////
void read_boot(void)
{
	struct buffer_head * temp_buf;
	unsigned char	   * temp_pChar;

	long	             temp_partition;
	long	             temp_cyl,temp_head,temp_sec;
	////////////////////////////////////////////////////////
	temp_buf	   = raw_rblock(0,0,0,0);

	if ((temp_buf == NULL) ||
		(temp_buf->b_data[510] != 0x55) || 
		(temp_buf->b_data[511] != 0xAA))
		while(1);

	temp_pChar = temp_buf->b_data + 0x1be;
	while ((*temp_pChar) != 0x80)
		temp_pChar = temp_pChar + 0x10;

	temp_partition = *((long *)(temp_pChar + 0x08));
	temp_sec       = temp_partition % hd_info[0].sect;
	temp_partition = temp_partition / hd_info[0].sect;
	temp_head	   = temp_partition % hd_info[0].head;
	temp_cyl	   = temp_partition / hd_info[0].head;

	temp_buf	   = raw_rblock(0,temp_cyl,temp_head,temp_sec);

	if ((temp_buf == NULL) ||
		(temp_buf->b_data[510] != 0x55) || 
		(temp_buf->b_data[511] != 0xAA))
		while(1);

	temp_pChar = temp_buf->b_data + 506;
	partition_sector = *((long *)temp_pChar);

	return;
}
///////////////////////////////////////////////////////////////////////////
void read_partition(void)
{
	struct buffer_head * temp_buf;
	long               * temp_pLong;

	long	             temp_partition;
	long	             temp_cyl,temp_head,temp_sec;

	int		             i;
	////////////////////////////////////////////////////////
	temp_partition = partition_sector;

	temp_sec       = temp_partition % hd_info[0].sect;
	temp_partition = temp_partition / hd_info[0].sect;
	temp_head	   = temp_partition % hd_info[0].head;
	temp_cyl	   = temp_partition / hd_info[0].head;

	temp_buf	   = raw_rblock(0,temp_cyl,temp_head,temp_sec);

	if ((temp_buf == NULL) ||
		(temp_buf->b_data[510] != 0x55) || 
		(temp_buf->b_data[511] != 0xAA))
		while(1);

	temp_pLong = (long *)(temp_buf->b_data);
	nr_super_blocks = *temp_pLong++;
	sys_blocksize   = *temp_pLong++;
	if (nr_super_blocks > NR_SUPER - 2)
		while(1);

	nr_super_blocks = nr_super_blocks + 2;
	for (i = 2; i < nr_super_blocks; i++)
	{
		the_super_block[i].start_sect = *temp_pLong++;
		the_super_block[i].nr_sects   = *temp_pLong++;
	}
	return;
}
///////////////////////////////////////////////////////////////////////////
void read_superblock(void)
{

	struct buffer_head * temp_buf;
	long               * temp_pLong;

	long	             temp_superblock;
	long	             temp_cyl,temp_head,temp_sec;

	int		             i;
	//////////////////////////////////////////////////////////////////
	for (i = 2; i < nr_super_blocks; i++)
	{
		temp_superblock = the_super_block[i].start_sect;

		temp_sec        = temp_superblock % hd_info[0].sect;
		temp_superblock = temp_superblock / hd_info[0].sect;
		temp_head	    = temp_superblock % hd_info[0].head;
		temp_cyl	    = temp_superblock / hd_info[0].head;

		temp_buf	    = raw_rblock(0,temp_cyl,temp_head,temp_sec);
		if (temp_buf == NULL)
			while(1);
		temp_pLong      = (long *)(temp_buf->b_data);
		the_super_block[i].s_ninodes		= *temp_pLong++;
		the_super_block[i].s_nzones			= *temp_pLong++;
		the_super_block[i].s_imap_blocks	= *temp_pLong++;
		the_super_block[i].s_zmap_blocks	= *temp_pLong++;
		the_super_block[i].s_firstdatazone	= *temp_pLong++;
		the_super_block[i].s_magic			= *temp_pLong++;
		if (the_super_block[i].s_magic != SUPER_MAGIC)
			while(1);
	}
	return;
}
///////////////////////////////////////////////////////////////////////////
void read_maps(void)
{
	long   i,j;
	///////////////////////////////////////////////////////////////////////////////////////////////
	dir_file.f_inode		= NULL;
	dir_file.f_pos			= 0;
	dir_file.f_flag			= 0;
	dir_file.f_count		= 0;
	dir_file.f_reserved[0]	= 0;
	dir_file.f_reserved[1]	= 0;

	for (i = 0 ; i < NR_FILE ; i++)
	{
		file_table[i].f_inode		= NULL;
		file_table[i].f_pos			= 0;
		file_table[i].f_flag		= 0;
		file_table[i].f_count		= 0;
		file_table[i].f_reserved[0]	= 0;
		file_table[i].f_reserved[1]	= 0;
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
    for (i = 0 ; i < NR_INODE; i++)
	{
		inode_table[i].i_mode		= 0;
		inode_table[i].i_reserved	= 0;
		inode_table[i].i_nlinks		= 0;
		inode_table[i].i_mtime		= 0;
		inode_table[i].i_size		= 0;
		for (j = 0; j < 13; j++)
			inode_table[i].i_zone[j]= 0;

		inode_table[i].i_dev		= 0;
		inode_table[i].i_reserved0	= 0;
		inode_table[i].i_num		= 0;
		inode_table[i].i_dirt		= 0;
		inode_table[i].i_count		= 0;
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
	inode_table[0].i_mode			= 0x10;
	inode_table[0].i_nlinks			= 1;
	inode_table[0].i_mtime			= file_datetime;
	inode_table[0].i_size			= 0;
	inode_table[0].i_zone[0]		= 0;
	inode_table[0].i_dev			= 0;
	inode_table[0].i_num			= MSDOS_ROOT_INO;
	inode_table[0].i_dirt			= 0;
	inode_table[0].i_count			= 2;

	inode_table[1].i_mode			= 0x10;
	inode_table[1].i_nlinks			= 1;
	inode_table[1].i_mtime			= file_datetime;
	inode_table[1].i_size			= 0;
	inode_table[1].i_zone[0]		= 0;
	inode_table[1].i_dev			= 1;
	inode_table[1].i_num			= MSDOS_ROOT_INO;
	inode_table[1].i_dirt			= 0;
	inode_table[1].i_count			= 2;

	the_super_block[0].s_driver_root	= &inode_table[0];
	the_super_block[0].s_driver_pwd		= &inode_table[0];

	the_super_block[1].s_driver_root	= &inode_table[1];
	the_super_block[1].s_driver_pwd		= &inode_table[1];

	cache_init();
	///////////////////////////////////////////////////////////////////////////////////////////////
	for (i = 2; i < nr_super_blocks; i++)
	{
		for (j = 0 ; j < the_super_block[i].s_imap_blocks ; j++)
		{
			the_super_block[i].s_imap[j] = bread(i,j + 1,0);
			if (the_super_block[i].s_imap[j] == NULL)
				while(1);
			sys_buffer++;
		}
		for (j = 0 ; j < the_super_block[i].s_zmap_blocks ; j++)
		{
			the_super_block[i].s_zmap[j] = bread(i,j + the_super_block[i].s_imap_blocks + 1,0);
			if (the_super_block[i].s_zmap[j] == NULL)
				while(1);
			sys_buffer++;
		}
		the_super_block[i].s_imap[0]->b_data[0] |= 1;
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
	for (i = 2; i < nr_super_blocks; i++)
	{
		the_super_block[i].s_driver_root = the_super_block[i].s_driver_pwd = iget(i,1);
		the_super_block[i].s_driver_root->i_count++;
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
	current_root = current_pwd = the_super_block[2].s_driver_root;
	current_driver = 2;
	///////////////////////////////////////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////////////////////////
	return;
}
////////////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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