예제 #1
0
파일: ktty.c 프로젝트: madd-games/glidix
void initTerminal()
{
	inputWrite = 0;
	inputRead = 0;
	lineBufferSize = 0;

	termState.c_iflag = ICRNL;
	termState.c_oflag = 0;
	termState.c_cflag = 0;
	termState.c_lflag = ECHO | ECHOE | ECHOK | ECHONL | ICANON | ISIG;

	semInit2(&semCount, 0);
	semInit(&semInput);
	semInit(&semLineBuffer);

	Inode *inode = vfsCreateInode(NULL, VFS_MODE_CHARDEV | 0620);
	inode->pread = termRead;
	inode->pwrite = termWrite;
	inode->ioctl = termIoctl;
	
	if (devfsAdd("tty0", inode) != 0)
	{
		panic("failed to create /dev/tty0");
	};
};
예제 #2
0
파일: mundo.c 프로젝트: maabmadb/SO
void iniciar_mundo ()
{
	int i, x, y;
	/* Criar a memória partilhada para o mundo */
	mundo = sharedInit ("shm.pesca-mundo", sizeof (Mundo));
	/* Inicializar a memória partilhada do mundo */
	mundo->estado_capitao = C_PLANEAR;
	for (x = 0; x < DIMENSAO_MAR; x++) {
		for (y = 0; y < DIMENSAO_MAR; y++) {
			mundo->mar [x][y].barco = VAZIO;
			mundo->mar [x][y].cardume = VAZIO;
		}
	}
	mundo->hora_regressar = 0;
	fifoInit (&mundo->espera_barcos);
	mundo->barcos_cais = num_barcos;
	mundo->peixes_cais = 0;
	mundo->jornadas_pesca = num_jornadas_pesca;
	
	/* Criar e inicializar os semáforos */
	
	char *nome;
	int max_digitos;
	
	/* ... semáforos dos barcos... */

	max_digitos = log (num_barcos) / log (10) + 1;
	nome = malloc (strlen ("pesca-barco") + max_digitos + 1);
	
	sem_barcos = semInit (*nome, max_digitos);

	free (nome);
	/* .. semáforos dos cardumes... */

	max_digitos = log (num_cardumes) / log (10) + 1;
	nome = malloc (strlen ("pesca-cardume") + max_digitos + 1);

	sem_cardumes = semInit (*nome, max_digitos);
	
	free (nome);

	/* .. semaforos do mutex .. */
	nome = malloc (strlen ("pesca-mutex"));

	sem_cardumes = semInit (*nome, 0);
	
	free (nome);

}
예제 #3
0
파일: tcpsock.c 프로젝트: madd-games/glidix
Socket *CreateTCPSocket()
{
	TCPSocket *tcpsock = NEW(TCPSocket);
	memset(tcpsock, 0, sizeof(TCPSocket));
	semInit(&tcpsock->lock);
	semInit2(&tcpsock->semConnected, 0);
	semInit2(&tcpsock->semAck, 0);
	semInit2(&tcpsock->semStop, 0);
	semInit2(&tcpsock->semAckOut, 0);
	semInit2(&tcpsock->semSendPut, TCP_BUFFER_SIZE);
	semInit2(&tcpsock->semSendFetch, 0);
	semInit2(&tcpsock->semRecvFetch, 0);
	semInit2(&tcpsock->semConnWaiting, 0);
	tcpsock->cntRecvPut = TCP_BUFFER_SIZE;
	Socket *sock = (Socket*) tcpsock;
	
	sock->bind = tcpsock_bind;
	sock->connect = tcpsock_connect;
	sock->close = tcpsock_close;
	sock->shutdown = tcpsock_shutdown;
	sock->packet = tcpsock_packet;
	sock->sendto = tcpsock_sendto;
	sock->recvfrom = tcpsock_recvfrom;
	sock->pollinfo = tcpsock_pollinfo;
	sock->getsockname = tcpsock_getsockname;
	sock->getpeername = tcpsock_getpeername;
	sock->listen = tcpsock_listen;
	sock->accept = tcpsock_accept;
	sock->geterr = tcpsock_geterr;
	
	return sock;
};
예제 #4
0
/* ****************************************************************************
*
* AlarmManager::init - 
*/
int AlarmManager::init(bool logAlreadyRaisedAlarms)
{
  notificationErrorLogAlways = logAlreadyRaisedAlarms;
  badInputLogAlways          = logAlreadyRaisedAlarms;
  dbErrorLogAlways           = logAlreadyRaisedAlarms;

  return semInit();
}
예제 #5
0
/* ****************************************************************************
*
* SubscriptionCache::init - 
*/
void SubscriptionCache::init(void)
{
  semInit();

  semTake();
  fillFromDb();
  semGive();
}
예제 #6
0
// init my cache
void cacheInit(proxyCache *cache){
	int i;
	for(i = 0; i < linenum; i++){
		cache->line[i].valid = 0;
		cache->line[i].block = malloc(MAX_OBJECT_SIZE);
		cache->line[i].tag = malloc(MAXLINE);	
		cache->line[i].counter = 0;
	} 
	semInit(&rlock, &wlock);	
}
예제 #7
0
// Initialize the buffer-cache in a shared memory block
buffcach *bc_ini() {
    int i, j;

    // avoid debugging file on init
    dbm = 0;

    // ensure key files existence
    close(creat(_SHMKEYPATH_BC_, 0666));
    close(creat(_SEMKEYPATH_BC_, 0666));

    // allocate buffer-cache in shared memory
    bc = (buffcach *)shmalloc(&bcshmid, _SHMKEY_BC_, _SIZE_BC_, 1);

    // initialize free list
    bc->header.freestart = 0;
    bc->header.freeend = MAXBUFF - 1;

    // initialize hash list
    for (i = 0; i < MAXHASH; i++)
        bc->header.hash[i] = -1;

    // initialize slept list
    for (i = 0; i < MAXSLPT; i++)
        bc->header.slept[i] = -1;

    // initialize buffers and link free list nodes
    for (i = 0; i < MAXBUFF; i++) {
        BS_CLR(bc->buffers[i].status, BS_LOCKED);
        BS_CLR(bc->buffers[i].status, BS_VALID);
        BS_CLR(bc->buffers[i].status, BS_DELAYED);

        if (i > 0)
            bc->buffers[i].freeprev = i - 1;

        if (i < MAXBUFF - 1)
            bc->buffers[i].freenext = i + 1;

        bc->buffers[i].hashnext = -1;

        for (j = 0; j < MAXSLPT; j++)
            bc->buffers[i].slept[j] = -1;
    }

    bc->buffers[0].freeprev = -1;
    bc->buffers[MAXBUFF - 1].freenext = -1;

    // initialize mutex semaphore
    semid = semInit(_SEMKEY_BC_, (short)1);

    // initialize files table
    ft_ini();

    // return initialized buffer-cache structure
    return bc;
}
예제 #8
0
파일: bid.c 프로젝트: rohsaini/mkunity
xkern_return_t
bid_init(
    XObj	self)
{
    Part_s	p;
    PState	*ps = (PState *)self->state;

    xTrace0(bidp, TR_GROSS_EVENTS, "bid Init");
    if ( ! (ps = pathAlloc(self->path, sizeof(PState))) ) {
	xTraceP0(self, TR_ERRORS, "allocation error");
	return XK_FAILURE;
    }
    self->state = ps;
    if ( ! xIsProtocol(xGetDown(self, BID_XPORT_I)) ) {
	xTrace0(bidp, TR_ERRORS,
		"bid could not get transport protocol -- aborting init");
	return XK_FAILURE;
    }
    if ( ! xIsProtocol(xGetDown(self, BID_CTL_I)) ) {
	xTrace0(bidp, TR_ERRORS,
		"bid could not get control protocol -- aborting init");
	return XK_FAILURE;
    }
    if ( xControl(xGetDown(self, BID_CTL_I), BIDCTL_GET_LOCAL_BID,
		  (char *)&ps->myBid, sizeof(BootId)) < (int)sizeof(BootId) ) {
	xTrace0(bidp, TR_ERRORS, "bid could not get my bid -- aborting init");
	return XK_FAILURE;
    }
#if BID_CHECK_CLUSTERID
    if ( xControl(xGetDown(self, BID_CTL_I), BIDCTL_GET_CLUSTERID,
		  (char *)&ps->myCluster, sizeof(ClusterId)) < (int)sizeof(ClusterId) ) {
	xTrace0(bidp, TR_ERRORS, "bid could not get my clusterid -- aborting init");
	return XK_FAILURE;
    }
#endif /* BID_CHECK_CLUSTERID */
    xTrace1(bidp, TR_GROSS_EVENTS, "bid using id == %x", ps->myBid);
    ps->activeMap = mapCreate(BID_ACTIVE_MAP_SIZE, sizeof(ActiveKey),
			      self->path);
    ps->passiveMap = mapCreate(BID_PASSIVE_MAP_SIZE, sizeof(PassiveKey),
			       self->path);
    if ( ! ps->activeMap || ! ps->passiveMap ) {
	xTraceP0(self, TR_ERRORS, "allocation error");
	return XK_FAILURE;
    }
    semInit(&ps->sessnCreationSem, 1);
    getProtlFuncs(self);
    partInit(&p, 1);
    partPush(p, ANY_HOST, 0);
    if ( xOpenEnable(self, self, xGetDown(self, BID_XPORT_I), &p)
							== XK_FAILURE ) {
	xTrace0(bidp, TR_ERRORS, "openEnable failed in bid init");
	return XK_FAILURE;
    }
    return XK_SUCCESS;
}
예제 #9
0
/* Exetuca as operações passadas de maneira segura, isso
 * é, se os semáforos não existirem ele são criados. */
static void semSafeOp(struct sembuf *ops, size_t nops) {
    while (semop(sem.id, ops, nops) == -1)
        switch(errno) {
            case EIDRM:
                semInit();
                break;
            default:
                /* Nunca deve acontecer. */
                puts("Unknown error.");
                exit(EXIT_FAILURE);
                break;
        }
}
예제 #10
0
/* ****************************************************************************
*
* semToString - 
*
* The real test here would be to create a few threads and play with the semaphores ... 
*
* Here I only exercise the code (which is also valid and important)
*
* This is only a wrapper function for the real semaphore function and as we're only testing
* the wrapper functions, there is no reason to do any more ...
*/
TEST(commonSem, unique)
{
   int s;

   s = semInit();
   EXPECT_EQ(0, s);

   s = reqSemGive(__FUNCTION__, "test");
   EXPECT_EQ(0, s);

   bool taken;
   s = reqSemTake(__FUNCTION__, "test", SemReadWriteOp, &taken);
   EXPECT_EQ(0, s);
   EXPECT_TRUE(taken);
}
예제 #11
0
int
tryPush( XObj self, XObj sessn, int times, int length )
{
    xkern_return_t xkr;
    int i;
    Msg_s	savedMsg, request;
    int c = 0;
    PState 	*ps = (PState *)self->state;
#if MACH_KERNEL
    tvalspec_t  time_val_before, time_val_after;
#endif /* MACH_KERNEL */
    
    xkr = msgConstructContig(&savedMsg, self->path,
				 (u_int)length,
				 TEST_STACK_SIZE);
    if (xkr == XK_FAILURE) {
	sprintf(errBuf, "Could not construct a msg of length %d\n", 
		length + TEST_STACK_SIZE);
	Kabort(errBuf);
    }
    msgConstructContig(&request, self->path, 0, 0);
    semInit(&ps->sema, 0);
    ps->flushing = FALSE;
    ps->partialcount = times - 1;
#if  MACH_KERNEL
    rtc_gettime(&ps->starttime);
    rtc_gettime(&ps->partialtime);
#else
    xGetTime(&ps->starttime);
#endif /* MACH_KERNEL */
    for (i = 0; i < ps->groupsize; i++) {
	msgAssign(&request, &savedMsg);
	xkr = xPush(sessn, &request);
	if( xkr == XK_FAILURE ) {
	    printf( "Dgram Push error %d\n" , xkr ); 
	    goto abort;
	}
    }
    evSchedule(ps->evdgram, dgram_abort, self, 30000000);
    semWait(&ps->sema);
    evCancel(ps->evdgram);
    
 abort:
    msgDestroy(&savedMsg);
    msgDestroy(&request);
    return (times - ps->partialcount);
}
예제 #12
0
파일: pipe.c 프로젝트: osstudy/glidix
int sys_pipe(int *pipefd)
{
	int rfd=-1, wfd=-1;

	FileTable *ftab = getCurrentThread()->ftab;
	spinlockAcquire(&ftab->spinlock);

	int i;
	for (i=0; i<MAX_OPEN_FILES; i++)
	{
		if (ftab->entries[i] == NULL)
		{
			if (rfd == -1)
			{
				rfd = i;
			}
			else if (wfd == -1)
			{
				wfd = i;
				break;
			};
		};
	};

	if ((rfd == -1) || (wfd == -1))
	{
		getCurrentThread()->therrno = EMFILE;
		return -1;
	};

	Pipe *pipe = (Pipe*) kmalloc(sizeof(Pipe));
	semInit(&pipe->sem);
	pipe->readcount = 0;
	pipe->writecount = 0;
	pipe->offRead = 0;
	pipe->offWrite = 0;
	pipe->size = 0;

	ftab->entries[rfd] = openPipe(pipe, O_RDONLY);
	ftab->entries[wfd] = openPipe(pipe, O_WRONLY);

	pipefd[0] = rfd;
	pipefd[1] = wfd;

	spinlockRelease(&ftab->spinlock);
	return 0;
};
예제 #13
0
int main(int argc, char const *argv[])
{
	setbuf(stdout, NULL);
	printf("%s created============\n",servername);
	/////////SemGet and Init///////////
	semid = semGet(SEMNUM);
	printf("semid: %d\n",semid);
	unsigned short arr[] = {1,0};
	semInit(semid,arr,SEMNUM);

	////////////////create famfifo///////////////
	unlink(famfifo);
	int ret = mkfifo(famfifo,0666);
	assert(ret != -1);
	ffd = open(famfifo,O_RDWR);
	assert(ffd != -1);
	////////////////////////////////////////////

	//////////Create another thread to poll clients/////////
	assert(pthread_mutex_init(&mut,NULL) == 0);
	assert(pthread_create(&tid,NULL,pollFifo,NULL) == 0);

	struct Request req;
	int i;

	while(1)
	{
		semWait(semid,1);
		read(ffd,&req,REQSIZE);
		printf("Request received from: %d\n",req.pid);
		genearteFifo(req.pid);
		cfd[numclients][INSTREAM] = ifd;
		cfd[numclients][OUTSTREAM]  = ofd;
		pfd[numclients].fd = ifd;
		pfd[numclients].events = POLLIN;
		pfd[numclients].revents = 0;
		////////Use MUTEX to CHANGE tHIS exclusively///////////
		pthread_mutex_lock(&mut);
		numclients++;
		printf("numclients %d\n",numclients);
		pthread_mutex_unlock(&mut);
		//////////////////////////////////////
		semSignal(semid,1);
	}

	return 0;
}
예제 #14
0
/* ****************************************************************************
*
* orionInit - 
*/
void orionInit
(
  OrionExitFunction  exitFunction,
  const char*        version,
  SemOpType          reqPolicy,
  bool               _countersStatistics,
  bool               _semWaitStatistics,
  bool               _timingStatistics,
  bool               _notifQueueStatistics,
  bool               _checkIdv1
)
{
  // Give the rest library the correct version string of this executable
  versionSet(version);

  // The function to call on fatal error
  orionExitFunction = exitFunction;

  // Initialize the semaphore used by mongoBackend
  semInit(reqPolicy, _semWaitStatistics);

  // Set timer object (singleton)
  setTimer(new Timer());

  // startTime for log library
  if (gettimeofday(&logStartTime, NULL) != 0)
  {
    fprintf(stderr, "gettimeofday: %s\n", strerror(errno));
    orionExitFunction(1, "gettimeofday error");
  }

  // Set start time and statisticsTime used by REST interface
  startTime      = logStartTime.tv_sec;
  statisticsTime = startTime;

  // Set other flags related with statistics
  countersStatistics   = _countersStatistics;
  timingStatistics     = _timingStatistics;
  notifQueueStatistics = _notifQueueStatistics;

  strncpy(transactionId, "N/A", sizeof(transactionId));

  checkIdv1 = _checkIdv1;
}
예제 #15
0
파일: threading.cpp 프로젝트: stxent/yaf
//------------------------------------------------------------------------------
ThreadSwarm::ThreadSwarm(Shell &parent) :
    ShellCommand(parent)
{
  result res;

  res = mutexInit(&queueLock);

  if (res == E_OK)
    res = semInit(&queueSynchronizer, THREAD_COUNT);

  if (res != E_OK)
  {
    owner.log("swarm: initialization error");
    exit(EXIT_FAILURE);
  }

  for (unsigned int i = 0; i < THREAD_COUNT; ++i)
  {
    WorkerThread *thread = new WorkerThread(*this);
    thread->start();
    pool.push(thread);
  }
}
예제 #16
0
파일: appli.c 프로젝트: Aldream/PLD-SR
int main()
{
	/*
	 * Create two threads
	 */
	/*
	createGThread("numbers", numbers, NULL, STACK_SIZE);
	createGThread("letters", letters, NULL, STACK_SIZE);
	createGThread("others", others, NULL, STACK_SIZE);
	createGThread("stuff", stuff, NULL, STACK_SIZE);
	createGThread("inifi", infiniteCoucou, NULL, STACK_SIZE);
	*/
	
	createGThread("lol", infiniteLol, NULL, STACK_SIZE);
	createGThread("truc", infiniteTruc, NULL, STACK_SIZE);
	createGThread("coucou", infiniteCoucou, NULL, STACK_SIZE);
	
	/*createGThread("others", others, NULL, STACK_SIZE);*/
		
	/* To be sure they are all well created */
	listThreads();
	
	sem = malloc(sizeof(semaphore));
	semInit(sem,0);
	
	/* Scheduler call */
	startSched();
	
	/*
	killGThread(numbersId);
	killGThread(lettersId);
	*/
	
	printf("Exit application\n");
	return 0;
}
예제 #17
0
파일: threading.cpp 프로젝트: stxent/yaf
//------------------------------------------------------------------------------
WorkerThread::WorkerThread(ThreadSwarm &parent) :
    owner(parent),
    finalize(false),
    baseContext(nullptr),
    argumentCount(0), firstArgument(nullptr)
{
  result res;

  res = semInit(&semaphore, 0);

  if (res == E_OK)
  {
    res = threadInit(&thread, THREAD_SIZE, THREAD_PRIORITY,
        workerThreadWrapper, this);
  }

  if (res != E_OK)
  {
    parent.owner.log("swarm: thread initialization error");
    exit(EXIT_FAILURE);
  }

  threadOnTerminateCallback(&thread, workerTerminateWrapper, this);
}
예제 #18
0
파일: nimrod.c 프로젝트: ddlsmurf/Nimrod
N_CDECL(void, NimMain)(void) {
  nim__datInit();
  systemInit();
parseutilsInit();
strutilsInit();
timesInit();
posixInit();
osInit();
listsInit();
nhashesInit();
nstrtabsInit();
optionsInit();
msgsInit();
nversionInit();
crcInit();
platformInit();
ropesInit();
identsInit();
astInit();
rodutilsInit();
astalgoInit();
condsymsInit();
hashesInit();
strtabsInit();
streamsInit();
osprocInit();
extccompInit();
wordrecgInit();
commandsInit();
llstreamInit();
lexbaseInit();
scannerInit();
nimconfInit();
pnimsynInit();
pbracesInit();
rnimsynInit();
filtersInit();
ptmplsynInit();
syntaxesInit();
rodreadInit();
treesInit();
typesInit();
mathInit();
magicsysInit();
bitsetsInit();
nimsetsInit();
passesInit();
treetabInit();
semdataInit();
lookupsInit();
importerInit();
rodwriteInit();
semfoldInit();
evalsInit();
procfindInit();
pragmasInit();
suggestInit();
semInit();
rstInit();
highliteInit();
docgenInit();
ccgutilsInit();
cgmethInit();
cgenInit();
ecmasgenInit();
interactInit();
passauxInit();
dependsInit();
transfInit();
mainInit();
parseoptInit();
nimrodInit();
}
예제 #19
0
파일: futexbm.c 프로젝트: bochf/testing
int main(int argc, char *argv[])
{
	/* int		err;  <------ Unused. Commenting out */
	int		N;                 //number of cycles
	int		ping_cpu=0;          //cpu number to pin the ping process
	int		pong_cpu=1;          //cpu number to pin the pong process 
	int		pingbusy = 0;
	int		pongbusy = 0;
   int     ncpus=0;

   struct optbase *ob;

 
   if(NULL == (ob = ReadOptions(argc, argv)))
      return(1);


   ncpus=sysconf( _SC_NPROCESSORS_ONLN );


   if ( ncpus > 2) {

      VerboseMessage ("number of cpu on the box %d\n",ncpus);
   } 
   else{

      ErrorMessage ("Not enough cpus to run the test\n");

      return -1;
   }
   

   /* 
      The cpu_set_t data structure represents a set of CPUs.  CPU sets are
      
      used by sched_setaffinity(2) and similar interfaces.
      cpu_set_t data type is implemented as a bitset. 
      
      mask should have only the total number of max cpu
   */

	cpu_set_t	mask[128];

   /* 
      inizialize mask with all 0
   */
	memset(mask, 0, sizeof(mask));

   /* 
      work the test options
      it must be update
   */


      int min_cpu=0;
      int max_cpu=ncpus-1;
      int busy=1;
      int nobusy=0;

      GetOptionValue(ob, "PING_CPU", GOV_INT16, &ping_cpu, &min_cpu, &max_cpu, NULL);
      GetOptionValue(ob, "PONG_CPU", GOV_INT16, &pong_cpu, &min_cpu, &max_cpu, NULL);
      GetOptionValue(ob, "N", GOV_INT16, &N, NULL, NULL, NULL);
      GetOptionValue(ob, "PING_BUSY", GOV_INT16, &pingbusy,&nobusy,&busy,NULL);
      GetOptionValue(ob, "PONG_BUSY", GOV_INT16, &pongbusy,&nobusy,&busy,NULL); 
      EvalOptions(ob);


if (1<0){
	if(argc < 4) {
		usage(argv[0]);
		return -1;
	}

	ping_cpu = atoi(argv[1]);
	pong_cpu = atoi(argv[2]);
	N = atoi(argv[3]);

	if(argc > 4) {
		if(strcmp(argv[4], "pongbusy") == 0)
			pongbusy = 1;
		else
		if(strcmp(argv[4], "pingbusy") == 0)
			pingbusy = 1;
	}

	if(argc > 5) {
		if(strcmp(argv[5], "pongbusy") == 0)
			pongbusy = 1;
		else
		if(strcmp(argv[5], "pingbusy") == 0)
			pingbusy = 1;
	}
}





/*
Let's create sem_open the two semaphore
oflag is O_CREATE, mode is 
mode is 0600 S_IRUSR | S_IWUSR from umask
*/



	semInit(&g_semPing, g_pingName);
	semInit(&g_semPong, g_pongName);



	if(fork() == 0) {
          /* child
           CPU_SET Add CPU cpu to set. 
         */
        VerboseMessage("run child\n");
		CPU_SET(pong_cpu, mask);
		sched_setaffinity(0, 128, mask); // If pid is zero, then the calling process is used.
	
        
    	if(pongbusy)
			pong_busy(N);
		else
			pong(N);
		TRY(sem_close(g_semPong), -1);
		TRY(sem_unlink(g_pongName), -1);
      VerboseMessage ("wrap child\n");
	  } else {
		/* parent */
		time_type start, finish;
		/* time_type start_one, finish_one; <---- Unused. Commenting out */
      VerboseMessage ("run parent\n");
		CPU_SET(ping_cpu, mask);
		sched_setaffinity(0, 128, mask);

		getTime(&start);
		if(pingbusy)
			ping_busy(N);
		else
			ping(N);
        VerboseMessage("wrapping parent\n");
		getTime(&finish);

		const long int elapsed = timeDiff(&start, &finish);

		printf("avg RTT = %.1f nsec.\n", (elapsed * 1.0) / N);
		TRY(sem_close(g_semPing), -1);
		TRY(sem_unlink(g_pingName), -1);

	}

	return 0;
}
예제 #20
0
파일: fsdriver.c 프로젝트: osstudy/glidix
void initFSDrivers()
{
	firstDriver = NULL;
	semInit(&semFS);
};
예제 #21
0
파일: main.c 프로젝트: osstudy/glidix
static int isoMount(const char *image, FileSystem *fs, size_t szfs)
{
	spinlockAcquire(&isoMountLock);

	int error;
	File *fp = vfsOpen(image, 0, &error);
	if (fp == NULL)
	{
		spinlockRelease(&isoMountLock);
		kprintf_debug("isofs: could not open %s\n", image);
		return -1;
	};

	if (fp->seek == NULL)
	{
		spinlockRelease(&isoMountLock);
		kprintf_debug("isofs: %s cannot seek\n", image);
		vfsClose(fp);
		return -1;
	};

	fp->seek(fp, 0x8000, SEEK_SET);
	ISOPrimaryVolumeDescriptor primary;
	if (vfsRead(fp, &primary, sizeof(ISOPrimaryVolumeDescriptor)) != sizeof(ISOPrimaryVolumeDescriptor))
	{
		spinlockRelease(&isoMountLock);
		kprintf_debug("isofs: cannot read the whole ISOPrimaryVolumeDescriptor (EOF)\n");
		vfsClose(fp);
		return -1;
	};

	if (!checkPVD(&primary))
	{
		spinlockRelease(&isoMountLock);
		kprintf_debug("isofs: the Primary Volume Descriptor is invalid\n");
		vfsClose(fp);
		return -1;
	};

	kprintf_debug("isofs: PVD validated\n");

	ISOFileSystem *isofs = (ISOFileSystem*) kmalloc(sizeof(ISOFileSystem));
	isofs->fp = fp;
	semInit(&isofs->sem);

	ISODirentHeader *rootDir = (ISODirentHeader*) &primary.rootDir;
	isofs->rootStart = (uint64_t)rootDir->startLBA * (uint64_t)primary.blockSize;
	isofs->rootEnd = isofs->rootStart + (uint64_t)rootDir->fileSize;
	isofs->blockSize = (uint64_t)primary.blockSize;
	isofs->numOpenInodes = 0;

	kprintf_debug("isofs: root directory start LBA is %a, block size is %d\n", rootDir->startLBA, primary.blockSize);

	fs->fsdata = isofs;
	fs->fsname = "isofs";
	fs->openroot = iso_openroot;
	fs->unmount = iso_unmount;

	isoMountCount++;
	spinlockRelease(&isoMountLock);
	return 0;
};
예제 #22
0
void PreMain() {
	systemDatInit();
	systemInit();
	testabilityDatInit();
	stdlibparseutilsDatInit();
	stdlibstrutilsDatInit();
	stdlibtimesDatInit();
	stdlibposixDatInit();
	stdlibosDatInit();
	listsDatInit();
	stdlibhashesDatInit();
	stdlibstrtabsDatInit();
	stdlibstreamsDatInit();
	stdlibosprocDatInit();
	stdlibmathDatInit();
	stdlibsetsDatInit();
	optionsDatInit();
	stdlibtablesDatInit();
	platformDatInit();
	crcDatInit();
	ropesDatInit();
	stdlibunsignedDatInit();
	stdlibsocketsDatInit();
	msgsDatInit();
	nversionDatInit();
	identsDatInit();
	condsymsDatInit();
	extccompDatInit();
	wordrecgDatInit();
	babelcmdDatInit();
	commandsDatInit();
	llstreamDatInit();
	nimlexbaseDatInit();
	lexerDatInit();
	nimconfDatInit();
	stdlibintsetsDatInit();
	idgenDatInit();
	astDatInit();
	rodutilsDatInit();
	astalgoDatInit();
	parserDatInit();
	pbracesDatInit();
	rendererDatInit();
	filtersDatInit();
	filter_tmplDatInit();
	syntaxesDatInit();
	treesDatInit();
	typesDatInit();
	stdlibmemfilesDatInit();
	rodreadDatInit();
	magicsysDatInit();
	bitsetsDatInit();
	nimsetsDatInit();
	passesDatInit();
	treetabDatInit();
	vmdefDatInit();
	semdataDatInit();
	lookupsDatInit();
	importerDatInit();
	rodwriteDatInit();
	saturateDatInit();
	semfoldDatInit();
	procfindDatInit();
	pragmasDatInit();
	semtypinstDatInit();
	parampatternsDatInit();
	stdliblexbaseDatInit();
	stdlibunicodeDatInit();
	stdlibjsonDatInit();
	docutilsrstastDatInit();
	docutilsrstDatInit();
	docutilshighliteDatInit();
	docutilsrstgenDatInit();
	guardsDatInit();
	sempass2DatInit();
	stdlibmacrosDatInit();
	stdlibxmltreeDatInit();
	stdlibcookiesDatInit();
	stdlibcgiDatInit();
	typesrendererDatInit();
	docgenDatInit();
	stdlibalgorithmDatInit();
	stdlibsequtilsDatInit();
	prettyDatInit();
	sigmatchDatInit();
	cgmethDatInit();
	loweringsDatInit();
	lambdaliftingDatInit();
	transfDatInit();
	vmgenDatInit();
	vmdepsDatInit();
	evaltemplDatInit();
	vmDatInit();
	aliasesDatInit();
	patternsDatInit();
	semmacrosanityDatInit();
	semDatInit();
	ccgutilsDatInit();
	cgendataDatInit();
	ccgmergeDatInit();
	cgenDatInit();
	jsgenDatInit();
	passauxDatInit();
	dependsDatInit();
	docgen2DatInit();
	stdlibparseoptDatInit();
	serviceDatInit();
	modulesDatInit();
	mainDatInit();
	nimrodDatInit();
	initStackBottom();
	testabilityInit();
	stdlibparseutilsInit();
	stdlibstrutilsInit();
	stdlibtimesInit();
	stdlibposixInit();
	stdlibosInit();
	listsInit();
	stdlibhashesInit();
	stdlibstrtabsInit();
	stdlibstreamsInit();
	stdlibosprocInit();
	stdlibmathInit();
	stdlibsetsInit();
	optionsInit();
	stdlibtablesInit();
	platformInit();
	crcInit();
	ropesInit();
	stdlibunsignedInit();
	stdlibsocketsInit();
	msgsInit();
	nversionInit();
	identsInit();
	condsymsInit();
	extccompInit();
	wordrecgInit();
	babelcmdInit();
	commandsInit();
	llstreamInit();
	nimlexbaseInit();
	lexerInit();
	nimconfInit();
	stdlibintsetsInit();
	idgenInit();
	astInit();
	rodutilsInit();
	astalgoInit();
	parserInit();
	pbracesInit();
	rendererInit();
	filtersInit();
	filter_tmplInit();
	syntaxesInit();
	treesInit();
	typesInit();
	stdlibmemfilesInit();
	rodreadInit();
	magicsysInit();
	bitsetsInit();
	nimsetsInit();
	passesInit();
	treetabInit();
	vmdefInit();
	semdataInit();
	lookupsInit();
	importerInit();
	rodwriteInit();
	saturateInit();
	semfoldInit();
	procfindInit();
	pragmasInit();
	semtypinstInit();
	parampatternsInit();
	stdliblexbaseInit();
	stdlibunicodeInit();
	stdlibjsonInit();
	docutilsrstastInit();
	docutilsrstInit();
	docutilshighliteInit();
	docutilsrstgenInit();
	guardsInit();
	sempass2Init();
	stdlibmacrosInit();
	stdlibxmltreeInit();
	stdlibcookiesInit();
	stdlibcgiInit();
	typesrendererInit();
	docgenInit();
	stdlibalgorithmInit();
	stdlibsequtilsInit();
	prettyInit();
	sigmatchInit();
	cgmethInit();
	loweringsInit();
	lambdaliftingInit();
	transfInit();
	vmgenInit();
	vmdepsInit();
	evaltemplInit();
	vmInit();
	aliasesInit();
	patternsInit();
	semmacrosanityInit();
	semInit();
	ccgutilsInit();
	cgendataInit();
	ccgmergeInit();
	cgenInit();
	jsgenInit();
	passauxInit();
	dependsInit();
	docgen2Init();
	stdlibparseoptInit();
	serviceInit();
	modulesInit();
	mainInit();
}
예제 #23
0
파일: pipe.c 프로젝트: racing19th/LN-DOS
int sysPipe(int fd[2], int flags) {
	int error = validateUserPointer(fd, sizeof(*fd) * 2);
	if (error) return error;
	int readFD;
	int writeFD;

	struct Process *proc = getCurrentThread()->process;
	acquireSpinlock(&proc->fdLock);

	struct ProcessFile *rf;
	readFD = allocateFD(proc, &rf);
	if (readFD < 0) {
		error = readFD;
		releaseSpinlock(&proc->fdLock);
		goto release;
	}
	struct ProcessFile *wf;
	writeFD = allocateFD(proc, &wf);
	if (writeFD < 0) {
		error = readFD;
		releaseSpinlock(&proc->fdLock);
		goto deallocReadFD;
	}

	void *buf = allocKPages(PIPE_BUF, PAGE_FLAG_WRITE);
	if (!buf) {
		error = -ENOMEM;
		releaseSpinlock(&proc->fdLock);
		goto deallocWriteFD;
	}

	struct Pipe *pipe = kmalloc(sizeof(*pipe));
	if (!pipe) {
		error = -ENOMEM;
		releaseSpinlock(&proc->fdLock);
		goto deallocBuf;
	}
	memset(pipe, 0, sizeof(*pipe));
	pipe->buf = buf;
	pipe->refCount = 2;
	semInit(&pipe->bytesFree, PIPE_BUF);
	semInit(&pipe->bytesUsed, 0);

	if (flags & SYSOPEN_FLAG_CLOEXEC) {
		rf->flags |= PROCFILE_FLAG_CLOEXEC;
	}
	rf->flags |= PROCFILE_FLAG_PIPE;
	wf->flags = rf->flags | PROCFILE_FLAG_PIPE_WRITE;
	rf->pipe = pipe;
	wf->pipe = pipe;

	fd[0] = readFD;
	fd[1] = writeFD;

	goto release;

	deallocBuf:
	deallocPages(buf, PIPE_BUF);
	deallocWriteFD:
	sysClose(writeFD);
	deallocReadFD:
	sysClose(readFD);
	return error;

	release:
	releaseSpinlock(&proc->fdLock);
	return error;
}