Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 7b16549 in mainline


Ignore:
Timestamp:
2012-04-16T09:39:43Z (10 years ago)
Author:
Frantisek Princ <frantisek.princ@…>
Branches:
lfn, master
Children:
3d93289a
Parents:
4358513
Message:

comments for bitmap functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext4/libext4_bitmap.c

    r4358513 r7b16549  
    4141#include "libext4.h"
    4242
     43/** Set bit in bitmap to 0 (free).
     44 *
     45 * Index must be checked by caller, if it's not out of bounds.
     46 *
     47 * @param bitmap        pointer to bitmap
     48 * @param index         index of bit in bitmap
     49 */
    4350void ext4_bitmap_free_bit(uint8_t *bitmap, uint32_t index)
    4451{
     
    5158}
    5259
     60/** Free continous set of bits (set to 0).
     61 *
     62 * Index and count must be checked by caller, if they aren't out of bounds.
     63 *
     64 * @param bitmap        pointer to bitmap
     65 * @param index         index of first bit to zeroed
     66 * @param count         number of bits to be zeroed
     67 */
    5368void ext4_bitmap_free_bits(uint8_t *bitmap, uint32_t index, uint32_t count)
    5469{
     
    5873        uint32_t byte_index;
    5974
     75        // Align index to multiple of 8
    6076        while (((idx % 8) != 0) && (remaining > 0)) {
    6177
     
    7187        }
    7288
     89        // For < 8 bits this check necessary
    7390        if (remaining == 0) {
    7491                return;
     
    8097        target = bitmap + byte_index;
    8198
     99        // Zero the whole bytes
    82100        while (remaining >= 8) {
    83101                *target = 0;
     
    90108        assert(remaining < 8);
    91109
     110        // Zero remaining bytes
    92111        while (remaining != 0) {
    93112
     
    104123}
    105124
     125/** Set bit in bitmap to 1 (used).
     126 *
     127 * @param bitmap        pointer to bitmap
     128 * @param index         index of bit to set
     129 */
    106130void ext4_bitmap_set_bit(uint8_t *bitmap, uint32_t index)
    107131{
     
    114138}
    115139
     140/** Check if requested bit is free.
     141 *
     142 * @param bitmap        pointer to bitmap
     143 * @param index         index of bit to be checked
     144 * @return                      true if bit is free, else false
     145 */
    116146bool ext4_bitmap_is_free_bit(uint8_t *bitmap, uint32_t index)
    117147{
     
    129159}
    130160
     161/**     Try to find free byte and set the first bit as used.
     162 *
     163 * Walk through bitmap and try to find free byte ( == 0).
     164 * If byte found, set the first bit as used.
     165 *
     166 * @param bitmap        pointer to bitmap
     167 * @param start         index of bit, where the algorithm will begin
     168 * @param index         output value - index of bit (if found free byte)
     169 * @param max           maximum index of bit in bitmap
     170 * @return                      error code
     171 */
    131172int ext4_bitmap_find_free_byte_and_set_bit(uint8_t *bitmap, uint32_t start, uint32_t *index, uint32_t max)
    132173{
    133174        uint32_t idx;
     175
     176        // Align idx
    134177        if (start % 8) {
    135178                idx = start + (8 - (start % 8));
     
    140183        uint8_t *pos = bitmap + (idx / 8);
    141184
     185        // Try to find free byte
    142186        while (idx < max) {
    143187
     
    153197        }
    154198
     199        // Free byte not found
    155200        return ENOSPC;
    156201}
    157202
     203/** Try to find free bit and set it as used (1).
     204 *
     205 * Walk through bitmap and try to find any free bit.
     206 *
     207 * @param bitmap        pointer to bitmap
     208 * @param start_idx     index of bit, where algorithm will begin
     209 * @param index         output value - index of set bit (if found)
     210 * @param max           maximum index of bit in bitmap
     211 * @return                      error code
     212 */
    158213int ext4_bitmap_find_free_bit_and_set(uint8_t *bitmap, uint32_t start_idx,
    159214                uint32_t *index, uint32_t max)
     
    163218        bool byte_part = false;
    164219
    165         // Check the rest of byte
     220        // Check the rest of first byte
    166221        while ((idx % 8) != 0) {
    167222                byte_part = true;
     
    180235        }
    181236
     237        // Check the whole bytes (255 = 11111111 binary)
    182238        while (idx < max) {
    183239
     
    191247        }
    192248
    193 
     249        // If idx < max, some free bit found
    194250        if (idx < max) {
     251
     252                // Check which bit from byte is free
    195253                for (uint8_t i = 0; i < 8; ++i) {
    196254                        if ((*pos & (1 << i)) == 0) {
     
    204262        }
    205263
     264        // Free bit not found
    206265        return ENOSPC;
    207266}
Note: See TracChangeset for help on using the changeset viewer.