Changeset 662bd71 in mainline
- Timestamp:
- 2012-04-04T18:05:46Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e7ed26be
- Parents:
- 81092ce
- Location:
- uspace/lib/ext4
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/libext4_balloc.c
r81092ce r662bd71 123 123 // Update superblock free blocks count 124 124 uint32_t sb_free_blocks = ext4_superblock_get_free_blocks_count(sb); 125 sb_free_blocks --;125 sb_free_blocks++; 126 126 ext4_superblock_set_free_blocks_count(sb, sb_free_blocks); 127 127 … … 136 136 bg_ref->block_group, sb); 137 137 free_blocks++; 138 ext4_block_group_set_free_blocks_count(bg_ref->block_group, 139 sb, free_blocks); 140 bg_ref->dirty = true; 141 142 rc = ext4_filesystem_put_block_group_ref(bg_ref); 143 if (rc != EOK) { 144 EXT4FS_DBG("error in saving bg_ref \%d", rc); 145 // TODO error 146 return rc; 147 } 148 149 return EOK; 150 } 151 152 int ext4_balloc_free_blocks(ext4_inode_ref_t *inode_ref, 153 uint32_t first, uint32_t count) 154 { 155 int rc; 156 157 ext4_filesystem_t *fs = inode_ref->fs; 158 ext4_superblock_t *sb = fs->superblock; 159 160 uint32_t block_group_first = 161 ext4_balloc_get_bgid_of_block(sb, first); 162 uint32_t block_group_last = 163 ext4_balloc_get_bgid_of_block(sb, first + count); 164 165 assert(block_group_first == block_group_last); 166 167 ext4_block_group_ref_t *bg_ref; 168 rc = ext4_filesystem_get_block_group_ref(fs, block_group_first, &bg_ref); 169 if (rc != EOK) { 170 EXT4FS_DBG("error in loading bg_ref \%d", rc); 171 return rc; 172 } 173 174 uint32_t index_in_group_first = 175 ext4_balloc_blockaddr2_index_in_group(sb, first); 176 177 uint32_t bitmap_block_addr = ext4_block_group_get_block_bitmap( 178 bg_ref->block_group, sb); 179 180 block_t *bitmap_block; 181 rc = block_get(&bitmap_block, fs->device, bitmap_block_addr, 0); 182 if (rc != EOK) { 183 EXT4FS_DBG("error in loading bitmap \%d", rc); 184 return rc; 185 } 186 187 ext4_bitmap_free_bits(bitmap_block->data, index_in_group_first, count); 188 189 bitmap_block->dirty = true; 190 191 rc = block_put(bitmap_block); 192 if (rc != EOK) { 193 // Error in saving bitmap 194 ext4_filesystem_put_block_group_ref(bg_ref); 195 EXT4FS_DBG("error in saving bitmap \%d", rc); 196 return rc; 197 } 198 199 uint32_t block_size = ext4_superblock_get_block_size(sb); 200 201 // Update superblock free blocks count 202 uint32_t sb_free_blocks = ext4_superblock_get_free_blocks_count(sb); 203 sb_free_blocks += count; 204 ext4_superblock_set_free_blocks_count(sb, sb_free_blocks); 205 206 // Update inode blocks count 207 uint64_t ino_blocks = ext4_inode_get_blocks_count(sb, inode_ref->inode); 208 ino_blocks -= count * (block_size / EXT4_INODE_BLOCK_SIZE); 209 ext4_inode_set_blocks_count(sb, inode_ref->inode, ino_blocks); 210 inode_ref->dirty = true; 211 212 // Update block group free blocks count 213 uint32_t free_blocks = ext4_block_group_get_free_blocks_count( 214 bg_ref->block_group, sb); 215 free_blocks += count; 138 216 ext4_block_group_set_free_blocks_count(bg_ref->block_group, 139 217 sb, free_blocks); -
uspace/lib/ext4/libext4_balloc.h
r81092ce r662bd71 38 38 39 39 extern int ext4_balloc_free_block(ext4_inode_ref_t *, uint32_t); 40 extern int ext4_balloc_free_blocks(ext4_inode_ref_t *, 41 uint32_t , uint32_t); 40 42 extern int ext4_balloc_alloc_block(ext4_inode_ref_t *, uint32_t *); 41 43 -
uspace/lib/ext4/libext4_bitmap.c
r81092ce r662bd71 51 51 } 52 52 53 void ext4_bitmap_free_bits(uint8_t *bitmap, uint32_t index, uint32_t count) 54 { 55 uint8_t *target; 56 uint32_t idx = index; 57 uint32_t remaining = count; 58 uint32_t byte_index; 59 60 while (((idx % 8) != 0) && (remaining > 0)) { 61 62 byte_index = idx / 8; 63 uint32_t bit_index = idx % 8; 64 65 target = bitmap + byte_index; 66 67 *target &= ~ (1 << bit_index); 68 69 idx++; 70 remaining--; 71 } 72 73 assert((idx % 8) == 0); 74 75 byte_index = idx / 8; 76 target = bitmap + byte_index; 77 78 while (remaining >= 8) { 79 *target = 0; 80 81 idx += 8; 82 remaining -= 8; 83 target++; 84 } 85 86 assert(remaining < 8); 87 88 while (remaining != 0) { 89 90 byte_index = idx / 8; 91 uint32_t bit_index = idx % 8; 92 93 target = bitmap + byte_index; 94 95 *target &= ~ (1 << bit_index); 96 97 idx++; 98 remaining--; 99 } 100 } 101 53 102 void ext4_bitmap_set_bit(uint8_t *bitmap, uint32_t index) 54 103 { -
uspace/lib/ext4/libext4_bitmap.h
r81092ce r662bd71 37 37 38 38 extern void ext4_bitmap_free_bit(uint8_t *, uint32_t); 39 extern void ext4_bitmap_free_bits(uint8_t *, uint32_t, uint32_t); 39 40 extern void ext4_bitmap_set_bit(uint8_t *, uint32_t); 40 41 extern bool ext4_bitmap_is_free_bit(uint8_t *, uint32_t);
Note:
See TracChangeset
for help on using the changeset viewer.