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

📄 alloc40.c

📁 reiser4progs ReiserFS V4 ReiserFs官方已经关闭 这个是1.0.6 2006-02-22发布的 给需要的朋友
💻 C
📖 第 1 页 / 共 2 页
字号:
	if ((res = aal_block_write(&block))) {		aal_error("Can't write bitmap block %llu. "			  "%s.", start, alloc->device->error);	} error_free_block:	aal_block_fini(&block);	return res;}/* Saves alloc40 data (bitmap in fact) to device */static errno_t alloc40_sync(reiser4_alloc_ent_t *entity) {	errno_t res = 0;	aal_assert("umka-366", entity != NULL);	aal_assert("umka-367", PLUG_ENT(entity)->bitmap != NULL);	/* Calling layout() function for saving all bitmap blocks to device	   block allocator lies on. */	if ((res = alloc40_layout(entity, cb_sync_bitmap, entity))) {		aal_error("Can't save bitmap to device.");		return res;	}	PLUG_ENT(entity)->state &= ~(1 << ENTITY_DIRTY);	return res;}/* Frees alloc40 instance and all helper structures like bitmap, crcmap, etc */static void alloc40_close(reiser4_alloc_ent_t *entity) {	alloc40_t *alloc = (alloc40_t *)entity;    	aal_assert("umka-368", alloc != NULL);	aal_assert("umka-369", alloc->bitmap != NULL);	reiser4_bitmap_close(alloc->bitmap);	aal_free(alloc->crc);	aal_free(alloc);}/* Marks specified region as used in block allocator */static errno_t alloc40_occupy(reiser4_alloc_ent_t *entity,			      uint64_t start, uint64_t count) {	alloc40_t *alloc = (alloc40_t *)entity;    	aal_assert("umka-370", alloc != NULL);	aal_assert("umka-371", alloc->bitmap != NULL);    	reiser4_bitmap_mark_region(alloc->bitmap,			       start, count);	alloc->state |= (1 << ENTITY_DIRTY);	return 0;}/* Marks specified region as free in blockallocator bitmap */static errno_t alloc40_release(reiser4_alloc_ent_t *entity,			       uint64_t start, uint64_t count) {	alloc40_t *alloc = (alloc40_t *)entity;    	aal_assert("umka-372", alloc != NULL);	aal_assert("umka-373", alloc->bitmap != NULL);    	reiser4_bitmap_clear_region(alloc->bitmap,				start, count);	alloc->state |= (1 << ENTITY_DIRTY);	return 0;}/* Tries to find specified @count of free blocks in block allocator. The first   block of the found free area is stored in @start. Actual found number of   blocks is retured to caller. This function is mostly needed for handling   extent allocation. */static uint64_t alloc40_allocate(reiser4_alloc_ent_t *entity,				 uint64_t *start, uint64_t count){	uint64_t found;	alloc40_t *alloc;		alloc = (alloc40_t *)entity;		aal_assert("umka-374", alloc != NULL);	aal_assert("umka-1771", start != NULL);	aal_assert("umka-375", alloc->bitmap != NULL);	/* Calling bitmap for gettign free area from it */	found = reiser4_bitmap_find_region(alloc->bitmap,				       start, count, 0);	/* Marking found region as occupied if its length more then zero.	   Probably we should implement more flexible behavior here. And	   probably we should do not mark found blocks as used in hope the	   caller will decide, that found area is not enough convenient for	   him. If so, he will call marking found area as occupied by hands. */	if (found > 0) {		reiser4_bitmap_mark_region(alloc->bitmap,				       *start, found);		alloc->state |= (1 << ENTITY_DIRTY);	}	return found;}/* Returns free blocks count */static uint64_t alloc40_free(reiser4_alloc_ent_t *entity) {	alloc40_t *alloc = (alloc40_t *)entity;	aal_assert("umka-376", alloc != NULL);	aal_assert("umka-377", alloc->bitmap != NULL);    	return reiser4_bitmap_cleared(alloc->bitmap);}/* Returns used blocks count */static uint64_t alloc40_used(reiser4_alloc_ent_t *entity) {	alloc40_t *alloc = (alloc40_t *)entity;    	aal_assert("umka-378", alloc != NULL);	aal_assert("umka-379", alloc->bitmap != NULL);	return reiser4_bitmap_marked(alloc->bitmap);}/* Checks whether specified blocks are used */int alloc40_occupied(reiser4_alloc_ent_t *entity, uint64_t start, uint64_t count) {	alloc40_t *alloc = (alloc40_t *)entity;    	aal_assert("umka-663", alloc != NULL);	aal_assert("umka-664", alloc->bitmap != NULL);	return reiser4_bitmap_test_region(alloc->bitmap,					  start, count, 1);}/* Checks whether specified blocks are unused */static int alloc40_available(reiser4_alloc_ent_t *entity,			     uint64_t start, 			     uint64_t count) {	alloc40_t *alloc = (alloc40_t *)entity;    	aal_assert("vpf-700", alloc != NULL);	aal_assert("vpf-701", alloc->bitmap != NULL);	return reiser4_bitmap_test_region(alloc->bitmap,					  start, count, 0);}static void cb_inval_warn(blk_t start, uint32_t ladler, uint32_t cadler) {	aal_error("Checksum mismatch in bitmap block %llu. Checksum "		  "is 0x%x, should be 0x%x.", start, ladler, cadler);}typedef void (*inval_func_t) (blk_t, uint32_t, uint32_t);/* Callback function for checking one bitmap block on validness. Here we just   calculate actual checksum and compare it with loaded one. */errno_t cb_valid_block(blk_t start, count_t width, void *data) {	inval_func_t inval_func;	alloc40_t *alloc;	errno_t res;		uint64_t offset;	uint32_t ladler;	uint32_t cadler;	uint32_t chunk;	uint32_t size;	uint32_t free;		char *current;	char *map;		alloc = (alloc40_t *)data;	inval_func = (inval_func_t)alloc->data;		size = alloc->blksize - CRC_SIZE;	map = alloc->bitmap->map;    	/* Getting pointer to next bitmap portion */	offset = start / size / 8;	current = map + (offset * size);	    	/* Getting the checksum from loaded crc map */	ladler = *((uint32_t *)(alloc->crc + (offset * CRC_SIZE)));	free = (map + alloc->bitmap->size) - current;    	/* Calculating adler checksumm for piece of bitmap */	chunk = free > size ? size : free;	if (chunk < size) {		void *fake;		if (!(fake = aal_calloc(size, 0xff)))			return -ENOMEM;		aal_memcpy(fake, current, chunk);		cadler = aux_adler32(0, fake, size);				aal_free(fake);	} else		cadler = aux_adler32(0, current, chunk);	/* If loaded checksum and calculated one are not equal, we have	   corrupted bitmap. */	res = (ladler != cadler) ? -ESTRUCT : 0;		if (res && inval_func)		inval_func(start, ladler, cadler);	return res;}/* Checks allocator on validness  */errno_t alloc40_valid(reiser4_alloc_ent_t *entity) {	alloc40_t *alloc = (alloc40_t *)entity;	aal_assert("umka-963", alloc != NULL);	aal_assert("umka-964", alloc->bitmap != NULL);	/* Calling layout function for traversing all the bitmap blocks with	   checking callback function. */	alloc->data = cb_inval_warn;	return alloc40_layout(entity, cb_valid_block, alloc);}/* Call @func for all blocks which belong to the same bitmap block as passed   @blk. It is needed for fsck. In the case it detremined that a block is not   corresponds to its value in block allocator, it should check all the related   (neighbour) blocks which are described by one bitmap block (4096 -   CRC_SIZE).*/errno_t alloc40_region(reiser4_alloc_ent_t *entity, blk_t blk, 		       region_func_t region_func, void *data) {	alloc40_t *alloc;	uint64_t start, size;    	aal_assert("vpf-554", entity != NULL);	aal_assert("umka-1746", region_func != NULL);    	alloc = (alloc40_t *)entity;    	aal_assert("vpf-710", alloc->bitmap != NULL);    	size = (alloc->blksize - CRC_SIZE) * 8;	start = (blk / size) * size;	/* The last region is of a smaller size. */	if (start + size > alloc->bitmap->total) {		size = alloc->bitmap->total - start;	}		/* Loop though the all blocks one bitmap block describes and calling	   passed @region_func for each of them. */   	return region_func(start, size, data);}reiser4_alloc_plug_t alloc40_plug = {	.p = {		.id = {ALLOC_REISER40_ID, 0, ALLOC_PLUG_TYPE},		.label = "alloc40",		.desc  = "Space allocator plugin.",	},		.open           = alloc40_open,	.close          = alloc40_close,	.create         = alloc40_create,	.assign         = alloc40_assign,	.extract        = alloc40_extract,	.sync           = alloc40_sync,	.pack           = alloc40_pack,	.unpack         = alloc40_unpack,	.print          = alloc40_print,	.used           = alloc40_used,	.free           = alloc40_free,	.valid          = alloc40_valid,	.layout         = alloc40_layout,	.occupied       = alloc40_occupied,	.available      = alloc40_available,	.set_state      = alloc40_set_state,	.get_state      = alloc40_get_state,	.layout_bad	= alloc40_layout_bad,	.region		= alloc40_region,	.occupy	        = alloc40_occupy,	.allocate       = alloc40_allocate,	.release        = alloc40_release,	.check_struct   = alloc40_check_struct};#endif

⌨️ 快捷键说明

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