Example #1
0
block_t *block_cache_get(block_thread_state_t *block_thread_state, block_cache_t *cache, inode_cache_t *inode_cache, index_t *index, uint64_t ino, off_t off) {
	block_t *block = NULL;
#ifdef MULTITHREADED
	if (sem_wait(&cache->sem)) {
		perror("sem_wait failed");
		return NULL;
	}
	if (pthread_mutex_lock(&cache->mutex)) {
		perror("pthread_mutex_lock failed");
		goto post;
	}
#endif
	int match = 0;
	block = _block_cache_get(cache, ino, off, &match);

#ifdef MULTITHREADED
	if (pthread_mutex_unlock(&cache->mutex)) {
		perror("pthread_mutex_unlock failed");
		goto post;
	}
#endif

	if (!block) {
		fprintf(stderr, "_block_cache_get failed\n");
		goto post;
	}

	if (match) {
		return block;
	}

	const inode_t *inode = inode_cache_lookup(inode_cache, ino);
	if (!inode) {
		fprintf(stderr, "inode_cache_lookup failed\n");
		goto post;
	}

	if (block_setup(block, inode->ref, inode->ref_len)) {
		fprintf(stderr, "block_setup failed\n");
		goto post;
	}

	if (off > 0 && block_skip(block_thread_state, block, index, off) <= 0) {
		fprintf(stderr, "block_skip failed\n");
		goto post;
	}

	return block;

post:
#ifdef MULTITHREADED
	if (block) {
		_block_cache_put(cache, block, 0, 0);
	}
	if (sem_post(&cache->sem)) {
		perror("sem_post failed");
	}
#endif
	return NULL;
}
Example #2
0
// Initialize hardware devices
void
device_hardware_setup(void)
{
    usb_setup();
    ps2port_setup();
    block_setup();
    lpt_setup();
    serial_setup();
    cbfs_payload_setup();
}