Lines Matching refs:dev
17 static int yaffs2_checkpt_space_ok(struct yaffs_dev *dev) in yaffs2_checkpt_space_ok() argument
19 int blocks_avail = dev->n_erased_blocks - dev->param.n_reserved_blocks; in yaffs2_checkpt_space_ok()
27 static int yaffs_checkpt_erase(struct yaffs_dev *dev) in yaffs_checkpt_erase() argument
31 if (!dev->param.erase_fn) in yaffs_checkpt_erase()
35 dev->internal_start_block, dev->internal_end_block); in yaffs_checkpt_erase()
37 for (i = dev->internal_start_block; i <= dev->internal_end_block; i++) { in yaffs_checkpt_erase()
38 struct yaffs_block_info *bi = yaffs_get_block_info(dev, i); in yaffs_checkpt_erase()
43 dev->n_erasures++; in yaffs_checkpt_erase()
45 if (dev->param. in yaffs_checkpt_erase()
46 erase_fn(dev, in yaffs_checkpt_erase()
47 i - dev->block_offset /* realign */)) { in yaffs_checkpt_erase()
49 dev->n_erased_blocks++; in yaffs_checkpt_erase()
50 dev->n_free_chunks += in yaffs_checkpt_erase()
51 dev->param.chunks_per_block; in yaffs_checkpt_erase()
53 dev->param.bad_block_fn(dev, i); in yaffs_checkpt_erase()
59 dev->blocks_in_checkpt = 0; in yaffs_checkpt_erase()
64 static void yaffs2_checkpt_find_erased_block(struct yaffs_dev *dev) in yaffs2_checkpt_find_erased_block() argument
67 int blocks_avail = dev->n_erased_blocks - dev->param.n_reserved_blocks; in yaffs2_checkpt_find_erased_block()
71 dev->n_erased_blocks, dev->param.n_reserved_blocks, in yaffs2_checkpt_find_erased_block()
72 blocks_avail, dev->checkpt_next_block); in yaffs2_checkpt_find_erased_block()
74 if (dev->checkpt_next_block >= 0 && in yaffs2_checkpt_find_erased_block()
75 dev->checkpt_next_block <= dev->internal_end_block && in yaffs2_checkpt_find_erased_block()
78 for (i = dev->checkpt_next_block; i <= dev->internal_end_block; in yaffs2_checkpt_find_erased_block()
81 yaffs_get_block_info(dev, i); in yaffs2_checkpt_find_erased_block()
83 dev->checkpt_next_block = i + 1; in yaffs2_checkpt_find_erased_block()
84 dev->checkpt_cur_block = i; in yaffs2_checkpt_find_erased_block()
93 dev->checkpt_next_block = -1; in yaffs2_checkpt_find_erased_block()
94 dev->checkpt_cur_block = -1; in yaffs2_checkpt_find_erased_block()
97 static void yaffs2_checkpt_find_block(struct yaffs_dev *dev) in yaffs2_checkpt_find_block() argument
104 dev->blocks_in_checkpt, dev->checkpt_next_block); in yaffs2_checkpt_find_block()
106 if (dev->blocks_in_checkpt < dev->checkpt_max_blocks) in yaffs2_checkpt_find_block()
107 for (i = dev->checkpt_next_block; i <= dev->internal_end_block; in yaffs2_checkpt_find_block()
109 int chunk = i * dev->param.chunks_per_block; in yaffs2_checkpt_find_block()
110 int realigned_chunk = chunk - dev->chunk_offset; in yaffs2_checkpt_find_block()
112 dev->param.read_chunk_tags_fn(dev, realigned_chunk, in yaffs2_checkpt_find_block()
121 dev->checkpt_next_block = tags.obj_id; in yaffs2_checkpt_find_block()
122 dev->checkpt_cur_block = i; in yaffs2_checkpt_find_block()
123 dev->checkpt_block_list[dev-> in yaffs2_checkpt_find_block()
125 dev->blocks_in_checkpt++; in yaffs2_checkpt_find_block()
134 dev->checkpt_next_block = -1; in yaffs2_checkpt_find_block()
135 dev->checkpt_cur_block = -1; in yaffs2_checkpt_find_block()
138 int yaffs2_checkpt_open(struct yaffs_dev *dev, int writing) in yaffs2_checkpt_open() argument
142 dev->checkpt_open_write = writing; in yaffs2_checkpt_open()
145 if (!dev->param.write_chunk_tags_fn || in yaffs2_checkpt_open()
146 !dev->param.read_chunk_tags_fn || in yaffs2_checkpt_open()
147 !dev->param.erase_fn || !dev->param.bad_block_fn) in yaffs2_checkpt_open()
150 if (writing && !yaffs2_checkpt_space_ok(dev)) in yaffs2_checkpt_open()
153 if (!dev->checkpt_buffer) in yaffs2_checkpt_open()
154 dev->checkpt_buffer = in yaffs2_checkpt_open()
155 kmalloc(dev->param.total_bytes_per_chunk, GFP_NOFS); in yaffs2_checkpt_open()
156 if (!dev->checkpt_buffer) in yaffs2_checkpt_open()
159 dev->checkpt_page_seq = 0; in yaffs2_checkpt_open()
160 dev->checkpt_byte_count = 0; in yaffs2_checkpt_open()
161 dev->checkpt_sum = 0; in yaffs2_checkpt_open()
162 dev->checkpt_xor = 0; in yaffs2_checkpt_open()
163 dev->checkpt_cur_block = -1; in yaffs2_checkpt_open()
164 dev->checkpt_cur_chunk = -1; in yaffs2_checkpt_open()
165 dev->checkpt_next_block = dev->internal_start_block; in yaffs2_checkpt_open()
169 memset(dev->checkpt_buffer, 0, dev->data_bytes_per_chunk); in yaffs2_checkpt_open()
170 dev->checkpt_byte_offs = 0; in yaffs2_checkpt_open()
171 return yaffs_checkpt_erase(dev); in yaffs2_checkpt_open()
175 dev->checkpt_byte_offs = dev->data_bytes_per_chunk; in yaffs2_checkpt_open()
178 dev->blocks_in_checkpt = 0; in yaffs2_checkpt_open()
179 dev->checkpt_max_blocks = in yaffs2_checkpt_open()
180 (dev->internal_end_block - dev->internal_start_block) / 16 + 2; in yaffs2_checkpt_open()
181 dev->checkpt_block_list = in yaffs2_checkpt_open()
182 kmalloc(sizeof(int) * dev->checkpt_max_blocks, GFP_NOFS); in yaffs2_checkpt_open()
184 if (!dev->checkpt_block_list) in yaffs2_checkpt_open()
187 for (i = 0; i < dev->checkpt_max_blocks; i++) in yaffs2_checkpt_open()
188 dev->checkpt_block_list[i] = -1; in yaffs2_checkpt_open()
193 int yaffs2_get_checkpt_sum(struct yaffs_dev *dev, u32 * sum) in yaffs2_get_checkpt_sum() argument
197 composite_sum = (dev->checkpt_sum << 8) | (dev->checkpt_xor & 0xff); in yaffs2_get_checkpt_sum()
202 static int yaffs2_checkpt_flush_buffer(struct yaffs_dev *dev) in yaffs2_checkpt_flush_buffer() argument
208 if (dev->checkpt_cur_block < 0) { in yaffs2_checkpt_flush_buffer()
209 yaffs2_checkpt_find_erased_block(dev); in yaffs2_checkpt_flush_buffer()
210 dev->checkpt_cur_chunk = 0; in yaffs2_checkpt_flush_buffer()
213 if (dev->checkpt_cur_block < 0) in yaffs2_checkpt_flush_buffer()
217 tags.obj_id = dev->checkpt_next_block; /* Hint to next place to look */ in yaffs2_checkpt_flush_buffer()
218 tags.chunk_id = dev->checkpt_page_seq + 1; in yaffs2_checkpt_flush_buffer()
220 tags.n_bytes = dev->data_bytes_per_chunk; in yaffs2_checkpt_flush_buffer()
221 if (dev->checkpt_cur_chunk == 0) { in yaffs2_checkpt_flush_buffer()
225 yaffs_get_block_info(dev, dev->checkpt_cur_block); in yaffs2_checkpt_flush_buffer()
227 dev->blocks_in_checkpt++; in yaffs2_checkpt_flush_buffer()
231 dev->checkpt_cur_block * dev->param.chunks_per_block + in yaffs2_checkpt_flush_buffer()
232 dev->checkpt_cur_chunk; in yaffs2_checkpt_flush_buffer()
236 chunk, dev->checkpt_cur_block, dev->checkpt_cur_chunk, in yaffs2_checkpt_flush_buffer()
239 realigned_chunk = chunk - dev->chunk_offset; in yaffs2_checkpt_flush_buffer()
241 dev->n_page_writes++; in yaffs2_checkpt_flush_buffer()
243 dev->param.write_chunk_tags_fn(dev, realigned_chunk, in yaffs2_checkpt_flush_buffer()
244 dev->checkpt_buffer, &tags); in yaffs2_checkpt_flush_buffer()
245 dev->checkpt_byte_offs = 0; in yaffs2_checkpt_flush_buffer()
246 dev->checkpt_page_seq++; in yaffs2_checkpt_flush_buffer()
247 dev->checkpt_cur_chunk++; in yaffs2_checkpt_flush_buffer()
248 if (dev->checkpt_cur_chunk >= dev->param.chunks_per_block) { in yaffs2_checkpt_flush_buffer()
249 dev->checkpt_cur_chunk = 0; in yaffs2_checkpt_flush_buffer()
250 dev->checkpt_cur_block = -1; in yaffs2_checkpt_flush_buffer()
252 memset(dev->checkpt_buffer, 0, dev->data_bytes_per_chunk); in yaffs2_checkpt_flush_buffer()
257 int yaffs2_checkpt_wr(struct yaffs_dev *dev, const void *data, int n_bytes) in yaffs2_checkpt_wr() argument
263 if (!dev->checkpt_buffer) in yaffs2_checkpt_wr()
266 if (!dev->checkpt_open_write) in yaffs2_checkpt_wr()
270 dev->checkpt_buffer[dev->checkpt_byte_offs] = *data_bytes; in yaffs2_checkpt_wr()
271 dev->checkpt_sum += *data_bytes; in yaffs2_checkpt_wr()
272 dev->checkpt_xor ^= *data_bytes; in yaffs2_checkpt_wr()
274 dev->checkpt_byte_offs++; in yaffs2_checkpt_wr()
277 dev->checkpt_byte_count++; in yaffs2_checkpt_wr()
279 if (dev->checkpt_byte_offs < 0 || in yaffs2_checkpt_wr()
280 dev->checkpt_byte_offs >= dev->data_bytes_per_chunk) in yaffs2_checkpt_wr()
281 ok = yaffs2_checkpt_flush_buffer(dev); in yaffs2_checkpt_wr()
287 int yaffs2_checkpt_rd(struct yaffs_dev *dev, void *data, int n_bytes) in yaffs2_checkpt_rd() argument
296 if (!dev->checkpt_buffer) in yaffs2_checkpt_rd()
299 if (dev->checkpt_open_write) in yaffs2_checkpt_rd()
304 if (dev->checkpt_byte_offs < 0 || in yaffs2_checkpt_rd()
305 dev->checkpt_byte_offs >= dev->data_bytes_per_chunk) { in yaffs2_checkpt_rd()
307 if (dev->checkpt_cur_block < 0) { in yaffs2_checkpt_rd()
308 yaffs2_checkpt_find_block(dev); in yaffs2_checkpt_rd()
309 dev->checkpt_cur_chunk = 0; in yaffs2_checkpt_rd()
312 if (dev->checkpt_cur_block < 0) { in yaffs2_checkpt_rd()
317 chunk = dev->checkpt_cur_block * in yaffs2_checkpt_rd()
318 dev->param.chunks_per_block + in yaffs2_checkpt_rd()
319 dev->checkpt_cur_chunk; in yaffs2_checkpt_rd()
321 realigned_chunk = chunk - dev->chunk_offset; in yaffs2_checkpt_rd()
322 dev->n_page_reads++; in yaffs2_checkpt_rd()
325 dev->param.read_chunk_tags_fn(dev, in yaffs2_checkpt_rd()
327 dev->checkpt_buffer, in yaffs2_checkpt_rd()
330 if (tags.chunk_id != (dev->checkpt_page_seq + 1) || in yaffs2_checkpt_rd()
337 dev->checkpt_byte_offs = 0; in yaffs2_checkpt_rd()
338 dev->checkpt_page_seq++; in yaffs2_checkpt_rd()
339 dev->checkpt_cur_chunk++; in yaffs2_checkpt_rd()
341 if (dev->checkpt_cur_chunk >= in yaffs2_checkpt_rd()
342 dev->param.chunks_per_block) in yaffs2_checkpt_rd()
343 dev->checkpt_cur_block = -1; in yaffs2_checkpt_rd()
346 *data_bytes = dev->checkpt_buffer[dev->checkpt_byte_offs]; in yaffs2_checkpt_rd()
347 dev->checkpt_sum += *data_bytes; in yaffs2_checkpt_rd()
348 dev->checkpt_xor ^= *data_bytes; in yaffs2_checkpt_rd()
349 dev->checkpt_byte_offs++; in yaffs2_checkpt_rd()
352 dev->checkpt_byte_count++; in yaffs2_checkpt_rd()
358 int yaffs_checkpt_close(struct yaffs_dev *dev) in yaffs_checkpt_close() argument
362 if (dev->checkpt_open_write) { in yaffs_checkpt_close()
363 if (dev->checkpt_byte_offs != 0) in yaffs_checkpt_close()
364 yaffs2_checkpt_flush_buffer(dev); in yaffs_checkpt_close()
365 } else if (dev->checkpt_block_list) { in yaffs_checkpt_close()
367 i < dev->blocks_in_checkpt && in yaffs_checkpt_close()
368 dev->checkpt_block_list[i] >= 0; i++) { in yaffs_checkpt_close()
369 int blk = dev->checkpt_block_list[i]; in yaffs_checkpt_close()
372 if (dev->internal_start_block <= blk && in yaffs_checkpt_close()
373 blk <= dev->internal_end_block) in yaffs_checkpt_close()
374 bi = yaffs_get_block_info(dev, blk); in yaffs_checkpt_close()
378 kfree(dev->checkpt_block_list); in yaffs_checkpt_close()
379 dev->checkpt_block_list = NULL; in yaffs_checkpt_close()
382 dev->n_free_chunks -= in yaffs_checkpt_close()
383 dev->blocks_in_checkpt * dev->param.chunks_per_block; in yaffs_checkpt_close()
384 dev->n_erased_blocks -= dev->blocks_in_checkpt; in yaffs_checkpt_close()
387 dev->checkpt_byte_count); in yaffs_checkpt_close()
389 if (dev->checkpt_buffer) { in yaffs_checkpt_close()
391 kfree(dev->checkpt_buffer); in yaffs_checkpt_close()
392 dev->checkpt_buffer = NULL; in yaffs_checkpt_close()
399 int yaffs2_checkpt_invalidate_stream(struct yaffs_dev *dev) in yaffs2_checkpt_invalidate_stream() argument
405 dev->blocks_in_checkpt); in yaffs2_checkpt_invalidate_stream()
407 return yaffs_checkpt_erase(dev); in yaffs2_checkpt_invalidate_stream()