2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2010 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
7 * Created by Charles Manning <charles@aleph1.co.uk>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include "yaffs_bitmap.h"
15 #include "yaffs_trace.h"
17 * Chunk bitmap manipulations
20 static Y_INLINE __u8 *yaffs_block_bits(yaffs_dev_t *dev, int blk)
22 if (blk < dev->internal_start_block || blk > dev->internal_end_block) {
24 (TSTR("**>> yaffs: BlockBits block %d is not valid" TENDSTR),
28 return dev->chunk_bits +
29 (dev->chunk_bit_stride * (blk - dev->internal_start_block));
32 void yaffs_verify_chunk_bit_id(yaffs_dev_t *dev, int blk, int chunk)
34 if (blk < dev->internal_start_block || blk > dev->internal_end_block ||
35 chunk < 0 || chunk >= dev->param.chunks_per_block) {
37 (TSTR("**>> yaffs: Chunk Id (%d:%d) invalid"TENDSTR),
43 void yaffs_clear_chunk_bits(yaffs_dev_t *dev, int blk)
45 __u8 *blk_bits = yaffs_block_bits(dev, blk);
47 memset(blk_bits, 0, dev->chunk_bit_stride);
50 void yaffs_clear_chunk_bit(yaffs_dev_t *dev, int blk, int chunk)
52 __u8 *blk_bits = yaffs_block_bits(dev, blk);
54 yaffs_verify_chunk_bit_id(dev, blk, chunk);
56 blk_bits[chunk / 8] &= ~(1 << (chunk & 7));
59 void yaffs_set_chunk_bit(yaffs_dev_t *dev, int blk, int chunk)
61 __u8 *blk_bits = yaffs_block_bits(dev, blk);
63 yaffs_verify_chunk_bit_id(dev, blk, chunk);
65 blk_bits[chunk / 8] |= (1 << (chunk & 7));
68 int yaffs_check_chunk_bit(yaffs_dev_t *dev, int blk, int chunk)
70 __u8 *blk_bits = yaffs_block_bits(dev, blk);
71 yaffs_verify_chunk_bit_id(dev, blk, chunk);
73 return (blk_bits[chunk / 8] & (1 << (chunk & 7))) ? 1 : 0;
76 int yaffs_still_some_chunks(yaffs_dev_t *dev, int blk)
78 __u8 *blk_bits = yaffs_block_bits(dev, blk);
80 for (i = 0; i < dev->chunk_bit_stride; i++) {
88 int yaffs_count_chunk_bits(yaffs_dev_t *dev, int blk)
90 __u8 *blk_bits = yaffs_block_bits(dev, blk);
93 for (i = 0; i < dev->chunk_bit_stride; i++) {