The following is the checkpt_close function,
( for yaffs2)
I noticed that the values of dev->n_free_chunks
and dev->n_erased_blocks
are being modified each time this function is called.
Should they only be modified if the
checkpt was open for writing , not reading?
Will this not cause an incorrect count
value, as it occurs on a close for read operation?
Also: If the buffers are not freed,
then the checkpt_open () function would not try to re-allocate memory,
as the buffers would exist. Since the checkpoint size would not change
for the given device, this should be OK.
Does this sound valid?
int yaffs_checkpt_close(struct
yaffs_dev
*dev)
{
int
i;
if
(dev->checkpt_open_write)
{
if
(dev->checkpt_byte_offs
!=
sizeof(sizeof(struct
yaffs_checkpt_chunk_hdr)))
yaffs2_checkpt_flush_buffer(dev);
}
else
if
(dev->checkpt_block_list)
{
for
(i
=
0;
i
<
dev->blocks_in_checkpt
&&
dev->checkpt_block_list[i]
>=
0;
i++)
{
int
blk
=
dev->checkpt_block_list[i];
struct
yaffs_block_info
*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;
}
yaffsfs_free(dev->checkpt_block_list);
/* TODO: we do not want
to free the buffer, but rather re-use it */
dev->checkpt_block_list
=
NULL;
}
/* TODO:
following should only be applicable if it was open for writing */
dev->n_free_chunks
-=
dev->blocks_in_checkpt
*
dev->param.chunks_per_block;
dev->n_erased_blocks
-=
dev->blocks_in_checkpt;
yaffs_trace(YAFFS_TRACE_CHECKPOINT,
"checkpoint byte
count %d",
dev->checkpt_byte_count);
if
(dev->checkpt_buffer)
{
/*
free the buffer */
yaffsfs_free(dev->checkpt_buffer);
/* TODO: we do not want
to free the buffer, but rather re-use it */
dev->checkpt_buffer
=
NULL;
return
1;
}
else
{
return
0;
}
}
Thanks
Chris