static int __jffs2_flush_wbuf(struct jffs2_sb_info *c, int pad){	int ret;	size_t retlen;	/* Nothing to do if not write-buffering the flash. In particular, we shouldn't	   del_timer() the timer we never initialised. */	if (!jffs2_is_writebuffered(c))		return 0;	if (!down_trylock(&c->alloc_sem)) {		up(&c->alloc_sem);		printk(KERN_CRIT "jffs2_flush_wbuf() called with alloc_sem not locked!\n");		BUG();	}	if (!c->wbuf_len)	/* already checked c->wbuf above */		return 0;	/* claim remaining space on the page	   this happens, if we have a change to a new block,	   or if fsync forces us to flush the writebuffer.	   if we have a switch to next page, we will not have	   enough remaining space for this. 	*/	if (pad && !jffs2_dataflash(c)) {		c->wbuf_len = PAD(c->wbuf_len);		/* Pad with JFFS2_DIRTY_BITMASK initially.  this helps out ECC'd NOR		   with 8 byte page size */		memset(c->wbuf + c->wbuf_len, 0, c->wbuf_pagesize - c->wbuf_len);				if ( c->wbuf_len + sizeof(struct jffs2_unknown_node) < c->wbuf_pagesize) {			struct jffs2_unknown_node *padnode = (void *)(c->wbuf + c->wbuf_len);			padnode->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);			padnode->nodetype = cpu_to_je16(JFFS2_NODETYPE_PADDING);			padnode->totlen = cpu_to_je32(c->wbuf_pagesize - c->wbuf_len);			padnode->hdr_crc = cpu_to_je32(crc32(0, padnode, sizeof(*padnode)-4));		}	}	/* else jffs2_flash_writev has actually filled in the rest of the	   buffer for us, and will deal with the node refs etc. later. */	#ifdef BREAKME	static int breakme;	if (breakme++ == 20) {		printk(KERN_NOTICE "Faking write error at 0x%08x\n", c->wbuf_ofs);		breakme = 0;		c->mtd->write_ecc(c->mtd, c->wbuf_ofs, c->wbuf_pagesize,					&retlen, brokenbuf, NULL, c->oobinfo);		ret = -EIO;	} else #endif		if (jffs2_cleanmarker_oob(c))		ret = c->mtd->write_ecc(c->mtd, c->wbuf_ofs, c->wbuf_pagesize, &retlen, c->wbuf, NULL, c->oobinfo);	else		ret = c->mtd->write(c->mtd, c->wbuf_ofs, c->wbuf_pagesize, &retlen, c->wbuf);	if (ret || retlen != c->wbuf_pagesize) {		if (ret)			printk(KERN_WARNING "jffs2_flush_wbuf(): Write failed with %d\n",ret);		else {			printk(KERN_WARNING "jffs2_flush_wbuf(): Write was short: %zd instead of %d\n",				retlen, c->wbuf_pagesize);			ret = -EIO;		}		jffs2_wbuf_recover(c);		return ret;	}	spin_lock(&c->erase_completion_lock);	/* Adjust free size of the block if we padded. */	if (pad && !jffs2_dataflash(c)) {		struct jffs2_eraseblock *jeb;		jeb = &c->blocks[c->wbuf_ofs / c->sector_size];		D1(printk(KERN_DEBUG "jffs2_flush_wbuf() adjusting free_size of %sblock at %08x\n",			  (jeb==c->nextblock)?"next":"", jeb->offset));		/* wbuf_pagesize - wbuf_len is the amount of space that's to be 		   padded. If there is less free space in the block than that,		   something screwed up */		if (jeb->free_size < (c->wbuf_pagesize - c->wbuf_len)) {			printk(KERN_CRIT "jffs2_flush_wbuf(): Accounting error. wbuf at 0x%08x has 0x%03x bytes, 0x%03x left.\n",			       c->wbuf_ofs, c->wbuf_len, c->wbuf_pagesize-c->wbuf_len);			printk(KERN_CRIT "jffs2_flush_wbuf(): But free_size for block at 0x%08x is only 0x%08x\n",			       jeb->offset, jeb->free_size);			BUG();		}		jeb->free_size -= (c->wbuf_pagesize - c->wbuf_len);		c->free_size -= (c->wbuf_pagesize - c->wbuf_len);		jeb->wasted_size += (c->wbuf_pagesize - c->wbuf_len);		c->wasted_size += (c->wbuf_pagesize - c->wbuf_len);	}	/* Stick any now-obsoleted blocks on the erase_pending_list */	jffs2_refile_wbuf_blocks(c);	jffs2_clear_wbuf_ino_list(c);	spin_unlock(&c->erase_completion_lock);	memset(c->wbuf,0xff,c->wbuf_pagesize);	/* adjust write buffer offset, else we get a non contiguous write bug */	c->wbuf_ofs += c->wbuf_pagesize;	c->wbuf_len = 0;	return 0;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/daba5cc4bcd025a9b4fd02a9117c71bfd400d811/wbuf.c/clean/fs/jffs2/wbuf.c