Lines Matching refs:inode

106 static void fill_inode(struct ext2_inode *inode, struct ext2_disk_inode *dino)  in fill_inode()  argument
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()
117 static void fill_disk_inode(struct ext2_disk_inode *dino, struct ext2_inode *inode) in fill_disk_inode() argument
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()
176 void ext2_set_disk_direntry_inode(struct ext2_disk_direntry *de, uint32_t inode) in ext2_set_disk_direntry_inode() argument
178 de->de_inode = sys_cpu_to_le32(inode); in ext2_set_disk_direntry_inode()
377 int ext2_fetch_inode(struct ext2_data *fs, uint32_t ino, struct ext2_inode *inode) in ext2_fetch_inode() argument
390 fill_inode(inode, dino); 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()
405 static int fetch_level_blocks(struct ext2_inode *inode, uint32_t offsets[4], int lvl, int max_lvl, in fetch_level_blocks() argument
409 bool already_fetched = try_current && (offsets[lvl] == inode->offsets[lvl]); 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()
444 return fetch_level_blocks(inode, offsets, lvl + 1, max_lvl, try_current); in fetch_level_blocks()
447 int ext2_fetch_inode_block(struct ext2_inode *inode, uint32_t block) in ext2_fetch_inode_block() argument
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()
463 ret = fetch_level_blocks(inode, offsets, 0, max_lvl, try_current); in ext2_fetch_inode_block()
465 ext2_inode_drop_blocks(inode); 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()
662 int64_t ext2_inode_remove_blocks(struct ext2_inode *inode, uint32_t first) in ext2_inode_remove_blocks() argument
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()
681 if (inode->i_block[offsets[0]] == 0) { in ext2_inode_remove_blocks()
688 ret = delete_blocks(inode->i_fs, inode->i_block[offsets[0]], in ext2_inode_remove_blocks()
697 if (inode->i_block[i] == 0) { in ext2_inode_remove_blocks()
700 ret = delete_blocks(inode->i_fs, inode->i_block[i], block0_level(i), in ext2_inode_remove_blocks()
706 inode->i_block[i] = 0; in ext2_inode_remove_blocks()
710 static int alloc_level_blocks(struct ext2_inode *inode) in alloc_level_blocks() argument
715 struct ext2_data *fs = inode->i_fs; in alloc_level_blocks()
717 for (int lvl = 0; lvl <= inode->block_lvl; ++lvl) { in alloc_level_blocks()
719 block = &inode->i_block[inode->offsets[lvl]]; in alloc_level_blocks()
721 block = &((uint32_t *)inode->blocks[lvl - 1]->data)[inode->offsets[lvl]]; in alloc_level_blocks()
726 ret = ext2_assign_block_num(fs, inode->blocks[lvl]); in alloc_level_blocks()
732 *block = sys_cpu_to_le32(inode->blocks[lvl]->num); in alloc_level_blocks()
734 ret = ext2_write_block(fs, inode->blocks[lvl-1]); in alloc_level_blocks()
744 lvl == inode->block_lvl ? "data" : "indirect"); in alloc_level_blocks()
751 inode->i_blocks += fs->block_size / 512; in alloc_level_blocks()
752 ret = ext2_commit_inode(inode); in alloc_level_blocks()
815 int ext2_commit_inode(struct ext2_inode *inode) in ext2_commit_inode() argument
817 struct ext2_data *fs = inode->i_fs; in ext2_commit_inode()
819 int32_t itable_offset = get_itable_entry(fs, inode->i_id); in ext2_commit_inode()
829 fill_disk_inode(dino, inode); in ext2_commit_inode()
834 int ext2_commit_inode_block(struct ext2_inode *inode) in ext2_commit_inode_block() argument
836 if (!(inode->flags & INODE_FETCHED_BLOCK)) { in ext2_commit_inode_block()
842 LOG_DBG("inode:%d current_blk:%d", inode->i_id, inode->block_num); in ext2_commit_inode_block()
844 ret = alloc_level_blocks(inode); in ext2_commit_inode_block()
848 ret = ext2_write_block(inode->i_fs, inode_current_block(inode)); in ext2_commit_inode_block()