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

📄 node40.c

📁 reiser4progs ReiserFS V4 ReiserFs官方已经关闭 这个是1.0.6 2006-02-22发布的 给需要的朋友
💻 C
📖 第 1 页 / 共 4 页
字号:
/* Copyright (C) 2001-2005 by Hans Reiser, licensing governed by   reiser4progs/COPYING.      node40.c -- reiser4 node plugin functions. */#include "node40.h"#include "node40_repair.h"reiser4_core_t *node40_core = NULL;/* Return item header void pointer by pos. As node40 is able to work with   different item types (short keys, large ones), we do not use item struct at   all. But prefer to use raw pointers along with macros for working with   them. */void *node40_ih_at(reiser4_node_t *entity, uint32_t pos) {	void *ih = entity->block->data + entity->block->size;	return (ih - (ih_size(entity->keypol) * (pos + 1)));}#define node40_ib_by_ih(entity, ih) \	entity->block->data + ih_get_offset(ih, entity->keypol)/* Retutrn item body by pos */void *node40_ib_at(reiser4_node_t *entity, uint32_t pos) {	void *ih = node40_ih_at(entity, pos);	return node40_ib_by_ih(entity, ih);}/* Returns node level field. */uint8_t node40_get_level(reiser4_node_t *entity) {	aal_assert("umka-1116", entity != NULL);	return nh_get_level((reiser4_node_t *)entity);}reiser4_node_t *node40_prepare(aal_block_t *block, reiser4_key_plug_t *kplug) {	reiser4_node_t *entity;		aal_assert("umka-2376", kplug != NULL);	aal_assert("umka-2375", block != NULL);		if (!(entity = aal_calloc(sizeof(*entity), 0)))		return NULL;	entity->kplug = kplug;	entity->block = block;	entity->plug = &node40_plug;	entity->keypol = plugcall(kplug, bodysize);	return entity;}#ifndef ENABLE_MINIMAL/* Functions for making node dirty, cleann and for check if it is dirty. This is   used in all node modifying functions, etc. */void node40_mkdirty(reiser4_node_t *entity) {	aal_assert("umka-3016", entity != NULL);	entity->block->dirty = 1;}void node40_mkclean(reiser4_node_t *entity) {	aal_assert("umka-3017", entity != NULL);	entity->block->dirty = 0;}int node40_isdirty(reiser4_node_t *entity) {	aal_assert("umka-3018", entity != NULL);	return entity->block->dirty;}static uint32_t node40_get_state(reiser4_node_t *entity) {	aal_assert("umka-2091", entity != NULL);	return entity->state;}static void node40_set_state(reiser4_node_t *entity,			     uint32_t state){	aal_assert("umka-2092", entity != NULL);	entity->state = state;}/* Returns node mkfs stamp. */static uint32_t node40_get_mstamp(reiser4_node_t *entity) {	aal_assert("umka-1127", entity != NULL);	return nh_get_mkfs_id(entity);}/* Returns node flush stamp. */static uint64_t node40_get_fstamp(reiser4_node_t *entity) {	aal_assert("vpf-645", entity != NULL);	return nh_get_flush_id(entity);}/* Initializes node of the given @level on the @block with key plugin   @kplug. Returns initialized node instance. */static reiser4_node_t *node40_init(aal_block_t *block, uint8_t level,				   reiser4_key_plug_t *kplug){	reiser4_node_t *entity;	aal_assert("umka-2374", block != NULL);	aal_assert("vpf-1417",  kplug != NULL);		if (!(entity = node40_prepare(block, kplug)))		return NULL;		nh_set_num_items(entity, 0);	nh_set_level(entity, level);	nh_set_magic(entity, NODE40_MAGIC);	nh_set_pid(entity, node40_plug.p.id.id);		nh_set_free_space_start(entity, sizeof(node40_header_t));	nh_set_free_space(entity, block->size - sizeof(node40_header_t));	return entity;}/* Saves node to device */static errno_t node40_sync(reiser4_node_t *entity) {	errno_t res;		aal_assert("umka-1552", entity != NULL);	if ((res = aal_block_write(entity->block)))		return res;	node40_mkclean(entity);	return 0;}#endif/* Closes node by means of closing its block */static errno_t node40_fini(reiser4_node_t *entity) {	aal_assert("umka-825", entity != NULL);	aal_block_free(entity->block);	entity->plug = NULL;	aal_free(entity);		return 0;}/* Returns item number in passed node entity. Used for any loops through the all   node items. */uint32_t node40_items(reiser4_node_t *entity) {	aal_assert("vpf-018", entity != NULL);	return nh_get_num_items(entity);}#ifndef ENABLE_MINIMAL/* Returns node free space. */uint16_t node40_space(reiser4_node_t *entity) {	aal_assert("vpf-020", entity != NULL);	return nh_get_free_space(entity);}/* Sets node make stamp. */static void node40_set_mstamp(reiser4_node_t *entity,			      uint32_t stamp){	aal_assert("vpf-644", entity != NULL);	nh_set_mkfs_id(entity, stamp);	node40_mkdirty(entity);}/* Returns node flush stamp */static void node40_set_fstamp(reiser4_node_t *entity,			      uint64_t stamp){	aal_assert("vpf-643", entity != NULL);		nh_set_flush_id(entity, stamp);	node40_mkdirty(entity);}/* Set new node level to @level. */static void node40_set_level(reiser4_node_t *entity,			     uint8_t level){	aal_assert("umka-1864", entity != NULL);		nh_set_level(entity, level);	node40_mkdirty(entity);}#endifstatic uint16_t node40_len_by_ih(reiser4_node_t *entity, void *ih, 				 pos_t *pos, uint16_t items) {	uint8_t pol = entity->keypol;	/* Item length is calculated as next item offset minus current item	   offset. If we're on the last item then we use free space start	   instead.*/	if (pos->item + 1 == items) {		return nh_get_free_space_start(entity) -			ih_get_offset(ih, pol);	} else {		return ih_get_offset((ih - ih_size(pol)), pol) -			ih_get_offset(ih, pol);	}}/* Returns length of item at pos. */uint16_t node40_len(reiser4_node_t *entity, pos_t *pos) {	void *ih;    	aal_assert("umka-942", pos != NULL);	aal_assert("vpf-037", entity != NULL);	ih = node40_ih_at(entity, pos->item);	return node40_len_by_ih(entity, ih, pos, 				nh_get_num_items(entity));}/* Open the node on the given @block with the given key plugin @kplug. Returns   initialized node instance. */static reiser4_node_t *node40_open(aal_block_t *block,				   reiser4_key_plug_t *kplug){	reiser4_node_t *entity;		aal_assert("vpf-1415", kplug != NULL);	aal_assert("vpf-1416", block != NULL);		if (!(entity = node40_prepare(block, kplug)))		return NULL;	/* Check the magic. */	if (nh_get_magic(entity) != NODE40_MAGIC) {		aal_free(entity);		return NULL;	}		return entity;}static void node40_get_key_by_ih(reiser4_node_t *entity, void *ih, 				 reiser4_key_t *key) {	uint32_t size;		key->plug = entity->kplug;	size = key_size(entity->keypol);	aal_memcpy(key->body, ih, size);}/* Returns key at passed @pos. */static errno_t node40_get_key(reiser4_node_t *entity,			      pos_t *pos, reiser4_key_t *key) {	void *ih;    	aal_assert("umka-821", key != NULL);	aal_assert("umka-939", pos != NULL);		aal_assert("umka-2333", entity != NULL);	ih = node40_ih_at(entity, pos->item);			/* Allow to fetch the item at pos > item count;	   but prevent segfault on errors. */	aal_assert("vpf-1661", ih > entity->block->data);	node40_get_key_by_ih(entity, ih, key);		return 0;}/* Initializes @place at @pos. Fetches all item fields. */errno_t node40_fetch(reiser4_node_t *entity,		     pos_t *pos, reiser4_place_t *place){	void *ih;		aal_assert("umka-1813", pos != NULL);	aal_assert("umka-1602", place != NULL);	aal_assert("umka-1631", entity != NULL);		ih = node40_ih_at(entity, pos->item);		/* Allow to fetch the item at pos > item count;	   but prevent segfault on errors. */	aal_assert("vpf-1660", ih > entity->block->data);	/* Initializing other fields. */	place->pos = *pos;	place->node = entity;	place->body = node40_ib_by_ih(entity, ih);	place->len = node40_len_by_ih(entity, ih, pos, 				      nh_get_num_items(entity));	/* Getting item key. */	node40_get_key_by_ih(entity, ih, &place->key);	/* Initializing item's plugin. */	place->plug = (reiser4_item_plug_t *)		node40_core->factory_ops.ifind(ITEM_PLUG_TYPE, 					       ih_get_pid(ih, entity->keypol));		if (!place->plug) {		aal_error("Can't find item plugin by its id 0x%x.",			  ih_get_pid(ih, entity->keypol));		return -EINVAL;	}	/* Init item specific stuff. */	if (place->plug->balance->init) {		place->plug->balance->init(place);	} else {		/* Zero all item-specific fields here. */		place->off = 0;	}		return 0;}#ifndef ENABLE_MINIMAL/* Retutns item overhead for this node format. Widely used in modification and   estimation routines. */static uint16_t node40_overhead(reiser4_node_t *entity) {	return ih_size(entity->keypol);}/* Returns maximal size of item possible for passed node instance */static uint16_t node40_maxspace(reiser4_node_t *entity) {	aal_assert("vpf-016", entity != NULL);		/* Maximal space is node size minus node header and minus item	   header. */	return (entity->block->size - sizeof(node40_header_t) -		ih_size(entity->keypol));}/* Calculates size of a region denoted by @pos and @count. This is used by   node40_copy(), node40_remove(), etc. */uint32_t node40_size(reiser4_node_t *entity, pos_t *pos, uint32_t count) {	void *ih;	uint32_t len;	aal_assert("umka-3032", pos != NULL);	aal_assert("umka-3031", entity != NULL);	ih = node40_ih_at(entity, pos->item);		if (pos->item + count < nh_get_num_items(entity)) {		uint32_t offset = (ih_size(entity->keypol) * count);		len = ih_get_offset((ih - offset), entity->keypol);	} else {		len = nh_get_free_space_start(entity);	}	return len - ih_get_offset(ih, entity->keypol);}/* Makes expand passed @node by @len in odrer to make room for insert new   items/units. This function is used by insert and shift methods. */errno_t node40_expand(reiser4_node_t *entity, pos_t *pos,		      uint32_t len, uint32_t count){	void *ih;	int insert;	uint32_t item;	uint32_t items;	uint32_t offset;	uint32_t headers;	aal_assert("vpf-006", pos != NULL);	aal_assert("umka-817", entity != NULL);	if (len == 0)		return 0;		headers = count * ih_size(entity->keypol);	items = nh_get_num_items(entity);	insert = (pos->unit == MAX_UINT32);	/* Getting real pos of the item to be updated. */	item = pos->item + !insert;	ih = node40_ih_at(entity, item);	/* If item pos is inside the range [0..count - 1], we should perform the	   data moving and offset upadting. */	if (item < items) {		void *src, *dst;		uint32_t i, size;		/* Moving items bodies */		offset = ih_get_offset(ih, entity->keypol);		src = entity->block->data + offset;		dst = entity->block->data + offset + len;		size = nh_get_free_space_start(entity) - offset;		aal_memmove(dst, src, size);		/* Updating item offsets. */		for (i = 0; i < items - item; i++) {			ih_inc_offset(ih, len, entity->keypol);			ih -= ih_size(entity->keypol);		}		/* If this is the insert new item mode, we should prepare the		   room for new item header and set it up. */		if (insert) {			src = node40_ih_at(entity, items - 1);			dst = node40_ih_at(entity, items - 1 +					   count);			size = ih_size(entity->keypol) * (items - item);						aal_memmove(dst, src, size);		}		ih = node40_ih_at(entity, item);	} else {		offset = nh_get_free_space_start(entity);	}	/* Updating node's free space and free space start fields. */	nh_inc_free_space_start(entity, len);

⌨️ 快捷键说明

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