示例#1
0
void ubiblk_setup_writecache(struct ubiblk_dev *ubiblk, int virt_block)
{
	ubiblk->vbw = virt_block;
	ubiblk->write_cache_state = STATE_USED;

	ubi_leb_read(ubiblk->uv, ubiblk->vbw, ubiblk->write_cache, 0, 
		     ubiblk->uv->vol->usable_leb_size, UBI_UNKNOWN);
}
示例#2
0
int ubifs_leb_read(const struct ubifs_info *c, int lnum, void *buf, int offs,
		   int len, int even_ebadmsg)
{
	int err;

	err = ubi_leb_read(c->ubi, lnum, buf, offs, len, 0);
	/*
	 * In case of %-EBADMSG print the error message only if the
	 * @even_ebadmsg is true.
	 */
	if (err && (err != -EBADMSG || even_ebadmsg)) {
		ubifs_err("reading %d bytes from LEB %d:%d failed, error %d",
			  len, lnum, offs, err);
		dbg_dump_stack();
	}
	return err;
}
示例#3
0
static int do_cached_read (struct ubiblk_dev *ubiblk, unsigned long sector, 
			   int len, char *buf)
{
	struct ubi_volume_desc *uv = ubiblk->uv;
	int ppb = uv->vol->ubi->leb_size / uv->vol->ubi->min_io_size;
	unsigned short sectors_per_page =  uv->vol->ubi->min_io_size >> 9;
	unsigned short page_shift =  ffs(uv->vol->ubi->min_io_size) - 1;
	unsigned short virt_block, page, page_offset; 	
	unsigned long virt_page; 
		
	virt_page = sector / sectors_per_page;
	page_offset = sector % sectors_per_page;
	virt_block = virt_page / ppb; 
	page = virt_page % ppb;

	if(ubiblk->vbw == virt_block){		
		mutex_lock(&ubiblk->cache_mutex);
		ubiblk_flush_writecache(ubiblk);
		mutex_unlock(&ubiblk->cache_mutex);
	}

	if ( ubi_is_mapped( uv, virt_block) == UNMAPPED){
		// In a Flash Memory device, there might be a logical block that is
		// not allcated to a physical block due to the block not being used.
		// All data returned should be set to 0xFF when accessing this logical 
		// block.
		//	dprintk("address translate fail\n");
		memset(buf, 0xFF, 512);
	} else {

		if( ubiblk->vbr != virt_block ||ubiblk->read_cache_state == STATE_UNUSED ){
			ubiblk->vbr = virt_block;
			ubi_leb_read(uv, virt_block, ubiblk->read_cache, 0, uv->vol->usable_leb_size, 0);				
			ubiblk->read_cache_state = STATE_USED;
		}
		memcpy(buf, &ubiblk->read_cache[(page<<page_shift)+(page_offset<<9)], len);
	}
	return 0;
}