Ejemplo n.º 1
0
static void ptr_validate(void * ptr, const char * syscall) {
    if (ptr && !PTR_INRANGE(ptr)) {
        debug_print(ERROR, "SEGFAULT: invalid pointer passed to %s. (0x%x < 0x%x)",
                    syscall, (uintptr_t)ptr, current_process->image.entry);
        HALT_AND_CATCH_FIRE("Segmentation fault", NULL);
    }
}
Ejemplo n.º 2
0
void ext2_set_real_block(ext2_inodetable_t *inode, uint32_t block, uint32_t real) {
	if (block < 12) {
		inode->block[block] = real;
		return;
	} else if (block < 12 + BLOCKSIZE / sizeof(uint32_t)) {
		uint8_t *tmp = malloc(BLOCKSIZE);
		ext2_disk_read_block(inode->block[12], tmp);
		((uint32_t *)tmp)[block - 12] = real;
		ext2_disk_write_block(inode->block[12], tmp);
		free(tmp);
		return;
	} else if (block < 12 + 256 + 256 * 256) {
		uint32_t a = block - 12;
		uint32_t b = a - 256;
		uint32_t c = b / 256;
		uint32_t d = b - c * 256;
		uint8_t *tmp = malloc(BLOCKSIZE);
		ext2_disk_read_block(inode->block[13], tmp);
		uint32_t nblock = ((uint32_t *)tmp)[c];
		ext2_disk_read_block(nblock, tmp);
		((uint32_t *)tmp)[d] = real;
		ext2_disk_write_block(nblock, tmp);
		free(tmp);
		return;
	} else if (block < 12 + 256 + 256 * 256 + 256 * 256 * 256) {
		uint32_t a = block - 12;
		uint32_t b = a - 256;
		uint32_t c = b - 256 * 256;
		uint32_t d = c / (256 * 256);
		uint32_t e = c - d * 256 * 256;
		uint32_t f = e / 256;
		uint32_t g = e - f * 256;
		uint8_t *tmp = malloc(BLOCKSIZE);
		ext2_disk_read_block(inode->block[14], tmp);
		uint32_t nblock = ((uint32_t *)tmp)[d];
		ext2_disk_read_block(nblock, tmp);
		nblock = ((uint32_t *)tmp)[f];
		ext2_disk_read_block(nblock, tmp);
		((uint32_t *)tmp)[g] = nblock;
		ext2_disk_write_block(nblock, tmp);
		free(tmp);
		return;
	}

	HALT_AND_CATCH_FIRE("Attempted to set a file block that was too high :(", NULL);
}
Ejemplo n.º 3
0
/**
 * Return the actual block number represented by the 'block'th block 
 * in the 'inode'.
 */
uint32_t ext2_get_real_block(ext2_inodetable_t *inode, uint32_t block) {
	if (block < 12) {
		return inode->block[block];
	} else if (block < 12 + PTRS_PER_BLOCK) {
		uint8_t *tmp = malloc(BLOCKSIZE);
		ext2_disk_read_block(inode->block[12], tmp);
		uint32_t nblock = ((uint32_t *)tmp)[block - 12];
		free(tmp);
		return nblock;
	} else if (block < 12 + PTRS_PER_BLOCK + PTRS_PER_BLOCK * PTRS_PER_BLOCK) {
		uint32_t a = block - 12;
		uint32_t b = a - PTRS_PER_BLOCK;
		uint32_t c = b / PTRS_PER_BLOCK;
		uint32_t d = b - c * PTRS_PER_BLOCK;
		uint8_t *tmp = malloc(BLOCKSIZE);
		ext2_disk_read_block(inode->block[13], tmp);
		uint32_t nblock = ((uint32_t *)tmp)[c];
		ext2_disk_read_block(nblock, tmp);
		nblock = ((uint32_t *)tmp)[d];
		free(tmp);
		return nblock;
	} else if (block < 12 + PTRS_PER_BLOCK + PTRS_PER_BLOCK * PTRS_PER_BLOCK + PTRS_PER_BLOCK * PTRS_PER_BLOCK * PTRS_PER_BLOCK) {
		uint32_t a = block - 12;
		uint32_t b = a - PTRS_PER_BLOCK;
		uint32_t c = b - PTRS_PER_BLOCK * PTRS_PER_BLOCK;
		uint32_t d = c / (PTRS_PER_BLOCK * PTRS_PER_BLOCK);
		uint32_t e = c - d * PTRS_PER_BLOCK * PTRS_PER_BLOCK;
		uint32_t f = e / PTRS_PER_BLOCK;
		uint32_t g = e - f * PTRS_PER_BLOCK;
		uint8_t *tmp = malloc(BLOCKSIZE);
		ext2_disk_read_block(inode->block[14], tmp);
		uint32_t nblock = ((uint32_t *)tmp)[d];
		ext2_disk_read_block(nblock, tmp);
		nblock = ((uint32_t *)tmp)[f];
		ext2_disk_read_block(nblock, tmp);
		nblock = ((uint32_t *)tmp)[g];
		free(tmp);
		return nblock;
	}

	HALT_AND_CATCH_FIRE("Attempted to get a file block that was too high :(", NULL);
	return 0;
}