Changeset b12ca16 in mainline for uspace/lib/ext4/libext4_bitmap.c
- Timestamp:
- 2011-11-18T15:30:24Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d5ba17f
- Parents:
- e18de3c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_bitmap.c
re18de3c rb12ca16 76 76 } 77 77 78 int ext4_bitmap_find_free_byte_and_set_bit(uint8_t *bitmap, uint32_t start, uint32_t *index, uint32_t size)78 int ext4_bitmap_find_free_byte_and_set_bit(uint8_t *bitmap, uint32_t start, uint32_t *index, uint32_t max) 79 79 { 80 uint8_t *pos = bitmap + (start / 8) + 1; 80 uint32_t idx; 81 if (start % 8) { 82 idx = start + (8 - (start % 8)); 83 } else { 84 idx = start; 85 } 81 86 82 while (pos < bitmap + size) { 87 uint8_t *pos = bitmap + (idx / 8); 88 89 while (idx < max) { 90 83 91 if (*pos == 0) { 84 92 *pos |= 1; 85 93 86 *index = (pos - bitmap) * 8;94 *index = idx; 87 95 return EOK; 88 96 } 89 97 98 idx += 8; 90 99 ++pos; 91 100 } 92 101 93 102 return ENOSPC; 94 95 103 } 96 104 97 int ext4_bitmap_find_free_bit_and_set(uint8_t *bitmap, uint32_t start, uint32_t *index, uint32_t size) 105 int ext4_bitmap_find_free_bit_and_set(uint8_t *bitmap, uint32_t start_idx, 106 uint32_t *index, uint32_t max) 98 107 { 99 uint8_t *pos = bitmap + (start / 8);100 int i;101 uint8_t value, new_value;108 uint8_t *pos = bitmap + (start_idx / 8); 109 uint32_t idx = start_idx; 110 bool byte_part = false; 102 111 103 while (pos < bitmap + size) { 112 // Check the rest of byte 113 while ((idx % 8) != 0) { 114 byte_part = true; 115 116 if (*pos & (1 << (idx % 8))) { 117 *pos |= (1 << (idx % 8)); 118 *index = idx; 119 return EOK; 120 } 121 122 ++idx; 123 } 124 125 if (byte_part) { 126 ++pos; 127 } 128 129 while (idx < max) { 130 104 131 if ((*pos & 255) != 255) { 105 132 // free bit found … … 107 134 } 108 135 136 idx += 8; 109 137 ++pos; 110 138 } 111 139 112 // Check the byte containing start 113 if (pos == bitmap + (start / 8)) { 114 for (i = start % 8; i < 8; ++i) { 115 value = *pos; 116 if ((value & (1 << i)) == 0) { 140 141 if (idx < max) { 142 for (uint8_t i = 0; i < 8; ++i) { 143 if ((*pos & (1 << i)) == 0) { 117 144 // free bit found 118 new_value = value | (1 << i); 119 *pos = new_value; 120 *index = (pos - bitmap) * 8 + i; 145 *pos |= (1 << i); 146 *index = idx; 121 147 return EOK; 122 148 } 123 } 124 } 125 126 if (pos < bitmap + size) { 127 128 for(i = 0; i < 8; ++i) { 129 value = *pos; 130 131 if ((value & (1 << i)) == 0) { 132 // free bit found 133 new_value = value | (1 << i); 134 *pos = new_value; 135 *index = (pos - bitmap) * 8 + i; 136 return EOK; 137 } 149 idx++; 138 150 } 139 151 }
Note:
See TracChangeset
for help on using the changeset viewer.