Lines Matching refs:inode

405 static int64_t find_dir_entry(struct ext2_inode *inode, const char *name, size_t len,
430 args->inode = cur_dir; in ext2_lookup_inode()
521 args->inode = next; in ext2_lookup_inode()
562 static int64_t find_dir_entry(struct ext2_inode *inode, const char *name, size_t len, in find_dir_entry() argument
568 struct ext2_data *fs = inode->i_fs; in find_dir_entry()
571 while (offset < inode->i_size) { in find_dir_entry()
575 rc = ext2_fetch_inode_block(inode, block); in find_dir_entry()
581 EXT2_DISK_DIRENTRY_BY_OFFSET(inode_current_block_mem(inode), block_off); in find_dir_entry()
609 ssize_t ext2_inode_read(struct ext2_inode *inode, void *buf, uint32_t offset, size_t nbytes) in ext2_inode_read() argument
613 uint32_t block_size = inode->i_fs->block_size; in ext2_inode_read()
616 while (read < nbytes && offset < inode->i_size) { in ext2_inode_read()
621 rc = ext2_fetch_inode_block(inode, block); in ext2_inode_read()
627 uint32_t left_in_file = inode->i_size - offset; in ext2_inode_read()
630 memcpy((uint8_t *)buf + read, inode_current_block_mem(inode) + block_off, to_read); in ext2_inode_read()
643 ssize_t ext2_inode_write(struct ext2_inode *inode, const void *buf, uint32_t offset, size_t nbytes) in ext2_inode_write() argument
647 uint32_t block_size = inode->i_fs->block_size; in ext2_inode_write()
654 inode->i_id, block, offset, offset + nbytes, inode->i_size); in ext2_inode_write()
656 rc = ext2_fetch_inode_block(inode, block); in ext2_inode_write()
663 memcpy(inode_current_block_mem(inode) + block_off, (uint8_t *)buf + written, in ext2_inode_write()
667 rc = ext2_commit_inode_block(inode); in ext2_inode_write()
679 if (offset + written > inode->i_size) { in ext2_inode_write()
680 LOG_DBG("New inode size: %d -> %zd", inode->i_size, offset + written); in ext2_inode_write()
681 inode->i_size = offset + written; in ext2_inode_write()
682 rc = ext2_commit_inode(inode); in ext2_inode_write()
691 int ext2_inode_trunc(struct ext2_inode *inode, off_t length) in ext2_inode_trunc() argument
699 uint32_t old_size = inode->i_size; in ext2_inode_trunc()
700 const uint32_t block_size = inode->i_fs->block_size; in ext2_inode_trunc()
721 rc = ext2_fetch_inode_block(inode, old_block); in ext2_inode_trunc()
726 memset(inode_current_block_mem(inode) + start_off, 0, to_write); in ext2_inode_trunc()
727 rc = ext2_commit_inode_block(inode); in ext2_inode_trunc()
747 removed_blocks = ext2_inode_remove_blocks(inode, start_blk); in ext2_inode_trunc()
754 inode->i_blocks -= removed_blocks * (block_size / 512); in ext2_inode_trunc()
757 inode->i_size = new_size; in ext2_inode_trunc()
759 LOG_DBG("New inode size: %d (blocks: %d)", inode->i_size, inode->i_blocks); in ext2_inode_trunc()
761 rc = ext2_commit_inode(inode); in ext2_inode_trunc()
780 int ext2_inode_sync(struct ext2_inode *inode) in ext2_inode_sync() argument
783 struct ext2_data *fs = inode->i_fs; in ext2_inode_sync()
786 if (inode->blocks[i] == NULL) { in ext2_inode_sync()
789 ret = write_one_block(fs, inode->blocks[i]); in ext2_inode_sync()
823 struct ext2_inode *inode = NULL; in ext2_get_direntry() local
852 rc = ext2_inode_get(fs, de->de_inode, &inode); in ext2_get_direntry()
857 size = inode->i_size; in ext2_get_direntry()
867 ext2_inode_drop(inode); in ext2_get_direntry()
875 struct ext2_inode *inode, int type) in ext2_create_inode() argument
885 inode->i_fs = fs; in ext2_create_inode()
886 inode->flags = 0; in ext2_create_inode()
887 inode->i_id = ino; in ext2_create_inode()
888 inode->i_size = 0; in ext2_create_inode()
889 inode->i_mode = type == FS_DIR_ENTRY_FILE ? EXT2_DEF_FILE_MODE : EXT2_DEF_DIR_MODE; in ext2_create_inode()
890 inode->i_links_count = 0; in ext2_create_inode()
891 memset(inode->i_block, 0, 15 * 4); in ext2_create_inode()
904 rc = ext2_commit_inode(inode); in ext2_create_inode()
1028 rc = ext2_create_inode(fs, args->inode, new_inode, FS_DIR_ENTRY_FILE); in ext2_create_file()
1063 rc = ext2_create_inode(fs, args->inode, new_inode, FS_DIR_ENTRY_DIR); in ext2_create_dir()
1225 static int remove_inode(struct ext2_inode *inode) in remove_inode() argument
1229 LOG_DBG("inode: %d", inode->i_id); in remove_inode()
1232 ret = ext2_inode_remove_blocks(inode, 0); in remove_inode()
1238 ret = ext2_free_inode(inode->i_fs, inode->i_id, IS_DIR(inode->i_mode)); in remove_inode()
1242 static int can_unlink(struct ext2_inode *inode) in can_unlink() argument
1244 if (!IS_DIR(inode->i_mode)) { in can_unlink()
1250 rc = ext2_fetch_inode_block(inode, 0); in can_unlink()
1261 de = EXT2_DISK_DIRENTRY_BY_OFFSET(inode_current_block_mem(inode), 0); in can_unlink()
1265 de = EXT2_DISK_DIRENTRY_BY_OFFSET(inode_current_block_mem(inode), offset); in can_unlink()
1268 uint32_t block_size = inode->i_fs->block_size; in can_unlink()
1273 if (offset == block_size && inode->i_size == block_size) { in can_unlink()
1280 int ext2_inode_unlink(struct ext2_inode *parent, struct ext2_inode *inode, uint32_t offset) in ext2_inode_unlink() argument
1284 rc = can_unlink(inode); in ext2_inode_unlink()
1294 if ((IS_REG_FILE(inode->i_mode) && inode->i_links_count == 1) || in ext2_inode_unlink()
1295 (IS_DIR(inode->i_mode) && inode->i_links_count == 2)) { in ext2_inode_unlink()
1300 inode->flags |= INODE_REMOVE; in ext2_inode_unlink()
1303 inode->i_links_count -= 1; in ext2_inode_unlink()
1304 rc = ext2_commit_inode(inode); in ext2_inode_unlink()
1314 LOG_DBG("Inode: %d Inode to replace: %d", args_from->inode->i_id, args_to->inode->i_id); in ext2_replace_file()
1339 ext2_set_disk_direntry_inode(de, args_to->inode->i_id); in ext2_replace_file()
1340 rc = ext2_inode_unlink(args_from->parent, args_to->inode, args_from->offset); in ext2_replace_file()
1343 ext2_set_disk_direntry_inode(de, args_from->inode->i_id); in ext2_replace_file()
1359 ext2_set_disk_direntry_inode(de, args_from->inode->i_id); in ext2_replace_file()
1419 uint32_t inode = ext2_get_disk_direntry_inode(old_de); in ext2_move_file() local
1422 new_de = ext2_create_direntry(args_to->path + args_to->name_pos, args_to->name_len, inode, in ext2_move_file()
1444 struct ext2_inode *inode; in ext2_inode_get() local
1447 inode = fs->inode_pool[i]; in ext2_inode_get()
1449 if (inode->i_id == ino) { in ext2_inode_get()
1450 *ret = inode; in ext2_inode_get()
1451 inode->i_ref++; in ext2_inode_get()
1461 rc = k_mem_slab_alloc(&inode_struct_slab, (void **)&inode, K_FOREVER); in ext2_inode_get()
1465 memset(inode, 0, sizeof(struct ext2_inode)); in ext2_inode_get()
1468 int rc2 = ext2_fetch_inode(fs, ino, inode); in ext2_inode_get()
1471 k_mem_slab_free(&inode_struct_slab, (void *)inode); in ext2_inode_get()
1476 fs->inode_pool[fs->open_inodes] = inode; in ext2_inode_get()
1479 inode->i_fs = fs; in ext2_inode_get()
1480 inode->i_ref = 1; in ext2_inode_get()
1481 *ret = inode; in ext2_inode_get()
1485 int ext2_inode_drop(struct ext2_inode *inode) in ext2_inode_drop() argument
1487 if (inode == NULL) { in ext2_inode_drop()
1491 struct ext2_data *fs = inode->i_fs; in ext2_inode_drop()
1498 inode->i_ref--; in ext2_inode_drop()
1501 if (inode->i_ref == 0) { in ext2_inode_drop()
1506 while (offset < MAX_INODES && fs->inode_pool[offset] != inode) { in ext2_inode_drop()
1511 LOG_ERR("Inode structure at %p not in inode_pool", inode); in ext2_inode_drop()
1515 ext2_inode_drop_blocks(inode); in ext2_inode_drop()
1517 if (inode->flags & INODE_REMOVE) { in ext2_inode_drop()
1521 int rc = remove_inode(inode); in ext2_inode_drop()
1528 k_mem_slab_free(&inode_struct_slab, (void *)inode); in ext2_inode_drop()
1541 void ext2_inode_drop_blocks(struct ext2_inode *inode) in ext2_inode_drop_blocks() argument
1544 ext2_drop_block(inode->blocks[i]); in ext2_inode_drop_blocks()
1546 inode->flags &= ~INODE_FETCHED_BLOCK; in ext2_inode_drop_blocks()