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

📄 cache_init.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 cache_init(void)
{
	int temp_count;

	fat_cache = &cache[0];
	for (temp_count = 0; temp_count < FAT_CACHE - 1; temp_count++) {
		cache[temp_count].ino			= 0;
		cache[temp_count].file_cluster	= 0;
		cache[temp_count].disk_cluster	= 0;
		cache[temp_count].next			= &cache[temp_count + 1];
	}
	cache[temp_count].ino			= 0;
	cache[temp_count].file_cluster	= 0;
	cache[temp_count].disk_cluster	= 0;
	cache[temp_count].next			= NULL;

	return;
}

void cache_inval_dev(void)
{
	int	temp_i;

	for (temp_i = 0; temp_i < FAT_CACHE; temp_i++)
		cache[temp_i].ino = 0;

	return;
}

void cache_inval_inode(struct m_inode * inode)
{
	struct fat_cache * temp_fatcache, * temp_fatcache0;
	unsigned long temp_inum;
	int	   temp_i;

	temp_inum = inode->i_num;
	while (fat_cache && (fat_cache->ino == temp_inum))
	{
		fat_cache->ino		= 0;
		fat_cache			= fat_cache->next;
	}
	temp_fatcache	= fat_cache;
	temp_fatcache0	= fat_cache;
	while (temp_fatcache0)
	{
		if (temp_fatcache0->ino == temp_inum)
		{
			temp_fatcache0->ino = 0;
			temp_fatcache->next	= temp_fatcache0->next;
		}
		else
			temp_fatcache		= temp_fatcache0;
		temp_fatcache0		= temp_fatcache0->next;
	}

	temp_fatcache0	= NULL;
	for (temp_i = 0; temp_i < FAT_CACHE; temp_i++)
		if (cache[temp_i].ino == 0)
		{
			cache[temp_i].next	= temp_fatcache0;
			temp_fatcache0		= &cache[temp_i];
		}

	if (temp_fatcache)
		temp_fatcache->next	= temp_fatcache0;
	else
		fat_cache			= temp_fatcache0;

	return;
}

void cache_lookup(struct m_inode * inode,int cluster,int * f_clu,int * d_clu)
{
	struct fat_cache * temp_fatcache, * temp_fatcache0;
	unsigned long temp_inum;

	temp_inum		= inode->i_num;
	temp_fatcache	= NULL;
	for (temp_fatcache0 = fat_cache; temp_fatcache0; temp_fatcache0 = (temp_fatcache = temp_fatcache0)->next)
		if (temp_fatcache0->ino == temp_inum && temp_fatcache0->file_cluster <= cluster && temp_fatcache0->file_cluster > *f_clu) {
			*f_clu = temp_fatcache0->file_cluster;			
			*d_clu = temp_fatcache0->disk_cluster;
			if (*f_clu == cluster)
			{
				if (temp_fatcache)
				{
					temp_fatcache->next = temp_fatcache0->next;
					temp_fatcache0->next= fat_cache;
					fat_cache			= temp_fatcache0;
				}
				return;
			}
		}
	return;
}

void cache_add(struct m_inode * inode,int f_clu,int d_clu)
{
	struct fat_cache * temp_fatcache, * temp_fatcache0;
	unsigned long temp_inum;

	temp_inum	  = inode->i_num;
	temp_fatcache = NULL;
	for (temp_fatcache0 = fat_cache; temp_fatcache0->next; temp_fatcache0 = (temp_fatcache = temp_fatcache0)->next)
		if (temp_fatcache0->ino == temp_inum && temp_fatcache0->file_cluster == f_clu) 
		{
			if (temp_fatcache)
			{
				temp_fatcache->next	= temp_fatcache0->next;
				temp_fatcache0->next= fat_cache;
				fat_cache			= temp_fatcache0;
			}
			return;
		}

	temp_fatcache0->ino				= temp_inum;
	temp_fatcache0->file_cluster	= f_clu;
	temp_fatcache0->disk_cluster	= d_clu;
	temp_fatcache->next				= NULL;
	temp_fatcache0->next			= fat_cache;
	fat_cache						= temp_fatcache0;
	
	return;
}

⌨️ 快捷键说明

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