2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2018 Aleph One Ltd.
6 * Created by Charles Manning <charles@aleph1.co.uk>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include "yaffs_bitmap.h"
14 #include "yaffs_trace.h"
16 * Chunk bitmap manipulations
19 static inline u8 *yaffs_block_bits(struct yaffs_dev *dev, int blk)
21 if (blk < (int)dev->internal_start_block ||
22 blk > (int)dev->internal_end_block) {
23 yaffs_trace(YAFFS_TRACE_ERROR,
24 "BlockBits block %d is not valid",
28 return dev->chunk_bits +
29 (dev->chunk_bit_stride * (blk - dev->internal_start_block));
32 void yaffs_verify_chunk_bit_id(struct yaffs_dev *dev, int blk, int chunk)
34 if (blk < (int)dev->internal_start_block ||
35 blk > (int)dev->internal_end_block ||
36 chunk < 0 || chunk >= (int)dev->param.chunks_per_block) {
37 yaffs_trace(YAFFS_TRACE_ERROR,
38 "Chunk Id (%d:%d) invalid",
44 void yaffs_clear_chunk_bits(struct yaffs_dev *dev, int blk)
46 u8 *blk_bits = yaffs_block_bits(dev, blk);
48 memset(blk_bits, 0, dev->chunk_bit_stride);
51 void yaffs_clear_chunk_bit(struct yaffs_dev *dev, int blk, int chunk)
53 u8 *blk_bits = yaffs_block_bits(dev, blk);
55 yaffs_verify_chunk_bit_id(dev, blk, chunk);
56 blk_bits[chunk / 8] &= ~(1 << (chunk & 7));
59 void yaffs_set_chunk_bit(struct yaffs_dev *dev, int blk, int chunk)
61 u8 *blk_bits = yaffs_block_bits(dev, blk);
63 yaffs_verify_chunk_bit_id(dev, blk, chunk);
64 blk_bits[chunk / 8] |= (1 << (chunk & 7));
67 int yaffs_check_chunk_bit(struct yaffs_dev *dev, int blk, int chunk)
69 u8 *blk_bits = yaffs_block_bits(dev, blk);
71 yaffs_verify_chunk_bit_id(dev, blk, chunk);
72 return (blk_bits[chunk / 8] & (1 << (chunk & 7))) ? 1 : 0;
75 int yaffs_still_some_chunks(struct yaffs_dev *dev, int blk)
77 u8 *blk_bits = yaffs_block_bits(dev, blk);
80 for (i = 0; i < dev->chunk_bit_stride; i++) {
88 int yaffs_count_chunk_bits(struct yaffs_dev *dev, int blk)
90 u8 *blk_bits = yaffs_block_bits(dev, blk);
94 for (i = 0; i < dev->chunk_bit_stride; i++, blk_bits++)
95 n += hweight8(*blk_bits);