Changeset 7b16549 in mainline
- Timestamp:
- 2012-04-16T09:39:43Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3d93289a
- Parents:
- 4358513
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_bitmap.c
r4358513 r7b16549 41 41 #include "libext4.h" 42 42 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 */ 43 50 void ext4_bitmap_free_bit(uint8_t *bitmap, uint32_t index) 44 51 { … … 51 58 } 52 59 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 */ 53 68 void ext4_bitmap_free_bits(uint8_t *bitmap, uint32_t index, uint32_t count) 54 69 { … … 58 73 uint32_t byte_index; 59 74 75 // Align index to multiple of 8 60 76 while (((idx % 8) != 0) && (remaining > 0)) { 61 77 … … 71 87 } 72 88 89 // For < 8 bits this check necessary 73 90 if (remaining == 0) { 74 91 return; … … 80 97 target = bitmap + byte_index; 81 98 99 // Zero the whole bytes 82 100 while (remaining >= 8) { 83 101 *target = 0; … … 90 108 assert(remaining < 8); 91 109 110 // Zero remaining bytes 92 111 while (remaining != 0) { 93 112 … … 104 123 } 105 124 125 /** Set bit in bitmap to 1 (used). 126 * 127 * @param bitmap pointer to bitmap 128 * @param index index of bit to set 129 */ 106 130 void ext4_bitmap_set_bit(uint8_t *bitmap, uint32_t index) 107 131 { … … 114 138 } 115 139 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 */ 116 146 bool ext4_bitmap_is_free_bit(uint8_t *bitmap, uint32_t index) 117 147 { … … 129 159 } 130 160 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 */ 131 172 int ext4_bitmap_find_free_byte_and_set_bit(uint8_t *bitmap, uint32_t start, uint32_t *index, uint32_t max) 132 173 { 133 174 uint32_t idx; 175 176 // Align idx 134 177 if (start % 8) { 135 178 idx = start + (8 - (start % 8)); … … 140 183 uint8_t *pos = bitmap + (idx / 8); 141 184 185 // Try to find free byte 142 186 while (idx < max) { 143 187 … … 153 197 } 154 198 199 // Free byte not found 155 200 return ENOSPC; 156 201 } 157 202 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 */ 158 213 int ext4_bitmap_find_free_bit_and_set(uint8_t *bitmap, uint32_t start_idx, 159 214 uint32_t *index, uint32_t max) … … 163 218 bool byte_part = false; 164 219 165 // Check the rest of byte220 // Check the rest of first byte 166 221 while ((idx % 8) != 0) { 167 222 byte_part = true; … … 180 235 } 181 236 237 // Check the whole bytes (255 = 11111111 binary) 182 238 while (idx < max) { 183 239 … … 191 247 } 192 248 193 249 // If idx < max, some free bit found 194 250 if (idx < max) { 251 252 // Check which bit from byte is free 195 253 for (uint8_t i = 0; i < 8; ++i) { 196 254 if ((*pos & (1 << i)) == 0) { … … 204 262 } 205 263 264 // Free bit not found 206 265 return ENOSPC; 207 266 }
Note:
See TracChangeset
for help on using the changeset viewer.