BarryServer : Git

All the code for all my projects
// BarryServer : Git / Orion / blob / 7ae31b03c38925f5d527e6303765925586731209 / vfs / ext2fs / block.c

// Related

Orion

Barry Importing existing Orion kernel d41a53c (2 years, 4 months ago)
/*
 * This file contains the Ext2 block implementation.  It reads a backing file
 * from the super block in the intervals specified by the superblock.  It also
 * contains functions for reading blocks from files.
 */

#include <stdint.h>
#include "fs.h"

/* Read a block of data */
void
ext2_read_block(SuperBlock *super, uint32_t index, char *buf)
{
	Ext2Super *rsuper = super->data;

	super->back->pos = index * (1024 << rsuper->blockSize);
	file_read(super->back, buf, 1024 << rsuper->blockSize);
}

/* Get the data block address from inode block index */
uint32_t
ext2_get_data_addr(SuperBlock *super, Ext2Inode *node, uint32_t index)
{
	uint32_t tmp;
	char block[4096];

	/* Main blocks */
	if (index < 12)
		return node->directBlock[index];
	index -= 12;
	return 0;
}