Changeset a35b458 in mainline for uspace/lib/ext4/src/bitmap.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/src/bitmap.c
r3061bc1 ra35b458 52 52 uint32_t byte_index = index / 8; 53 53 uint32_t bit_index = index % 8; 54 54 55 55 uint8_t *target = bitmap + byte_index; 56 56 57 57 *target &= ~ (1 << bit_index); 58 58 } … … 73 73 uint32_t remaining = count; 74 74 uint32_t byte_index; 75 75 76 76 /* Align index to multiple of 8 */ 77 77 while (((idx % 8) != 0) && (remaining > 0)) { 78 78 byte_index = idx / 8; 79 79 uint32_t bit_index = idx % 8; 80 80 81 81 target = bitmap + byte_index; 82 82 *target &= ~ (1 << bit_index); 83 83 84 84 idx++; 85 85 remaining--; 86 86 } 87 87 88 88 /* For < 8 bits this check necessary */ 89 89 if (remaining == 0) 90 90 return; 91 91 92 92 assert((idx % 8) == 0); 93 93 94 94 byte_index = idx / 8; 95 95 target = bitmap + byte_index; 96 96 97 97 /* Zero the whole bytes */ 98 98 while (remaining >= 8) { 99 99 *target = 0; 100 100 101 101 idx += 8; 102 102 remaining -= 8; 103 103 target++; 104 104 } 105 105 106 106 assert(remaining < 8); 107 107 108 108 /* Zero remaining bytes */ 109 109 while (remaining != 0) { 110 110 byte_index = idx / 8; 111 111 uint32_t bit_index = idx % 8; 112 112 113 113 target = bitmap + byte_index; 114 114 *target &= ~ (1 << bit_index); 115 115 116 116 idx++; 117 117 remaining--; … … 129 129 uint32_t byte_index = index / 8; 130 130 uint32_t bit_index = index % 8; 131 131 132 132 uint8_t *target = bitmap + byte_index; 133 133 134 134 *target |= 1 << bit_index; 135 135 } … … 147 147 uint32_t byte_index = index / 8; 148 148 uint32_t bit_index = index % 8; 149 149 150 150 uint8_t *target = bitmap + byte_index; 151 151 152 152 if (*target & (1 << bit_index)) 153 153 return false; … … 173 173 { 174 174 uint32_t idx; 175 175 176 176 /* Align idx */ 177 177 if (start % 8) … … 179 179 else 180 180 idx = start; 181 181 182 182 uint8_t *pos = bitmap + (idx / 8); 183 183 184 184 /* Try to find free byte */ 185 185 while (idx < max) { 186 186 if (*pos == 0) { 187 187 *pos |= 1; 188 188 189 189 *index = idx; 190 190 return EOK; 191 191 } 192 192 193 193 idx += 8; 194 194 ++pos; 195 195 } 196 196 197 197 /* Free byte not found */ 198 198 return ENOSPC; … … 217 217 uint32_t idx = start_idx; 218 218 bool byte_part = false; 219 219 220 220 /* Check the rest of first byte */ 221 221 while ((idx % 8) != 0) { 222 222 byte_part = true; 223 223 224 224 if ((*pos & (1 << (idx % 8))) == 0) { 225 225 *pos |= (1 << (idx % 8)); … … 227 227 return EOK; 228 228 } 229 229 230 230 ++idx; 231 231 } 232 232 233 233 if (byte_part) 234 234 ++pos; 235 235 236 236 /* Check the whole bytes (255 = 11111111 binary) */ 237 237 while (idx < max) { … … 240 240 break; 241 241 } 242 242 243 243 idx += 8; 244 244 ++pos; 245 245 } 246 246 247 247 /* If idx < max, some free bit found */ 248 248 if (idx < max) { … … 252 252 /* Free bit found */ 253 253 *pos |= (1 << i); 254 254 255 255 *index = idx; 256 256 return EOK; 257 257 } 258 258 259 259 idx++; 260 260 } 261 261 } 262 262 263 263 /* Free bit not found */ 264 264 return ENOSPC;
Note:
See TracChangeset
for help on using the changeset viewer.