release/src/linux/linux/fs/jffs/intrep.c
/* If an obsolete node is partly going to be erased due to garbage
   collection, the part that isn't going to be erased must be filled
   with zeroes so that the scan of the flash will work smoothly next
   time.  (The data in the file could for instance be a JFFS image
   which could cause enormous confusion during a scan of the flash
   device if we didn't do this.)
     There are two phases in this procedure: First, the clearing of
   the name and data parts of the node. Second, possibly also clearing
   a part of the raw inode as well.  If the box is power cycled during
   the first phase, only the checksum of this node-to-be-cleared-at-
   the-end will be wrong.  If the box is power cycled during, or after,
   the clearing of the raw inode, the information like the length of
   the name and data parts are zeroed.  The next time the box is
   powered up, the scanning algorithm manages this faulty data too
   because:

   - The checksum is invalid and thus the raw inode must be discarded
     in any case.
   - If the lengths of the data part or the name part are zeroed, the
     scanning just continues after the raw inode.  But after the inode
     the scanning procedure just finds zeroes which is the same as
     dirt.

   So, in the end, this could never fail. :-)  Even if it does fail,
   the scanning algorithm should manage that too.  */
If an obsolete node is partly going to be erased due to garbage
collection, the part that isn't going to be erased must be filled
with zeroes so that the scan of the flash will work smoothly next
time.  (The data in the file could for instance be a JFFS image
which could cause enormous confusion during a scan of the flash
device if we didn't do this.)
There are two phases in this procedure: First, the clearing of
the name and data parts of the node. Second, possibly also clearing
a part of the raw inode as well.

The checksum is invalid and thus the raw inode must be discarded
in any case.
If the lengths of the data part or the name part are zeroed, the
scanning just continues after the raw inode.  But after the inode
the scanning procedure just finds zeroes which is the same as
dirt.

So, in the end, this could never fail. :-)  Even if it does fail,
the scanning algorithm should manage that too.
If an obsolete node is partly going to be erased due to garbage collection the part that isn ' t going to be erased must be filled with zeroes so that the scan of the flash will work smoothly next time . ( The data in the file could for instance be a JFFS image which could cause enormous confusion during a scan of the flash device if we didn ' t do this . ) There are two phases in this procedure : First the clearing of the name and data parts of the node . Second possibly also clearing a part of the raw inode as well . The checksum is invalid and thus the raw inode must be discarded in any case . If the lengths of the data part or the name part are zeroed the scanning just continues after the raw inode . But after the inode the scanning procedure just finds zeroes which is the same as dirt . So in the end this could never fail . : - ) Even if it does fail the scanning algorithm should manage that too .
static int
jffs_clear_end_of_node(struct jffs_control *c, __u32 erase_size)
{
	struct jffs_fm *fm;
	struct jffs_fmcontrol *fmc = c->fmc;
	__u32 zero_offset;
	__u32 zero_size;
	__u32 zero_offset_data;
	__u32 zero_size_data;
	__u32 cutting_raw_inode = 0;
	if (!(fm = jffs_cut_node(fmc, erase_size))) {
		D3(printk("jffs_clear_end_of_node(): fm == NULL\n"));
		return 0;
	}
	zero_offset = fmc->head->offset + erase_size;
	zero_size = fm->offset + fm->size - zero_offset;
	if (fm->size - zero_size < sizeof(struct jffs_raw_inode)) {
		cutting_raw_inode = sizeof(struct jffs_raw_inode)
				    - (fm->size - zero_size);
	}
	zero_offset_data = zero_offset + cutting_raw_inode;
	zero_size_data = zero_size - cutting_raw_inode;
	flash_safe_acquire(fmc->mtd);
	flash_memset(fmc->mtd, zero_offset_data, 0, zero_size_data);
	flash_safe_release(fmc->mtd);
	if (cutting_raw_inode) {
		flash_safe_acquire(fmc->mtd);
		flash_memset(fmc->mtd, zero_offset, 0,
			     cutting_raw_inode);
		flash_safe_release(fmc->mtd);
	}
	return 0;
}
static int jffs_clear_end_of_node ( struct jffs_control * c , __u32 erase_size ) { struct jffs_fm * fm ; struct jffs_fmcontrol * fmc = c -> fmc ; __u32 zero_offset ; __u32 zero_size ; __u32 zero_offset_data ; __u32 zero_size_data ; __u32 cutting_raw_inode = 0 ; if ( ! ( fm = jffs_cut_node ( fmc , erase_size ) ) ) { D3 ( printk ( " \n " ) ) ; return 0 ; } zero_offset = fmc -> head -> offset + erase_size ; zero_size = fm -> offset + fm -> size - zero_offset ; if ( fm -> size - zero_size < sizeof ( struct jffs_raw_inode ) ) { cutting_raw_inode = sizeof ( struct jffs_raw_inode ) - ( fm -> size - zero_size ) ; } zero_offset_data = zero_offset + cutting_raw_inode ; zero_size_data = zero_size - cutting_raw_inode ; flash_safe_acquire ( fmc -> mtd ) ; flash_memset ( fmc -> mtd , zero_offset_data , 0 , zero_size_data ) ; flash_safe_release ( fmc -> mtd ) ; if ( cutting_raw_inode ) { flash_safe_acquire ( fmc -> mtd ) ; flash_memset ( fmc -> mtd , zero_offset , 0 , cutting_raw_inode ) ; flash_safe_release ( fmc -> mtd ) ; } return 0 ; }
If an obsolete node is partly going to be erased due to garbage
collection, the part that isn't going to be erased must be filled
with zeroes so that the scan of the flash will work smoothly next
time.
If an obsolete node is partly going to be erased due to garbage collection the part that isn ' t going to be erased must be filled with zeroes so that the scan of the flash will work smoothly next time .
/* Where and how much shall we clear?  */ /* Do we have to clear the raw_inode explicitly?  */ /* First, clear the name and data fields.  */ /* Should we clear a part of the raw inode?  */ /* I guess it is ok to clear the raw inode in this order.  */