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

📄 fat_access.c

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

///////////////////////////////////////////////////////////////////////////////////////////
#include "general.h"
#include "clear_sector.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"
///////////////////////////////////////////////////////////////////////////////////////////
int fat_access(int fatno,int new_value){	struct buffer_head	*temp_bh0, *temp_bh1, *temp_cbh0, *temp_cbh1;
	unsigned char		*temp_pfirst, *temp_plast, *temp_cpfirst, *temp_cplast;
	int					 temp_first, temp_last, temp_next;
	temp_first	= ((fatno << 1) + fatno) >> 1;	temp_last	= temp_first + 1;

	temp_pfirst = start_buffer->b_data + 512 + temp_first;
	temp_plast	= start_buffer->b_data + 512 + temp_last;
	
	if (fatno & 0x01)
		temp_next = ((*temp_pfirst >> 4) | (*temp_plast << 4)) & 0xfff;
	else
		temp_next = ((*temp_pfirst) | (*temp_plast << 8)) & 0xfff;
	if (temp_next >= 0xff8)
		temp_next = -1;

	if (new_value != -1)
	{
		temp_bh0	= start_buffer + ((temp_first + 512) >> 10);
		temp_bh1	= start_buffer + ((temp_last  + 512) >> 10);
		temp_cbh0	= start_buffer + (temp_first >> 10) + 5;
		temp_cbh1	= start_buffer + (temp_last  >> 10) + 5;
		temp_cpfirst= temp_pfirst  + 9 * 512;
		temp_cplast = temp_plast   + 9 * 512;

		if (fatno & 0x01)
		{
			*temp_pfirst = (*temp_pfirst & 0x0f) | (new_value << 4); 
			*temp_plast	 = new_value >> 4;
		}
		else
		{
			*temp_pfirst = new_value & 0xff;
			*temp_plast	 = (*temp_plast & 0xf0) | (new_value >> 8);
		}

		*temp_cpfirst = *temp_pfirst;
		*temp_cplast  = *temp_plast;

		temp_bh0->b_dirt  = temp_bh1->b_dirt  = 1;
		temp_cbh0->b_dirt = temp_cbh1->b_dirt = 1;
	}
	return temp_next;}
int new_cluster(void)
{
	struct buffer_head * temp_bh;
	unsigned char      * temp_pChar;
	int	temp_block, temp_sector;
	int	temp_fatno, temp_flag;

	temp_fatno	= current_fatno;
	temp_flag	= 0;
	do {
		if (fat_access(temp_fatno, -1) == 0)
		{
			current_fatno = temp_fatno;
			current_fatno++;
			if (current_fatno == 2849)
				current_fatno = 2;
			temp_flag	  = 1;
			break;
		}
		temp_fatno++;
		if (temp_fatno == 2849)
			temp_fatno = 2;
	} while (temp_fatno != current_fatno);
	if (!temp_flag)
		return -1;

	temp_sector	= temp_fatno + 31;
	temp_block	= temp_sector / 2;
	if (!(temp_bh = bread(0,temp_block,0)))
		return -1;
	if (temp_sector & 0x01)
		temp_pChar = temp_bh->b_data + 512;
	else
		temp_pChar = temp_bh->b_data;
	clear_sector(temp_pChar);
	temp_bh->b_dirt = 1;
	brelse(temp_bh);

	fat_access(temp_fatno, 0xfff);
	return temp_fatno;
}

void free_cluster(int fatno)
{
	fat_access(fatno, 0);
	return;
}

void do_clrsector(int fatno) 
{
	struct buffer_head * temp_bh;
	unsigned char      * temp_pChar;
	int	temp_block, temp_sector;

	if (fatno < 2)
		return;

	temp_sector	= fatno + 31;
	temp_block	= temp_sector / 2;
	if (!(temp_bh = bread(0,temp_block,0)))
		return;
	if (temp_sector & 0x01)
		temp_pChar = temp_bh->b_data + 512;
	else
		temp_pChar = temp_bh->b_data;
	clear_sector(temp_pChar);
	temp_bh->b_dirt = 1;
	brelse(temp_bh);

	return;
}

⌨️ 快捷键说明

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