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

📄 unmap_deal.c

📁 国内一位牛人自己开发的操作系统
💻 C
字号:
#include"memory.h"

#define WRONG_MEMORY_BODY	-1
#define WRONG_FILE_NUMBER	-2
#define WRONG_PROCESS_NUMBER	-3
#define WRONG_CAPABILITY	-4
#define WRONG_FILE_STATE	-5

int file_unmemory_map_deal(
	int file_number,struct capability *capability)
{
	int i,first_block;
	struct physical_block *b;
	struct file_window *f;

	if(file_number<0)
		return WRONG_FILE_NUMBER;
	if(file_number>=(*(memory_body->file_number)))
		return WRONG_FILE_NUMBER;	
	f=file_number+memory_body->file_window;
	if(!KERNEL_COMPARE_CAPABILITY(
			(f->file.capability),(*capability)))
		return WRONG_CAPABILITY;
	if(f->state!=FILE_OPEN)
		return WRONG_FILE_STATE;
	if((first_block=f->block_ring)>=0)
		for(i=first_block;;){
			b=i+memory_body->physical_block;
			clear_block_number(b);
			if((i=b->file_back)==first_block)
				break;
		}
	return 0;
}


int process_unmemory_map_deal(int process_number,
		int unmap_number,struct capability *capability)
{
	int i,j,first_block;
	struct physical_block *b;
	struct memory_process *p;
	
	if(process_number<0)
		return WRONG_PROCESS_NUMBER;
	if(process_number>=(*(memory_body->process_number)))
		return WRONG_PROCESS_NUMBER;
	p=memory_body->memory_process+process_number;

	if(!KERNEL_COMPARE_CAPABILITY(
			(p->capability),(*capability)))
		return WRONG_CAPABILITY;
	if(unmap_number>p->block_number)
		unmap_number=p->block_number;
	if((first_block=p->block_ring)<0)
		first_block=p->write_block_ring;
	if((j=first_block)>=0)
		for(i=0;i<unmap_number;i++){
			b=j+memory_body->physical_block;
			j=b->buf_back;
			clear_block_number(b);
			if(j==first_block)
				break;
		}
	return 0;
}

⌨️ 快捷键说明

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