示例#1
0
int yaffs2_checkpt_open(yaffs_dev_t *dev, int writing)
{


	dev->checkpt_open_write = writing;

	/* Got the functions we need? */
	if (!dev->param.write_chunk_tags_fn ||
		!dev->param.read_chunk_tags_fn ||
		!dev->param.erase_fn ||
		!dev->param.bad_block_fn)
		return 0;

	if (writing && !yaffs2_checkpt_space_ok(dev))
		return 0;

	if (!dev->checkpt_buffer)
		dev->checkpt_buffer = YMALLOC_DMA(dev->param.total_bytes_per_chunk);
	if (!dev->checkpt_buffer)
		return 0;


	dev->checkpt_page_seq = 0;
	dev->checkpt_byte_count = 0;
	dev->checkpt_sum = 0;
	dev->checkpt_xor = 0;
	dev->checkpt_cur_block = -1;
	dev->checkpt_cur_chunk = -1;
	dev->checkpt_next_block = dev->internal_start_block;

	/* Erase all the blocks in the checkpoint area */
	if (writing) {
		memset(dev->checkpt_buffer, 0, dev->data_bytes_per_chunk);
		dev->checkpt_byte_offs = 0;
		return yaffs_checkpt_erase(dev);
	} else {
		int i;
		/* Set to a value that will kick off a read */
		dev->checkpt_byte_offs = dev->data_bytes_per_chunk;
		/* A checkpoint block list of 1 checkpoint block per 16 block is (hopefully)
		 * going to be way more than we need */
		dev->blocks_in_checkpt = 0;
		dev->checkpt_max_blocks = (dev->internal_end_block - dev->internal_start_block)/16 + 2;
		dev->checkpt_block_list = YMALLOC(sizeof(int) * dev->checkpt_max_blocks);
		if(!dev->checkpt_block_list)
			return 0;

		for (i = 0; i < dev->checkpt_max_blocks; i++)
			dev->checkpt_block_list[i] = -1;
	}

	return 1;
}
int yaffs_CheckpointOpen(yaffs_Device *dev, int forWriting)
{


	dev->checkpointOpenForWrite = forWriting;

	/* Got the functions we need? */
	if (!dev->writeChunkWithTagsToNAND ||
			!dev->readChunkWithTagsFromNAND ||
			!dev->eraseBlockInNAND ||
			!dev->markNANDBlockBad)
		return 0;

	if (forWriting && !yaffs_CheckpointSpaceOk(dev))
		return 0;

	if (!dev->checkpointBuffer)
		dev->checkpointBuffer = YMALLOC_DMA(dev->totalBytesPerChunk);
	if (!dev->checkpointBuffer)
		return 0;


	dev->checkpointPageSequence = 0;
	dev->checkpointByteCount = 0;
	dev->checkpointSum = 0;
	dev->checkpointXor = 0;
	dev->checkpointCurrentBlock = -1;
	dev->checkpointCurrentChunk = -1;
	dev->checkpointNextBlock = dev->internalStartBlock;

	/* Erase all the blocks in the checkpoint area */
	if (forWriting) {
		memset(dev->checkpointBuffer, 0, dev->nDataBytesPerChunk);
		dev->checkpointByteOffset = 0;
		return yaffs_CheckpointErase(dev);
	} else {
		int i;
		/* Set to a value that will kick off a read */
		dev->checkpointByteOffset = dev->nDataBytesPerChunk;
		/* A checkpoint block list of 1 checkpoint block per 16 block is (hopefully)
		 * going to be way more than we need */
		dev->blocksInCheckpoint = 0;
		dev->checkpointMaxBlocks = (dev->internalEndBlock - dev->internalStartBlock)/16 + 2;
		dev->checkpointBlockList = YMALLOC(sizeof(int) * dev->checkpointMaxBlocks);
		if(!dev->checkpointBlockList)
			return 0;

		for (i = 0; i < dev->checkpointMaxBlocks; i++)
			dev->checkpointBlockList[i] = -1;
	}

	return 1;
}