Example #1
0
int ext2_load_inode(ext2_t *ext2, inodenum_t num, struct ext2_inode *inode)
{
	int err;

	LTRACEF("num %d, inode %p\n", num, inode);

	blocknum_t bnum;
	size_t block_offset;
	get_inode_addr(ext2, num, &bnum, &block_offset);

	LTRACEF("bnum %u, offset %zd\n", bnum, block_offset);

	/* get a pointer to the cache block */
	void *cache_ptr;
	err = bcache_get_block(ext2->cache, &cache_ptr, bnum);
	if (err < 0)
		return err;

	/* copy the inode out */
	memcpy(inode, (uint8_t *)cache_ptr + block_offset, sizeof(struct ext2_inode));

	/* put the cache block */
	bcache_put_block(ext2->cache, bnum);

	/* endian swap it */
	endian_swap_inode(inode);

	LTRACEF("read inode: mode 0x%x, size %d\n", inode->i_mode, inode->i_size);

	return 0;
}
Example #2
0
File: io.c Project: 0xBADCA7/lk
int ext2_get_block(ext2_t *ext2, void **ptr, blocknum_t bnum)
{
    return bcache_get_block(ext2->cache, ptr, bnum);
}