Ejemplo n.º 1
0
void BufInit(void) {
	int i = 0;
	Buf* pBuf = (Buf*)malloc(sizeof(Buf) * MAX_BUF_NUM);
	
	for (i; i < MAX_BUF_NUM; i++) {
		(pBuf + i)->state = -1;
		(pBuf + i)->pMem = malloc(strlen("block[0000]")+1);
		BufInsertToTail(pBuf + i, BLKNO_INVALID, BUF_LIST_FREE);
	}
	Init();
	DevCreateDisk();
	DevOpenDisk();
}
Ejemplo n.º 2
0
void BufInit(void)
{
	int i = 0;
	Buf* pBuf;

	//init all list
	for( i=0; i<HASH_TBL_SIZE; i++ )
	{
		ppHashHead[i] = NULL;
		ppHashTail[i] = NULL;
	}
	for( i=0; i<3; i++ )
	{
		ppObjListHead[i] = NULL;
		ppObjListTail[i] = NULL;
	}
	pLruListHead = NULL;
	pLruListTail = NULL;

	//create buffers
	for( i=0; i<MAX_BUF_NUM; i++ )
	{
		pBuf = (Buf*)malloc(sizeof(Buf));
		pBuf->pMem = malloc(BLOCK_SIZE);
		pushFree(pBuf);
	}

	//init device
	DevCreateDisk();
	DevOpenDisk();

	//init semaphore
	semaInit();
	semaLock(SEMA_IDX_MAIN);
	semaLock(SEMA_IDX_DAEMON);

	//init daemon
	const int stack_size = 1024;
	char* stack = (char*)malloc(stack_size);
	memset(stack, 0, stack_size);
	char* stack_top = stack + stack_size;

	clone(BufDaemon, stack_top, CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_VM, 0);
}