Lines Matching +full:fill +full:- +full:level

4  * SPDX-License-Identifier: Apache-2.0
34 sb->s_inodes_count = sys_le32_to_cpu(disk_sb->s_inodes_count); in fill_sblock()
35 sb->s_blocks_count = sys_le32_to_cpu(disk_sb->s_blocks_count); in fill_sblock()
36 sb->s_free_blocks_count = sys_le32_to_cpu(disk_sb->s_free_blocks_count); in fill_sblock()
37 sb->s_free_inodes_count = sys_le32_to_cpu(disk_sb->s_free_inodes_count); in fill_sblock()
38 sb->s_first_data_block = sys_le32_to_cpu(disk_sb->s_first_data_block); in fill_sblock()
39 sb->s_log_block_size = sys_le32_to_cpu(disk_sb->s_log_block_size); in fill_sblock()
40 sb->s_log_frag_size = sys_le32_to_cpu(disk_sb->s_log_frag_size); in fill_sblock()
41 sb->s_blocks_per_group = sys_le32_to_cpu(disk_sb->s_blocks_per_group); in fill_sblock()
42 sb->s_frags_per_group = sys_le32_to_cpu(disk_sb->s_frags_per_group); in fill_sblock()
43 sb->s_inodes_per_group = sys_le32_to_cpu(disk_sb->s_inodes_per_group); in fill_sblock()
44 sb->s_mnt_count = sys_le16_to_cpu(disk_sb->s_mnt_count); in fill_sblock()
45 sb->s_max_mnt_count = sys_le16_to_cpu(disk_sb->s_max_mnt_count); in fill_sblock()
46 sb->s_magic = sys_le16_to_cpu(disk_sb->s_magic); in fill_sblock()
47 sb->s_state = sys_le16_to_cpu(disk_sb->s_state); in fill_sblock()
48 sb->s_errors = sys_le16_to_cpu(disk_sb->s_errors); in fill_sblock()
49 sb->s_creator_os = sys_le32_to_cpu(disk_sb->s_creator_os); in fill_sblock()
50 sb->s_rev_level = sys_le32_to_cpu(disk_sb->s_rev_level); in fill_sblock()
51 sb->s_first_ino = sys_le32_to_cpu(disk_sb->s_first_ino); in fill_sblock()
52 sb->s_inode_size = sys_le16_to_cpu(disk_sb->s_inode_size); in fill_sblock()
53 sb->s_block_group_nr = sys_le16_to_cpu(disk_sb->s_block_group_nr); in fill_sblock()
54 sb->s_feature_compat = sys_le32_to_cpu(disk_sb->s_feature_compat); in fill_sblock()
55 sb->s_feature_incompat = sys_le32_to_cpu(disk_sb->s_feature_incompat); in fill_sblock()
56 sb->s_feature_ro_compat = sys_le32_to_cpu(disk_sb->s_feature_ro_compat); in fill_sblock()
61 disk_sb->s_inodes_count = sys_cpu_to_le32(sb->s_inodes_count); in fill_disk_sblock()
62 disk_sb->s_blocks_count = sys_cpu_to_le32(sb->s_blocks_count); in fill_disk_sblock()
63 disk_sb->s_free_blocks_count = sys_cpu_to_le32(sb->s_free_blocks_count); in fill_disk_sblock()
64 disk_sb->s_free_inodes_count = sys_cpu_to_le32(sb->s_free_inodes_count); in fill_disk_sblock()
65 disk_sb->s_first_data_block = sys_cpu_to_le32(sb->s_first_data_block); in fill_disk_sblock()
66 disk_sb->s_log_block_size = sys_cpu_to_le32(sb->s_log_block_size); in fill_disk_sblock()
67 disk_sb->s_log_frag_size = sys_cpu_to_le32(sb->s_log_frag_size); in fill_disk_sblock()
68 disk_sb->s_blocks_per_group = sys_cpu_to_le32(sb->s_blocks_per_group); in fill_disk_sblock()
69 disk_sb->s_frags_per_group = sys_cpu_to_le32(sb->s_frags_per_group); in fill_disk_sblock()
70 disk_sb->s_inodes_per_group = sys_cpu_to_le32(sb->s_inodes_per_group); in fill_disk_sblock()
71 disk_sb->s_mnt_count = sys_cpu_to_le16(sb->s_mnt_count); in fill_disk_sblock()
72 disk_sb->s_max_mnt_count = sys_cpu_to_le16(sb->s_max_mnt_count); in fill_disk_sblock()
73 disk_sb->s_magic = sys_cpu_to_le16(sb->s_magic); in fill_disk_sblock()
74 disk_sb->s_state = sys_cpu_to_le16(sb->s_state); in fill_disk_sblock()
75 disk_sb->s_errors = sys_cpu_to_le16(sb->s_errors); in fill_disk_sblock()
76 disk_sb->s_creator_os = sys_cpu_to_le32(sb->s_creator_os); in fill_disk_sblock()
77 disk_sb->s_rev_level = sys_cpu_to_le32(sb->s_rev_level); in fill_disk_sblock()
78 disk_sb->s_first_ino = sys_cpu_to_le32(sb->s_first_ino); in fill_disk_sblock()
79 disk_sb->s_inode_size = sys_cpu_to_le16(sb->s_inode_size); in fill_disk_sblock()
80 disk_sb->s_block_group_nr = sys_cpu_to_le16(sb->s_block_group_nr); in fill_disk_sblock()
81 disk_sb->s_feature_compat = sys_cpu_to_le32(sb->s_feature_compat); in fill_disk_sblock()
82 disk_sb->s_feature_incompat = sys_cpu_to_le32(sb->s_feature_incompat); in fill_disk_sblock()
83 disk_sb->s_feature_ro_compat = sys_cpu_to_le32(sb->s_feature_ro_compat); in fill_disk_sblock()
88 bg->bg_block_bitmap = sys_le32_to_cpu(disk_bg->bg_block_bitmap); in fill_bgroup()
89 bg->bg_inode_bitmap = sys_le32_to_cpu(disk_bg->bg_inode_bitmap); in fill_bgroup()
90 bg->bg_inode_table = sys_le32_to_cpu(disk_bg->bg_inode_table); in fill_bgroup()
91 bg->bg_free_blocks_count = sys_le16_to_cpu(disk_bg->bg_free_blocks_count); in fill_bgroup()
92 bg->bg_free_inodes_count = sys_le16_to_cpu(disk_bg->bg_free_inodes_count); in fill_bgroup()
93 bg->bg_used_dirs_count = sys_le16_to_cpu(disk_bg->bg_used_dirs_count); in fill_bgroup()
98 disk_bg->bg_block_bitmap = sys_cpu_to_le32(bg->bg_block_bitmap); in fill_disk_bgroup()
99 disk_bg->bg_inode_bitmap = sys_cpu_to_le32(bg->bg_inode_bitmap); in fill_disk_bgroup()
100 disk_bg->bg_inode_table = sys_cpu_to_le32(bg->bg_inode_table); in fill_disk_bgroup()
101 disk_bg->bg_free_blocks_count = sys_cpu_to_le16(bg->bg_free_blocks_count); in fill_disk_bgroup()
102 disk_bg->bg_free_inodes_count = sys_cpu_to_le16(bg->bg_free_inodes_count); in fill_disk_bgroup()
103 disk_bg->bg_used_dirs_count = sys_cpu_to_le16(bg->bg_used_dirs_count); in fill_disk_bgroup()
108 inode->i_mode = sys_le16_to_cpu(dino->i_mode); in fill_inode()
109 inode->i_size = sys_le32_to_cpu(dino->i_size); in fill_inode()
110 inode->i_links_count = sys_le16_to_cpu(dino->i_links_count); in fill_inode()
111 inode->i_blocks = sys_le32_to_cpu(dino->i_blocks); in fill_inode()
113 inode->i_block[i] = sys_le32_to_cpu(dino->i_block[i]); in fill_inode()
119 dino->i_mode = sys_cpu_to_le16(inode->i_mode); in fill_disk_inode()
120 dino->i_size = sys_cpu_to_le32(inode->i_size); in fill_disk_inode()
121 dino->i_links_count = sys_cpu_to_le16(inode->i_links_count); in fill_disk_inode()
122 dino->i_blocks = sys_cpu_to_le32(inode->i_blocks); in fill_disk_inode()
124 dino->i_block[i] = sys_cpu_to_le32(inode->i_block[i]); in fill_disk_inode()
131 if (disk_de->de_name_len > EXT2_MAX_FILE_NAME) { in ext2_fetch_direntry()
134 uint32_t prog_rec_len = sizeof(struct ext2_direntry) + disk_de->de_name_len; in ext2_fetch_direntry()
139 de->de_inode = sys_le32_to_cpu(disk_de->de_inode); in ext2_fetch_direntry()
140 de->de_rec_len = sys_le16_to_cpu(disk_de->de_rec_len); in ext2_fetch_direntry()
141 de->de_name_len = disk_de->de_name_len; in ext2_fetch_direntry()
142 de->de_file_type = disk_de->de_file_type; in ext2_fetch_direntry()
143 memcpy(de->de_name, disk_de->de_name, de->de_name_len); in ext2_fetch_direntry()
149 disk_de->de_inode = sys_le32_to_cpu(de->de_inode); in ext2_write_direntry()
150 disk_de->de_rec_len = sys_le16_to_cpu(de->de_rec_len); in ext2_write_direntry()
151 disk_de->de_name_len = de->de_name_len; in ext2_write_direntry()
152 disk_de->de_file_type = de->de_file_type; in ext2_write_direntry()
153 memcpy(disk_de->de_name, de->de_name, de->de_name_len); in ext2_write_direntry()
158 return sys_le32_to_cpu(de->de_inode); in ext2_get_disk_direntry_inode()
163 return sys_le16_to_cpu(de->de_rec_len); in ext2_get_disk_direntry_reclen()
168 return de->de_name_len; in ext2_get_disk_direntry_namelen()
173 return de->de_file_type; in ext2_get_disk_direntry_type()
178 de->de_inode = sys_cpu_to_le32(inode); in ext2_set_disk_direntry_inode()
183 de->de_rec_len = sys_cpu_to_le16(reclen); in ext2_set_disk_direntry_reclen()
188 de->de_name_len = namelen; in ext2_set_disk_direntry_namelen()
193 de->de_file_type = type; in ext2_set_disk_direntry_type()
198 memcpy(de->de_name, name, len); in ext2_set_disk_direntry_name()
206 if (fs->block_size == 1024) { in ext2_fetch_superblock()
214 return -ENOENT; in ext2_fetch_superblock()
218 (struct ext2_disk_superblock *)(b->data + sblock_offset); in ext2_fetch_superblock()
220 fill_sblock(&fs->sblock, disk_sb); in ext2_fetch_superblock()
229 fs->sblock.s_blocks_count / fs->sblock.s_blocks_per_group; in get_ngroups()
231 if (fs->sblock.s_blocks_count % fs->sblock.s_blocks_per_group != 0) { in get_ngroups()
240 struct ext2_bgroup *bg = &fs->bgroup; in ext2_fetch_block_group()
243 if (group == bg->num) { in ext2_fetch_block_group()
250 LOG_DBG("cur_group:%d fetch_group:%d", bg->num, group); in ext2_fetch_block_group()
253 return -ERANGE; in ext2_fetch_block_group()
256 uint32_t groups_per_block = fs->block_size / sizeof(struct ext2_disk_bgroup); in ext2_fetch_block_group()
259 uint32_t global_block = fs->sblock.s_first_data_block + 1 + block; in ext2_fetch_block_group()
264 return -ENOENT; in ext2_fetch_block_group()
267 struct ext2_disk_bgroup *disk_bg = ((struct ext2_disk_bgroup *)b->data) + offset; in ext2_fetch_block_group()
275 ext2_drop_block(bg->inode_table); in ext2_fetch_block_group()
276 ext2_drop_block(bg->inode_bitmap); in ext2_fetch_block_group()
277 ext2_drop_block(bg->block_bitmap); in ext2_fetch_block_group()
278 bg->inode_table = bg->inode_bitmap = bg->block_bitmap = NULL; in ext2_fetch_block_group()
280 bg->fs = fs; in ext2_fetch_block_group()
281 bg->num = group; in ext2_fetch_block_group()
284 group, bg->bg_inode_table, in ext2_fetch_block_group()
285 bg->bg_free_blocks_count, in ext2_fetch_block_group()
286 bg->bg_free_inodes_count, in ext2_fetch_block_group()
287 bg->bg_used_dirs_count, in ext2_fetch_block_group()
288 bg->bg_block_bitmap, in ext2_fetch_block_group()
289 bg->bg_inode_bitmap); in ext2_fetch_block_group()
295 if (bg->inode_table && bg->inode_table_block == block) { in ext2_fetch_bg_itable()
299 struct ext2_data *fs = bg->fs; in ext2_fetch_bg_itable()
300 uint32_t global_block = bg->bg_inode_table + block; in ext2_fetch_bg_itable()
302 ext2_drop_block(bg->inode_table); in ext2_fetch_bg_itable()
303 bg->inode_table = ext2_get_block(fs, global_block); in ext2_fetch_bg_itable()
304 if (bg->inode_table == NULL) { in ext2_fetch_bg_itable()
305 return -ENOENT; in ext2_fetch_bg_itable()
308 bg->inode_table_block = block; in ext2_fetch_bg_itable()
314 if (bg->inode_bitmap) { in ext2_fetch_bg_ibitmap()
318 struct ext2_data *fs = bg->fs; in ext2_fetch_bg_ibitmap()
319 uint32_t global_block = bg->bg_inode_bitmap; in ext2_fetch_bg_ibitmap()
321 bg->inode_bitmap = ext2_get_block(fs, global_block); in ext2_fetch_bg_ibitmap()
322 if (bg->inode_bitmap == NULL) { in ext2_fetch_bg_ibitmap()
323 return -ENOENT; in ext2_fetch_bg_ibitmap()
330 if (bg->block_bitmap) { in ext2_fetch_bg_bbitmap()
334 struct ext2_data *fs = bg->fs; in ext2_fetch_bg_bbitmap()
335 uint32_t global_block = bg->bg_block_bitmap; in ext2_fetch_bg_bbitmap()
337 bg->block_bitmap = ext2_get_block(fs, global_block); in ext2_fetch_bg_bbitmap()
338 if (bg->block_bitmap == NULL) { in ext2_fetch_bg_bbitmap()
339 return -ENOENT; in ext2_fetch_bg_bbitmap()
352 uint32_t ino_group = (ino - 1) / fs->sblock.s_inodes_per_group; in get_itable_entry()
353 uint32_t ino_index = (ino - 1) % fs->sblock.s_inodes_per_group; in get_itable_entry()
362 uint32_t inode_size = fs->sblock.s_inode_size; in get_itable_entry()
363 uint32_t inodes_per_block = fs->block_size / inode_size; in get_itable_entry()
370 rc = ext2_fetch_bg_itable(&fs->bgroup, block_index); in get_itable_entry()
388 struct ext2_disk_inode *dino = &BGROUP_INODE_TABLE(&fs->bgroup)[itable_offset]; in ext2_fetch_inode()
393 inode->i_fs = fs; in ext2_fetch_inode()
394 inode->flags = 0; in ext2_fetch_inode()
395 inode->i_id = ino; in ext2_fetch_inode()
397 LOG_DBG("mode:%d size:%d links:%d", dino->i_mode, dino->i_size, dino->i_links_count); in ext2_fetch_inode()
402 * @param try_current -- if true then check if searched offset matches offset of currently fetched
403 * block on that level. If they match then it is the block we are looking for.
409 bool already_fetched = try_current && (offsets[lvl] == inode->offsets[lvl]); in fetch_level_blocks()
416 /* If already fetched block matches desired one we can use it and move to the next level. */ in fetch_level_blocks()
418 /* Fetched block on current level was wrong. in fetch_level_blocks()
423 ext2_drop_block(inode->blocks[lvl]); in fetch_level_blocks()
426 block = inode->i_block[offsets[0]]; in fetch_level_blocks()
428 uint32_t *list = (uint32_t *)inode->blocks[lvl - 1]->data; in fetch_level_blocks()
434 inode->blocks[lvl] = ext2_get_empty_block(inode->i_fs); in fetch_level_blocks()
436 inode->blocks[lvl] = ext2_get_block(inode->i_fs, block); in fetch_level_blocks()
439 if (inode->blocks[lvl] == NULL) { in fetch_level_blocks()
440 return -ENOENT; in fetch_level_blocks()
450 if (inode->flags & INODE_FETCHED_BLOCK && inode->block_num == block) { in ext2_fetch_inode_block()
454 LOG_DBG("inode:%d cur_blk:%d fetch_blk:%d", inode->i_id, inode->block_num, block); in ext2_fetch_inode_block()
456 struct ext2_data *fs = inode->i_fs; in ext2_fetch_inode_block()
459 bool try_current = inode->flags & INODE_FETCHED_BLOCK; in ext2_fetch_inode_block()
469 memcpy(inode->offsets, offsets, MAX_OFFSETS_SIZE * sizeof(uint32_t)); in ext2_fetch_inode_block()
470 inode->block_lvl = max_lvl; in ext2_fetch_inode_block()
471 inode->block_num = block; in ext2_fetch_inode_block()
472 inode->flags |= INODE_FETCHED_BLOCK; in ext2_fetch_inode_block()
474 LOG_DBG("[ino:%d fetch]\t Lvl:%d {%d, %d, %d, %d}", inode->i_id, inode->block_lvl, in ext2_fetch_inode_block()
475 inode->offsets[0], inode->offsets[1], inode->offsets[2], inode->offsets[3]); in ext2_fetch_inode_block()
522 return -ENOENT; in delete_blocks()
524 list = (uint32_t *)list_block->data; in delete_blocks()
549 fs->flags |= EXT2_DATA_FLAGS_ERR; in delete_blocks()
550 removed = -EINVAL; in delete_blocks()
554 /* We will start removing whole blocks from next block on this level */ in delete_blocks()
557 /* Remove desired part of lower level block. */ in delete_blocks()
558 rem = delete_blocks(fs, block_num2, lvl - 1, &offsets[1]); in delete_blocks()
567 for (uint32_t i = start_blk; i < fs->block_size / EXT2_BLOCK_NUM_SIZE; ++i) { in delete_blocks()
573 rem = delete_blocks(fs, block_num2, lvl - 1, zero_offsets); in delete_blocks()
612 const uint32_t B = fs->block_size / EXT2_BLOCK_NUM_SIZE; in get_level_offsets()
618 /* Level 0 */ in get_level_offsets()
624 /* Level 1 */ in get_level_offsets()
625 block -= lvl0_blks; in get_level_offsets()
632 /* Level 2 */ in get_level_offsets()
633 block -= lvl1_blks; in get_level_offsets()
641 /* Level 3 */ in get_level_offsets()
643 block -= lvl2_blks; in get_level_offsets()
651 return -EINVAL; in get_level_offsets()
657 return block - EXT2_INODE_BLOCK_1LVL + 1; in block0_level()
668 struct ext2_data *fs = inode->i_fs; in ext2_inode_remove_blocks()
670 max_lvl = get_level_offsets(inode->i_fs, first, offsets); in ext2_inode_remove_blocks()
674 * - one of the first 12 blocks in the indode in ext2_inode_remove_blocks()
675 * - the first referenced block in the indirect block list; in ext2_inode_remove_blocks()
683 if (inode->i_block[offsets[0]] == 0) { in ext2_inode_remove_blocks()
685 fs->flags |= EXT2_DATA_FLAGS_ERR; in ext2_inode_remove_blocks()
686 return -EINVAL; in ext2_inode_remove_blocks()
690 ret = delete_blocks(inode->i_fs, inode->i_block[offsets[0]], in ext2_inode_remove_blocks()
699 if (inode->i_block[i] == 0) { in ext2_inode_remove_blocks()
702 ret = delete_blocks(inode->i_fs, inode->i_block[i], block0_level(i), in ext2_inode_remove_blocks()
708 inode->i_block[i] = 0; in ext2_inode_remove_blocks()
717 struct ext2_data *fs = inode->i_fs; in alloc_level_blocks()
719 for (int lvl = 0; lvl <= inode->block_lvl; ++lvl) { in alloc_level_blocks()
721 block = &inode->i_block[inode->offsets[lvl]]; in alloc_level_blocks()
723 block = &((uint32_t *)inode->blocks[lvl - 1]->data)[inode->offsets[lvl]]; in alloc_level_blocks()
728 ret = ext2_assign_block_num(fs, inode->blocks[lvl]); in alloc_level_blocks()
733 /* Update block from higher level. */ in alloc_level_blocks()
734 *block = sys_cpu_to_le32(inode->blocks[lvl]->num); in alloc_level_blocks()
736 ret = ext2_write_block(fs, inode->blocks[lvl-1]); in alloc_level_blocks()
742 /* Allocating block on that level implies that blocks on lower levels will in alloc_level_blocks()
746 lvl == inode->block_lvl ? "data" : "indirect"); in alloc_level_blocks()
753 inode->i_blocks += fs->block_size / 512; in alloc_level_blocks()
765 if (fs->block_size == 1024) { in ext2_commit_superblock()
773 return -ENOENT; in ext2_commit_superblock()
777 (struct ext2_disk_superblock *)(b->data + sblock_offset); in ext2_commit_superblock()
779 fill_disk_sblock(disk_sb, &fs->sblock); in ext2_commit_superblock()
792 struct ext2_bgroup *bg = &fs->bgroup; in ext2_commit_bg()
794 uint32_t groups_per_block = fs->block_size / sizeof(struct ext2_disk_bgroup); in ext2_commit_bg()
795 uint32_t block = bg->num / groups_per_block; in ext2_commit_bg()
796 uint32_t offset = bg->num % groups_per_block; in ext2_commit_bg()
797 uint32_t global_block = fs->sblock.s_first_data_block + 1 + block; in ext2_commit_bg()
802 return -ENOENT; in ext2_commit_bg()
805 struct ext2_disk_bgroup *disk_bg = ((struct ext2_disk_bgroup *)b->data) + offset; in ext2_commit_bg()
819 struct ext2_data *fs = inode->i_fs; in ext2_commit_inode()
821 int32_t itable_offset = get_itable_entry(fs, inode->i_id); in ext2_commit_inode()
828 struct ext2_disk_inode *dino = &BGROUP_INODE_TABLE(&fs->bgroup)[itable_offset]; in ext2_commit_inode()
830 /* fill dinode */ in ext2_commit_inode()
833 return ext2_write_block(fs, fs->bgroup.inode_table); in ext2_commit_inode()
838 if (!(inode->flags & INODE_FETCHED_BLOCK)) { in ext2_commit_inode_block()
839 return -EINVAL; in ext2_commit_inode_block()
844 LOG_DBG("inode:%d current_blk:%d", inode->i_id, inode->block_num); in ext2_commit_inode_block()
850 ret = ext2_write_block(inode->i_fs, inode_current_block(inode)); in ext2_commit_inode_block()
863 memset(&BGROUP_INODE_TABLE(&fs->bgroup)[itable_offset], 0, sizeof(struct ext2_disk_inode)); in ext2_clear_inode()
864 ret = ext2_write_block(fs, fs->bgroup.inode_table); in ext2_clear_inode()
879 LOG_DBG("Free blocks: %d", fs->bgroup.bg_free_blocks_count); in ext2_alloc_block()
880 while ((rc >= 0) && (fs->bgroup.bg_free_blocks_count == 0)) { in ext2_alloc_block()
883 if (rc == -ERANGE) { in ext2_alloc_block()
885 return -ENOSPC; in ext2_alloc_block()
892 rc = ext2_fetch_bg_bbitmap(&fs->bgroup); in ext2_alloc_block()
897 bitmap_slot = ext2_bitmap_find_free(BGROUP_BLOCK_BITMAP(&fs->bgroup), fs->block_size); in ext2_alloc_block()
904 total = group * fs->sblock.s_blocks_per_group + bitmap_slot + fs->sblock.s_first_data_block; in ext2_alloc_block()
908 rc = ext2_bitmap_set(BGROUP_BLOCK_BITMAP(&fs->bgroup), bitmap_slot, fs->block_size); in ext2_alloc_block()
913 fs->bgroup.bg_free_blocks_count -= 1; in ext2_alloc_block()
914 fs->sblock.s_free_blocks_count -= 1; in ext2_alloc_block()
916 set = ext2_bitmap_count_set(BGROUP_BLOCK_BITMAP(&fs->bgroup), fs->sblock.s_blocks_count); in ext2_alloc_block()
918 if (set != (fs->sblock.s_blocks_count - fs->sblock.s_free_blocks_count)) { in ext2_alloc_block()
920 return -EINVAL; in ext2_alloc_block()
926 return -EIO; in ext2_alloc_block()
931 return -EIO; in ext2_alloc_block()
933 rc = ext2_write_block(fs, fs->bgroup.block_bitmap); in ext2_alloc_block()
936 return -EIO; in ext2_alloc_block()
949 uint8_t *bytes = (uint8_t *)&BGROUP_INODE_TABLE(&fs->bgroup)[itable_offset]; in check_zero_inode()
953 return -EINVAL; in check_zero_inode()
967 while (fs->bgroup.bg_free_inodes_count == 0 && rc >= 0) { in ext2_alloc_inode()
970 if (rc == -ERANGE) { in ext2_alloc_inode()
972 return -ENOSPC; in ext2_alloc_inode()
980 LOG_DBG("Free inodes (bg): %d", fs->bgroup.bg_free_inodes_count); in ext2_alloc_inode()
981 LOG_DBG("Free inodes (sb): %d", fs->sblock.s_free_inodes_count); in ext2_alloc_inode()
983 rc = ext2_fetch_bg_ibitmap(&fs->bgroup); in ext2_alloc_inode()
988 r = ext2_bitmap_find_free(BGROUP_INODE_BITMAP(&fs->bgroup), fs->block_size); in ext2_alloc_inode()
995 global_idx = group * fs->sblock.s_inodes_per_group + r + 1; in ext2_alloc_inode()
1000 return -EINVAL; in ext2_alloc_inode()
1005 rc = ext2_bitmap_set(BGROUP_INODE_BITMAP(&fs->bgroup), r, fs->block_size); in ext2_alloc_inode()
1010 fs->bgroup.bg_free_inodes_count -= 1; in ext2_alloc_inode()
1011 fs->sblock.s_free_inodes_count -= 1; in ext2_alloc_inode()
1013 set = ext2_bitmap_count_set(BGROUP_INODE_BITMAP(&fs->bgroup), fs->sblock.s_inodes_count); in ext2_alloc_inode()
1015 if (set != fs->sblock.s_inodes_count - fs->sblock.s_free_inodes_count) { in ext2_alloc_inode()
1017 return -EINVAL; in ext2_alloc_inode()
1023 return -EIO; in ext2_alloc_inode()
1028 return -EIO; in ext2_alloc_inode()
1030 rc = ext2_write_block(fs, fs->bgroup.inode_bitmap); in ext2_alloc_inode()
1033 return -EIO; in ext2_alloc_inode()
1036 LOG_DBG("Free inodes (bg): %d", fs->bgroup.bg_free_inodes_count); in ext2_alloc_inode()
1037 LOG_DBG("Free inodes (sb): %d", fs->sblock.s_free_inodes_count); in ext2_alloc_inode()
1047 block -= fs->sblock.s_first_data_block; in ext2_free_block()
1050 uint32_t group = block / fs->sblock.s_blocks_per_group; in ext2_free_block()
1051 uint32_t off = block % fs->sblock.s_blocks_per_group; in ext2_free_block()
1059 rc = ext2_fetch_bg_bbitmap(&fs->bgroup); in ext2_free_block()
1064 rc = ext2_bitmap_unset(BGROUP_BLOCK_BITMAP(&fs->bgroup), off, fs->block_size); in ext2_free_block()
1069 fs->bgroup.bg_free_blocks_count += 1; in ext2_free_block()
1070 fs->sblock.s_free_blocks_count += 1; in ext2_free_block()
1072 set = ext2_bitmap_count_set(BGROUP_BLOCK_BITMAP(&fs->bgroup), fs->sblock.s_blocks_count); in ext2_free_block()
1074 if (set != fs->sblock.s_blocks_count - fs->sblock.s_free_blocks_count) { in ext2_free_block()
1076 return -EINVAL; in ext2_free_block()
1082 return -EIO; in ext2_free_block()
1087 return -EIO; in ext2_free_block()
1089 rc = ext2_write_block(fs, fs->bgroup.block_bitmap); in ext2_free_block()
1092 return -EIO; in ext2_free_block()
1102 uint32_t group = (ino - 1) / fs->sblock.s_inodes_per_group; in ext2_free_inode()
1103 uint32_t bitmap_off = (ino - 1) % fs->sblock.s_inodes_per_group; in ext2_free_inode()
1111 rc = ext2_fetch_bg_ibitmap(&fs->bgroup); in ext2_free_inode()
1116 rc = ext2_bitmap_unset(BGROUP_INODE_BITMAP(&fs->bgroup), bitmap_off, fs->block_size); in ext2_free_inode()
1126 fs->bgroup.bg_free_inodes_count += 1; in ext2_free_inode()
1127 fs->sblock.s_free_inodes_count += 1; in ext2_free_inode()
1130 fs->bgroup.bg_used_dirs_count -= 1; in ext2_free_inode()
1133 set = ext2_bitmap_count_set(BGROUP_INODE_BITMAP(&fs->bgroup), fs->sblock.s_inodes_count); in ext2_free_inode()
1135 if (set != fs->sblock.s_inodes_count - fs->sblock.s_free_inodes_count) { in ext2_free_inode()
1137 return -EINVAL; in ext2_free_inode()
1145 return -EIO; in ext2_free_inode()
1150 return -EIO; in ext2_free_inode()
1152 rc = ext2_write_block(fs, fs->bgroup.inode_bitmap); in ext2_free_inode()
1155 return -EIO; in ext2_free_inode()
1157 rc = fs->backend_ops->sync(fs); in ext2_free_inode()
1159 return -EIO; in ext2_free_inode()