2007-10-10 21:05:48 +03:00
|
|
|
/*
|
|
|
|
* YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
|
|
|
|
*
|
2012-10-30 16:58:17 +02:00
|
|
|
* Copyright (C) 2002-2010 Aleph One Ltd.
|
2007-10-10 21:05:48 +03:00
|
|
|
* for Toby Churchill Ltd and Brightstar Engineering
|
|
|
|
*
|
|
|
|
* Created by Charles Manning <charles@aleph1.co.uk>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "yaffs_checkptrw.h"
|
2012-10-30 16:58:13 +02:00
|
|
|
#include "yaffs_getblockinfo.h"
|
2007-10-10 21:05:48 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
static int yaffs2_checkpt_space_ok(yaffs_dev_t *dev)
|
2007-10-10 21:05:48 +03:00
|
|
|
{
|
2012-10-30 16:58:17 +02:00
|
|
|
int blocksAvailable = dev->n_erased_blocks - dev->param.n_reserved_blocks;
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2007-10-10 21:05:48 +03:00
|
|
|
T(YAFFS_TRACE_CHECKPOINT,
|
|
|
|
(TSTR("checkpt blocks available = %d" TENDSTR),
|
|
|
|
blocksAvailable));
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2007-10-10 21:05:48 +03:00
|
|
|
return (blocksAvailable <= 0) ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
static int yaffs_checkpt_erase(yaffs_dev_t *dev)
|
2007-10-10 21:05:48 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (!dev->param.erase_fn)
|
2007-10-10 21:05:48 +03:00
|
|
|
return 0;
|
2012-10-30 16:58:13 +02:00
|
|
|
T(YAFFS_TRACE_CHECKPOINT, (TSTR("checking blocks %d to %d"TENDSTR),
|
2012-10-30 16:58:17 +02:00
|
|
|
dev->internal_start_block, dev->internal_end_block));
|
2012-10-30 16:58:13 +02:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
for (i = dev->internal_start_block; i <= dev->internal_end_block; i++) {
|
|
|
|
yaffs_block_info_t *bi = yaffs_get_block_info(dev, i);
|
|
|
|
if (bi->block_state == YAFFS_BLOCK_STATE_CHECKPOINT) {
|
2012-10-30 16:58:13 +02:00
|
|
|
T(YAFFS_TRACE_CHECKPOINT, (TSTR("erasing checkpt block %d"TENDSTR), i));
|
2012-10-30 16:58:17 +02:00
|
|
|
|
|
|
|
dev->n_erasures++;
|
|
|
|
|
|
|
|
if (dev->param.erase_fn(dev, i - dev->block_offset /* realign */)) {
|
|
|
|
bi->block_state = YAFFS_BLOCK_STATE_EMPTY;
|
|
|
|
dev->n_erased_blocks++;
|
|
|
|
dev->n_free_chunks += dev->param.chunks_per_block;
|
2012-10-30 16:58:13 +02:00
|
|
|
} else {
|
2012-10-30 16:58:17 +02:00
|
|
|
dev->param.bad_block_fn(dev, i);
|
|
|
|
bi->block_state = YAFFS_BLOCK_STATE_DEAD;
|
2007-10-10 21:05:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
dev->blocks_in_checkpt = 0;
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2007-10-10 21:05:48 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
static void yaffs2_checkpt_find_erased_block(yaffs_dev_t *dev)
|
2007-10-10 21:05:48 +03:00
|
|
|
{
|
|
|
|
int i;
|
2012-10-30 16:58:17 +02:00
|
|
|
int blocksAvailable = dev->n_erased_blocks - dev->param.n_reserved_blocks;
|
2007-10-10 21:05:48 +03:00
|
|
|
T(YAFFS_TRACE_CHECKPOINT,
|
|
|
|
(TSTR("allocating checkpt block: erased %d reserved %d avail %d next %d "TENDSTR),
|
2012-10-30 16:58:17 +02:00
|
|
|
dev->n_erased_blocks, dev->param.n_reserved_blocks, blocksAvailable, dev->checkpt_next_block));
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (dev->checkpt_next_block >= 0 &&
|
|
|
|
dev->checkpt_next_block <= dev->internal_end_block &&
|
2012-10-30 16:58:13 +02:00
|
|
|
blocksAvailable > 0) {
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
for (i = dev->checkpt_next_block; i <= dev->internal_end_block; i++) {
|
|
|
|
yaffs_block_info_t *bi = yaffs_get_block_info(dev, i);
|
|
|
|
if (bi->block_state == YAFFS_BLOCK_STATE_EMPTY) {
|
|
|
|
dev->checkpt_next_block = i + 1;
|
|
|
|
dev->checkpt_cur_block = i;
|
2012-10-30 16:58:13 +02:00
|
|
|
T(YAFFS_TRACE_CHECKPOINT, (TSTR("allocating checkpt block %d"TENDSTR), i));
|
2007-10-10 21:05:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-10-30 16:58:13 +02:00
|
|
|
T(YAFFS_TRACE_CHECKPOINT, (TSTR("out of checkpt blocks"TENDSTR)));
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
dev->checkpt_next_block = -1;
|
|
|
|
dev->checkpt_cur_block = -1;
|
2007-10-10 21:05:48 +03:00
|
|
|
}
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
static void yaffs2_checkpt_find_block(yaffs_dev_t *dev)
|
2007-10-10 21:05:48 +03:00
|
|
|
{
|
|
|
|
int i;
|
2012-10-30 16:58:17 +02:00
|
|
|
yaffs_ext_tags tags;
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:13 +02:00
|
|
|
T(YAFFS_TRACE_CHECKPOINT, (TSTR("find next checkpt block: start: blocks %d next %d" TENDSTR),
|
2012-10-30 16:58:17 +02:00
|
|
|
dev->blocks_in_checkpt, dev->checkpt_next_block));
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (dev->blocks_in_checkpt < dev->checkpt_max_blocks)
|
|
|
|
for (i = dev->checkpt_next_block; i <= dev->internal_end_block; i++) {
|
|
|
|
int chunk = i * dev->param.chunks_per_block;
|
|
|
|
int realignedChunk = chunk - dev->chunk_offset;
|
2007-10-10 21:05:48 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
dev->param.read_chunk_tags_fn(dev, realignedChunk,
|
2012-10-30 16:58:13 +02:00
|
|
|
NULL, &tags);
|
|
|
|
T(YAFFS_TRACE_CHECKPOINT, (TSTR("find next checkpt block: search: block %d oid %d seq %d eccr %d" TENDSTR),
|
2012-10-30 16:58:17 +02:00
|
|
|
i, tags.obj_id, tags.seq_number, tags.ecc_result));
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (tags.seq_number == YAFFS_SEQUENCE_CHECKPOINT_DATA) {
|
2007-10-10 21:05:48 +03:00
|
|
|
/* Right kind of block */
|
2012-10-30 16:58:17 +02:00
|
|
|
dev->checkpt_next_block = tags.obj_id;
|
|
|
|
dev->checkpt_cur_block = i;
|
|
|
|
dev->checkpt_block_list[dev->blocks_in_checkpt] = i;
|
|
|
|
dev->blocks_in_checkpt++;
|
2012-10-30 16:58:13 +02:00
|
|
|
T(YAFFS_TRACE_CHECKPOINT, (TSTR("found checkpt block %d"TENDSTR), i));
|
2007-10-10 21:05:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-30 16:58:13 +02:00
|
|
|
T(YAFFS_TRACE_CHECKPOINT, (TSTR("found no more checkpt blocks"TENDSTR)));
|
2007-10-10 21:05:48 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
dev->checkpt_next_block = -1;
|
|
|
|
dev->checkpt_cur_block = -1;
|
2007-10-10 21:05:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
int yaffs2_checkpt_open(yaffs_dev_t *dev, int forWriting)
|
2007-10-10 21:05:48 +03:00
|
|
|
{
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
|
|
|
|
dev->checkpt_open_write = forWriting;
|
|
|
|
|
2007-10-10 21:05:48 +03:00
|
|
|
/* Got the functions we need? */
|
2012-10-30 16:58:17 +02:00
|
|
|
if (!dev->param.write_chunk_tags_fn ||
|
|
|
|
!dev->param.read_chunk_tags_fn ||
|
|
|
|
!dev->param.erase_fn ||
|
|
|
|
!dev->param.bad_block_fn)
|
2007-10-10 21:05:48 +03:00
|
|
|
return 0;
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (forWriting && !yaffs2_checkpt_space_ok(dev))
|
2007-10-10 21:05:48 +03:00
|
|
|
return 0;
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (!dev->checkpt_buffer)
|
|
|
|
dev->checkpt_buffer = YMALLOC_DMA(dev->param.total_bytes_per_chunk);
|
|
|
|
if (!dev->checkpt_buffer)
|
2007-10-10 21:05:48 +03:00
|
|
|
return 0;
|
|
|
|
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
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;
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2007-10-10 21:05:48 +03:00
|
|
|
/* Erase all the blocks in the checkpoint area */
|
2012-10-30 16:58:13 +02:00
|
|
|
if (forWriting) {
|
2012-10-30 16:58:17 +02:00
|
|
|
memset(dev->checkpt_buffer, 0, dev->data_bytes_per_chunk);
|
|
|
|
dev->checkpt_byte_offs = 0;
|
|
|
|
return yaffs_checkpt_erase(dev);
|
2007-10-10 21:05:48 +03:00
|
|
|
} else {
|
|
|
|
int i;
|
|
|
|
/* Set to a value that will kick off a read */
|
2012-10-30 16:58:17 +02:00
|
|
|
dev->checkpt_byte_offs = dev->data_bytes_per_chunk;
|
2007-10-10 21:05:48 +03:00
|
|
|
/* A checkpoint block list of 1 checkpoint block per 16 block is (hopefully)
|
|
|
|
* going to be way more than we need */
|
2012-10-30 16:58:17 +02:00
|
|
|
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;
|
2007-10-10 21:05:48 +03:00
|
|
|
}
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2007-10-10 21:05:48 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
int yaffs2_get_checkpt_sum(yaffs_dev_t *dev, __u32 *sum)
|
2007-10-10 21:05:48 +03:00
|
|
|
{
|
|
|
|
__u32 compositeSum;
|
2012-10-30 16:58:17 +02:00
|
|
|
compositeSum = (dev->checkpt_sum << 8) | (dev->checkpt_xor & 0xFF);
|
2007-10-10 21:05:48 +03:00
|
|
|
*sum = compositeSum;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
static int yaffs2_checkpt_flush_buffer(yaffs_dev_t *dev)
|
2007-10-10 21:05:48 +03:00
|
|
|
{
|
|
|
|
int chunk;
|
|
|
|
int realignedChunk;
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
yaffs_ext_tags tags;
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (dev->checkpt_cur_block < 0) {
|
|
|
|
yaffs2_checkpt_find_erased_block(dev);
|
|
|
|
dev->checkpt_cur_chunk = 0;
|
2007-10-10 21:05:48 +03:00
|
|
|
}
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (dev->checkpt_cur_block < 0)
|
2007-10-10 21:05:48 +03:00
|
|
|
return 0;
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
tags.is_deleted = 0;
|
|
|
|
tags.obj_id = dev->checkpt_next_block; /* Hint to next place to look */
|
|
|
|
tags.chunk_id = dev->checkpt_page_seq + 1;
|
|
|
|
tags.seq_number = YAFFS_SEQUENCE_CHECKPOINT_DATA;
|
|
|
|
tags.n_bytes = dev->data_bytes_per_chunk;
|
|
|
|
if (dev->checkpt_cur_chunk == 0) {
|
2007-10-10 21:05:48 +03:00
|
|
|
/* First chunk we write for the block? Set block state to
|
|
|
|
checkpoint */
|
2012-10-30 16:58:17 +02:00
|
|
|
yaffs_block_info_t *bi = yaffs_get_block_info(dev, dev->checkpt_cur_block);
|
|
|
|
bi->block_state = YAFFS_BLOCK_STATE_CHECKPOINT;
|
|
|
|
dev->blocks_in_checkpt++;
|
2007-10-10 21:05:48 +03:00
|
|
|
}
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
chunk = dev->checkpt_cur_block * dev->param.chunks_per_block + dev->checkpt_cur_chunk;
|
2007-10-10 21:05:48 +03:00
|
|
|
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:13 +02:00
|
|
|
T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint wite buffer nand %d(%d:%d) objid %d chId %d" TENDSTR),
|
2012-10-30 16:58:17 +02:00
|
|
|
chunk, dev->checkpt_cur_block, dev->checkpt_cur_chunk, tags.obj_id, tags.chunk_id));
|
|
|
|
|
|
|
|
realignedChunk = chunk - dev->chunk_offset;
|
|
|
|
|
|
|
|
dev->n_page_writes++;
|
|
|
|
|
|
|
|
dev->param.write_chunk_tags_fn(dev, realignedChunk,
|
|
|
|
dev->checkpt_buffer, &tags);
|
|
|
|
dev->checkpt_byte_offs = 0;
|
|
|
|
dev->checkpt_page_seq++;
|
|
|
|
dev->checkpt_cur_chunk++;
|
|
|
|
if (dev->checkpt_cur_chunk >= dev->param.chunks_per_block) {
|
|
|
|
dev->checkpt_cur_chunk = 0;
|
|
|
|
dev->checkpt_cur_block = -1;
|
2007-10-10 21:05:48 +03:00
|
|
|
}
|
2012-10-30 16:58:17 +02:00
|
|
|
memset(dev->checkpt_buffer, 0, dev->data_bytes_per_chunk);
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2007-10-10 21:05:48 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
int yaffs2_checkpt_wr(yaffs_dev_t *dev, const void *data, int n_bytes)
|
2007-10-10 21:05:48 +03:00
|
|
|
{
|
2012-10-30 16:58:13 +02:00
|
|
|
int i = 0;
|
2007-10-10 21:05:48 +03:00
|
|
|
int ok = 1;
|
|
|
|
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2007-10-10 21:05:48 +03:00
|
|
|
__u8 * dataBytes = (__u8 *)data;
|
2008-05-28 10:31:26 +03:00
|
|
|
|
|
|
|
|
2007-10-10 21:05:48 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (!dev->checkpt_buffer)
|
2007-10-10 21:05:48 +03:00
|
|
|
return 0;
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (!dev->checkpt_open_write)
|
2007-10-10 21:05:48 +03:00
|
|
|
return -1;
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
while (i < n_bytes && ok) {
|
|
|
|
dev->checkpt_buffer[dev->checkpt_byte_offs] = *dataBytes;
|
|
|
|
dev->checkpt_sum += *dataBytes;
|
|
|
|
dev->checkpt_xor ^= *dataBytes;
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
dev->checkpt_byte_offs++;
|
2007-10-10 21:05:48 +03:00
|
|
|
i++;
|
|
|
|
dataBytes++;
|
2012-10-30 16:58:17 +02:00
|
|
|
dev->checkpt_byte_count++;
|
2008-05-28 10:31:26 +03:00
|
|
|
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (dev->checkpt_byte_offs < 0 ||
|
|
|
|
dev->checkpt_byte_offs >= dev->data_bytes_per_chunk)
|
|
|
|
ok = yaffs2_checkpt_flush_buffer(dev);
|
2007-10-10 21:05:48 +03:00
|
|
|
}
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:13 +02:00
|
|
|
return i;
|
2007-10-10 21:05:48 +03:00
|
|
|
}
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
int yaffs2_checkpt_rd(yaffs_dev_t *dev, void *data, int n_bytes)
|
2007-10-10 21:05:48 +03:00
|
|
|
{
|
2012-10-30 16:58:13 +02:00
|
|
|
int i = 0;
|
2007-10-10 21:05:48 +03:00
|
|
|
int ok = 1;
|
2012-10-30 16:58:17 +02:00
|
|
|
yaffs_ext_tags tags;
|
2007-10-10 21:05:48 +03:00
|
|
|
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2007-10-10 21:05:48 +03:00
|
|
|
int chunk;
|
|
|
|
int realignedChunk;
|
|
|
|
|
|
|
|
__u8 *dataBytes = (__u8 *)data;
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (!dev->checkpt_buffer)
|
2007-10-10 21:05:48 +03:00
|
|
|
return 0;
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (dev->checkpt_open_write)
|
2007-10-10 21:05:48 +03:00
|
|
|
return -1;
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
while (i < n_bytes && ok) {
|
2008-05-28 10:31:26 +03:00
|
|
|
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (dev->checkpt_byte_offs < 0 ||
|
|
|
|
dev->checkpt_byte_offs >= dev->data_bytes_per_chunk) {
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (dev->checkpt_cur_block < 0) {
|
|
|
|
yaffs2_checkpt_find_block(dev);
|
|
|
|
dev->checkpt_cur_chunk = 0;
|
2007-10-10 21:05:48 +03:00
|
|
|
}
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (dev->checkpt_cur_block < 0)
|
2007-10-10 21:05:48 +03:00
|
|
|
ok = 0;
|
|
|
|
else {
|
2012-10-30 16:58:17 +02:00
|
|
|
chunk = dev->checkpt_cur_block *
|
|
|
|
dev->param.chunks_per_block +
|
|
|
|
dev->checkpt_cur_chunk;
|
2007-10-10 21:05:48 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
realignedChunk = chunk - dev->chunk_offset;
|
|
|
|
|
|
|
|
dev->n_page_reads++;
|
2007-10-10 21:05:48 +03:00
|
|
|
|
2012-10-30 16:58:13 +02:00
|
|
|
/* read in the next chunk */
|
|
|
|
/* printf("read checkpoint page %d\n",dev->checkpointPage); */
|
2012-10-30 16:58:17 +02:00
|
|
|
dev->param.read_chunk_tags_fn(dev,
|
2012-10-30 16:58:13 +02:00
|
|
|
realignedChunk,
|
2012-10-30 16:58:17 +02:00
|
|
|
dev->checkpt_buffer,
|
2012-10-30 16:58:13 +02:00
|
|
|
&tags);
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (tags.chunk_id != (dev->checkpt_page_seq + 1) ||
|
|
|
|
tags.ecc_result > YAFFS_ECC_RESULT_FIXED ||
|
|
|
|
tags.seq_number != YAFFS_SEQUENCE_CHECKPOINT_DATA)
|
2012-10-30 16:58:13 +02:00
|
|
|
ok = 0;
|
2007-10-10 21:05:48 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
dev->checkpt_byte_offs = 0;
|
|
|
|
dev->checkpt_page_seq++;
|
|
|
|
dev->checkpt_cur_chunk++;
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (dev->checkpt_cur_chunk >= dev->param.chunks_per_block)
|
|
|
|
dev->checkpt_cur_block = -1;
|
2007-10-10 21:05:48 +03:00
|
|
|
}
|
|
|
|
}
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:13 +02:00
|
|
|
if (ok) {
|
2012-10-30 16:58:17 +02:00
|
|
|
*dataBytes = dev->checkpt_buffer[dev->checkpt_byte_offs];
|
|
|
|
dev->checkpt_sum += *dataBytes;
|
|
|
|
dev->checkpt_xor ^= *dataBytes;
|
|
|
|
dev->checkpt_byte_offs++;
|
2007-10-10 21:05:48 +03:00
|
|
|
i++;
|
|
|
|
dataBytes++;
|
2012-10-30 16:58:17 +02:00
|
|
|
dev->checkpt_byte_count++;
|
2007-10-10 21:05:48 +03:00
|
|
|
}
|
|
|
|
}
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2007-10-10 21:05:48 +03:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
int yaffs_checkpt_close(yaffs_dev_t *dev)
|
2007-10-10 21:05:48 +03:00
|
|
|
{
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (dev->checkpt_open_write) {
|
|
|
|
if (dev->checkpt_byte_offs != 0)
|
|
|
|
yaffs2_checkpt_flush_buffer(dev);
|
|
|
|
} else if(dev->checkpt_block_list){
|
2007-10-10 21:05:48 +03:00
|
|
|
int i;
|
2012-10-30 16:58:17 +02:00
|
|
|
for (i = 0; i < dev->blocks_in_checkpt && dev->checkpt_block_list[i] >= 0; i++) {
|
|
|
|
int blk = dev->checkpt_block_list[i];
|
|
|
|
yaffs_block_info_t *bi = NULL;
|
|
|
|
if( dev->internal_start_block <= blk && blk <= dev->internal_end_block)
|
|
|
|
bi = yaffs_get_block_info(dev, blk);
|
|
|
|
if (bi && bi->block_state == YAFFS_BLOCK_STATE_EMPTY)
|
|
|
|
bi->block_state = YAFFS_BLOCK_STATE_CHECKPOINT;
|
2007-10-10 21:05:48 +03:00
|
|
|
else {
|
2012-10-30 16:58:13 +02:00
|
|
|
/* Todo this looks odd... */
|
2007-10-10 21:05:48 +03:00
|
|
|
}
|
|
|
|
}
|
2012-10-30 16:58:17 +02:00
|
|
|
YFREE(dev->checkpt_block_list);
|
|
|
|
dev->checkpt_block_list = NULL;
|
2007-10-10 21:05:48 +03:00
|
|
|
}
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
dev->n_free_chunks -= dev->blocks_in_checkpt * dev->param.chunks_per_block;
|
|
|
|
dev->n_erased_blocks -= dev->blocks_in_checkpt;
|
2007-10-10 21:05:48 +03:00
|
|
|
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:13 +02:00
|
|
|
T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint byte count %d" TENDSTR),
|
2012-10-30 16:58:17 +02:00
|
|
|
dev->checkpt_byte_count));
|
2008-05-28 10:31:26 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
if (dev->checkpt_buffer) {
|
2008-05-28 10:31:26 +03:00
|
|
|
/* free the buffer */
|
2012-10-30 16:58:17 +02:00
|
|
|
YFREE(dev->checkpt_buffer);
|
|
|
|
dev->checkpt_buffer = NULL;
|
2007-10-10 21:05:48 +03:00
|
|
|
return 1;
|
2012-10-30 16:58:13 +02:00
|
|
|
} else
|
2007-10-10 21:05:48 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
int yaffs2_checkpt_invalidate_stream(yaffs_dev_t *dev)
|
2007-10-10 21:05:48 +03:00
|
|
|
{
|
2012-10-30 16:58:17 +02:00
|
|
|
/* Erase the checkpoint data */
|
2007-10-10 21:05:48 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint invalidate of %d blocks"TENDSTR),
|
|
|
|
dev->blocks_in_checkpt));
|
2007-10-10 21:05:48 +03:00
|
|
|
|
2012-10-30 16:58:17 +02:00
|
|
|
return yaffs_checkpt_erase(dev);
|
2007-10-10 21:05:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|