Ejemplo n.º 1
0
	list <int> Poller::WaitForData (int timeOut) const
	{
		vector <pollfd> pfd (FileDescriptors.size());
		for (size_t i = 0; i < FileDescriptors.size(); i++)
		{
			pfd[i].fd = FileDescriptors[i];
			pfd[i].events = POLLIN;
		}

		list <int> descList;

		int pollRes = poll (&pfd[0], pfd.size(), timeOut);

		if (pollRes == 0 && timeOut != -1)
			throw TimeOut (SRC_POS);

		if (pollRes > 0)
		{
			for (size_t i = 0; i < pfd.size(); i++)
			{
				if (pfd[i].revents & POLLIN)
					descList.push_back (pfd[i].fd);
			}
		}

		return descList;
	}
Ejemplo n.º 2
0
int read_pipe()
{
	char fds[32], buf[1024], bytes[32];
	int fd, n, nbytes;
	pfd();

	printf("enter fd: ");
	gets(fds);

	printf("enter nbytes: ");
	gets(bytes);

	fd = atoi(fds);
	nbytes = atoi(bytes);

	printf("fd=%d nbytes=%d : %s\n", fd, nbytes, buf);

	n = syscall(31, fd, buf, nbytes);

	if(n >= 0)
	{
		printf("proc %d back to Umode, read %d bytes from pipe : ", getpid(), n);
		buf[n] = 0;
		printf("%s\n", buf);
	}
	else
		printf("read pipe failed\n");
}
Ejemplo n.º 3
0
bool IsInsideRootDir(TCHAR* profiledir, bool exact)
{
	VARST pfd( _T("%miranda_path%"));
	if (exact)
		return _tcsicmp(profiledir, pfd) == 0;

	return _tcsnicmp(profiledir, pfd, _tcslen(pfd)) == 0;
}
Ejemplo n.º 4
0
main(int argc, char *argv[])
{ 
    int pid, cmd, i;
    char name[64];
    ucolor = 0;
    clearScreen(UMODE);
    printf("enter main() : argc = %d\n", argc);
    for (i=0; i<argc; i++)
        printf("argv[%d] = %s\n", i, argv[i]);

    while(1){
        pid = getpid();
        color = ucolor ? ucolor:0x000B + (pid % 5);// avoid black on black baground
        cmd?resetCursor(UMODE):1;
        printf("----------------------------------------------\n");
        printf("I am proc %din U mode: segment=%x\n", pid, (pid+1)*0x1000);
        show_menu();
        printf("Command ? ");
        getCurPos(UMODE);
        printf("                                                                      \n");
        setCurPos(ux_col,uy_row,UMODE);
        gets(name);
        clearScreenRegion(K_X_PRINT_OFFSET,80,U_Y_PRINT_OFFSET-1,24,UMODE);
        if (name[0]==0) 
            continue;

        cmd = find_cmd(name);
        
        getCurPos(UMODE);
        setCurPos(K_X_PRINT_OFFSET,U_Y_PRINT_OFFSET,UMODE);
        switch(cmd){
            case 0 : do_getpid();   break;
            case 1 : ps();          break;
            case 2 : chname();      break;
            case 3 : kmode();       break;
            case 4 : kswitch();     break;
            case 5 : wait();        break;
            case 6 : exit();        break;
            case 7 : fork();        break;
            case 8 : exec();        break;
            case 9 : ucolor = chcolor();     break;

            case 10: pipe();        break;
            case 11: pfd();         break;
            case 12: read_pipe();   break;
            case 13: write_pipe();  break;
            case 14: close_pipe();  break;
            
            default: invalid(name); break;
        }
        setCurPos(ux_col,uy_row,UMODE);
    }
}
Ejemplo n.º 5
0
int main()
{
    pfd(2.0);
    CHECK_GOOD(3);
    pfi(2);
    CHECK_GOOD(3+4);
    rfi(2);
    CHECK_GOOD(3+4+4);
    rfd(2.0);
    CHECK_GOOD(3+4+4+3);
    return errors != 0;

}
Ejemplo n.º 6
0
int main(int argc, char *argv[]) { 
	char name[64];
	int pid, cmd;
	int pd[2];

	while(1){

		printf("\n----------------------------------------------\n");
		#ifndef _LAB_3_
			printf("I am proc %d in U mode with ppid %d: running segment=%x\n",getpid(), getppid(), getcs());
		#else
			printf("I am proc "); getpid(); printf(" in U mode: running segment=%x\n", getcs());
		#endif

		#ifdef _SLEEPER_
			while(1) {
				printf("PID: %d PPID: %d\n", getpid(), getppid());
				sleep(5);
				return 0;
			}
		#endif

		show_menu();
		printf("Command? ");
		gets(name);
		printf("\n"); 
		if (name[0]==0) 
		continue;

		cmd = find_cmd(name);
		switch(cmd){
			case 0:		getpid();	break;
			case 1:		ps();		break;
			case 2:		chname();	break;
			case 3:		kswitch();	break;
			case 4:		wait();		break;
			case 5:		ufork();	break;
			case 6:		uexec();	break;
			case 7: 	exit();		break;
			case 8: 	pipe(pd);	break;
			case 9: 	pfd();		break;
			case 10:	uclose();	break;
			case 11:	uread();	break;
			case 12:	uwrite();	break;
			case 13:	usleep();	break;
			default:invalid(name);break;
		}
	}
}
Ejemplo n.º 7
0
Archivo: int.c Proyecto: Cj-muse/Lab6
int kcinth()
{
   u16    segment, offset;
   int    a,b,c,d, r;

   segment = running->uss;
   offset = running->usp;

   a = get_word(segment, offset + 2*PA);
   b = get_word(segment, offset + 2*PB);
   c = get_word(segment, offset + 2*PC);
   d = get_word(segment, offset + 2*PD);
		
 	/*printf("interupthandler a = %d\n", a);
	printf("b = %d\n",     b);
	printf("string: %s\n", c);
	printf("n = %d\n",     d);*/
   switch(a){
       case 0 : r = running->pid;     break;
       case 1 : r = do_ps();          break;
       case 2 : r = kchname(b);        break;
       case 3 : r = kmode();          break;
       case 4 : r = tswitch();        break;
       case 5 : r = do_wait(b);       break;
       case 6 : r = do_exit(b);       break;
       case 7 : r = fork();           break;
       case 8 : r = exec(b);          break;

   /****** these are YOUR pipe functions ************/
   case 30 : r = kpipe(b); break;
   case 31 : r = read_pipe(b,c,d);  break;
   case 32 : r = write_pipe(b,c,d); break;
   case 33 : r = close_pipe(b);     break;
   case 34 : r = pfd();             break;
  /**************** end of pipe functions ***********/

       case 90: r =  getc();          break;
       case 91: color=running->pid+11;
                r =  putc(b);         break;
       case 99: do_exit(b);           break;
       default: printf("invalid syscall # : %d\n", a);
   }
   //printf("interupthandler r = %d\n", r);
   //getc();
   put_word(r, segment, offset + 2*AX);
}
Ejemplo n.º 8
0
int kcinth()
{
   u16    segment, offset;
   int    a,b,c,d, r;

   segment = running->uss; 
   offset = running->usp;

   a = get_word(segment, offset + 2*PA);
   b = get_word(segment, offset + 2*PB);
   c = get_word(segment, offset + 2*PC);
   d = get_word(segment, offset + 2*PD);

   switch(a){
       case 0 : r = running->pid;     break;
       case 1 : r = do_ps();          break;
       case 2 : r = chname(b);        break;
       case 3 : r = kmode();          break;
       case 4 : r = tswitch();        break;
       case 5 : r = do_wait(b);       break;
       case 6 : r = do_exit(b);       break;
        
       case 7 : r = fork();           break;
       case 8 : r = exec(b);          break;

       case 9 : r = vfork();          break;


   case 30 : r = kpipe(b); break;
   case 31 : r = read_pipe(b,c,d);  break;
   case 32 : r = write_pipe(b,c,d); break;
   case 33 : r = close_pipe(b);     break;
   case 34 : r = pfd();             break;

       case 90: r =  getc();          break;
       case 91: color=running->pid+11;
                r =  putc(b);         break;       
       case 99: do_exit(b);           break;
       default: printf("invalid syscall # : %d\n", a); 
   }
   put_word(r, segment, offset + 2*AX);
}
Ejemplo n.º 9
0
Archivo: u2.c Proyecto: shank8/CS460
main()
{ 
  char name[64]; int pid, cmd;
  pid = getpid();

  while(1){
       color = 0x0000B + pid;

       printf("==============================================\n");
       printf("\nIch bin Prozess %d in der U Weise: das laufen im Segment=%x\n",
                getpid(), getcs());
       
       show_menu();
       printf("Command ? ");
       gets(name); 
       if (name[0]==0) 
           continue;

       cmd = find_cmd(name);
       printf("find_cmd = %d\n", cmd);
       switch(cmd){
            case 0 : getpid();   break;
           case 1 : ps();       break;
           case 2 : chname();   break;
           case 3 : kmode();    break;
           case 4 : kswitch();  break;
           case 5 : wait();     break;
           case 6 : exit();     break;
           case 7 : fork();     break;
           case 8 : exec();     break;
         
           case 9 : pipe();    break;
           case 10: pfd();       break;
          
           case 11 : read_pipe(); break;
           case 12 : write_pipe();break;
            case 13: close();     break;
           default: invalid(name); break;
       } 

  }
}
Ejemplo n.º 10
0
Archivo: u1.c Proyecto: shank8/CS460
main()
{ 
  char name[64]; int pid, cmd;

  while(1){
    pid = getpid();
    color = 0x000B + (pid % 6);
       
    printf("----------------------------------------------\n");
    printf("I am proc %d in U mode: running segment=%x\n",getpid(), getcs());
    show_menu();
    printf("Command ? ");
    gets(name); 
    if (name[0]==0) 
        continue;

    cmd = find_cmd(name);
      printf("find_cmd = %d\n", cmd);
    /*char *cmd[]={"getpid", "ps", "chname", "kmode", "switch", "wait", "exit", 
             "fork", "exec", "pipe", "pfd", "read", "write", "close", 0};*/
    switch(cmd){
           case 0 : getpid();   break;
           case 1 : ps();       break;
           case 2 : chname();   break;
           case 3 : kmode();    break;
           case 4 : kswitch();  break;
           case 5 : wait();     break;
           case 6 : exit();     break;
           case 7 : fork();     break;
           case 8 : exec();     break;
         
           case 9 : pipe();    break;
           case 10: pfd();       break;
          
           case 11 : read_pipe(); break;
           case 12 : write_pipe();break;
            case 13: close_pipe();     break;
           default: invalid(name); break;
    }
  }
}
Ejemplo n.º 11
0
Archivo: u1.c Proyecto: B-Rich/CptS460
main()
{ 
  char name[64]; int pid, cmd, segment, i;
  pid = getpid();
  color = 0x000B + (pid % 5);  // avoid black on black baground
 
  while(1){
       pid = getpid();
       color = 0x000B + (pid % 5);
       segment = (pid+1)*0x1000;   
       printf("==============================================\n");
       printf("I am proc %din U mode: segment=%x\n", pid, segment);
       show_menu();
       printf("Command ? ");
       gets(name); 
       if (name[0]==0) 
           continue;

       cmd = find_cmd(name);

       switch(cmd){
           case 0 : getpid();   break;
           case 1 : ps();       break;
           case 2 : chname();   break;
           case 3 : kmode();    break;
           case 4 : kswitch();  break;
           case 5 : wait();     break;
           case 6 : exit();     break;
           case 7 : fork();     break;
           case 8 : exec();     break;

       case 9:  pipe(); break;
       case 10: pfd();  break;
       case 11: read_pipe(); break;
       case 12: write_pipe(); break;
       case 13: close_pipe(); break;

           default: invalid(name); break;
       } 
  }
}
Ejemplo n.º 12
0
Archivo: int.c Proyecto: konorati/cs460
/****************** syscall handler in C ***************************/
int kcinth()
{
   int a,b,c,d, r;

    //WRITE CODE TO GET get syscall parameters a,b,c,d from ustack 
    a = get_word(running->uss, running->usp + 26);
    b = get_word(running->uss, running->usp + 28);
    c = get_word(running->uss, running->usp + 30);
    d = get_word(running->uss, running->usp + 32);

   switch(a){
       case 0 : r = kgetpid();        break;
       case 1 : r = kps();            break;
       case 2 : r = kchname(b);       break;
       case 3 : r = kmode();         break;
       case 4 : r = tswitch();       break;
       case 5 : r = kkwait(b);        break;
       case 6 : r = kkexit(b);        break;
       case 7 : r = fork();           break;
       case 8 : r = kexec(b);         break;

       case 30: r = kpipe(b);         break;
       case 31: r = read_pipe(b,c,d); break;
       case 32: r = write_pipe(b,c,d);break;
       case 33: r = close_pipe(b);    break;
       case 34: r = pfd();            break;

       case 90: r = getc();           break;
       case 91: r = putc(b);          break;
       case 99: kkexit(b);            break;
       default: printf("invalid syscall # : %d\n", a); 
   }

    //WRITE CODE to let r be the return value to Umode
    put_word(r, running->uss, running->usp + 16);
    return r;

}
Ejemplo n.º 13
0
int write_pipe()
{
	char fds[16], buf[1024];
	int fd, n, nbytes;
	pfd();

	printf("enter fd: ");
	gets(fds);

	printf("enter text: ");
	gets(buf);

	fd = atoi(fds);
	nbytes = strlen(buf);

	printf("fd=%d nbytes=%d : %s\n", fd, nbytes, buf);

	n = syscall(32, fd, buf, nbytes);

	if(n >= 0)
		printf("\nproc %d back to Umodde, wrote %d bytes to pipe\n", getpid(), n);
	else
		printf("write pipe failed\n");
}
Ejemplo n.º 14
0
lasErr FUNCTION c_eopens(struct FDESC **fdesc,char *fname,int bands[],
	int *sl,int *ss,int *nl,int *ns,int offset[],
	int *acc,int *dtype,int *nbuf,int opt[])
{
struct DDR ddr;
register struct FDESC *fd;

int dflag;
int filesize;
int i;				/* counter -- current band		*/
int nbands;
int stati;
/*int linsiz;*/

char errtxt[ERRLEN];
/*char system[DDSYLN];*/

*fdesc = (struct FDESC *)calloc(1,sizeof(struct FDESC));
if (*fdesc == NULL)
   {
   c_errmsg("Error allocating dynamic memory","eopens-alloc",NON_FATAL);
   return(E_FAIL);
   }
fd = *fdesc;	/* used to simplify expressions */
fd->nl = fd->img_nl = *nl;
fd->ns = fd->img_ns = *ns;
fd->sl = *sl;
fd->ss = *ss;
fd->offset = offset;
fd->acc = *acc;
fd->method = STEP;
fd->dtype = *dtype;
fd->nbuf = *nbuf;
fd->linsiz = (*ns * datasize[*dtype] + 511) & ~0x1ff;
(void)strcpy(fd->fname, fname);
fd->flags = 0; /* clear flags */
fd->cnvlsz = 0; /* set conversion line size 0 */ 

if ((fd->acc == IREAD) || (fd->acc == IUPDATE))
	{	
		
/*  Compare the system that the data is stored on and the system that will
    process the data.
--------------------------------------------------------------------------*/
	c_getddr(fname, &ddr);
	if ((dflag == 3) || 
            ((dflag == 1) && (ddr.dtype == EREAL)) ||
	    ((dflag == 2) && (ddr.dtype != EBYTE)))
	   {
	   c_errmsg("Data type of image is not compatible with the processor",
	      "eopens-dtype",NON_FATAL);
	   return(E_FAIL);
	   }

	
        /*linsiz = (ddr.ns * datasize[ddr.dtype] + 511) & ~0x1ff;*/

	/* if a zero was specified for bands all the bands are specified
        ----------------------------------------------------------------*/
	nbands = 0;
        if (bands[0] == 0)
	   {
           for (i = 1; i <= ddr.nbands; i++)
              {
              fd->bands[nbands] = i;
              nbands++;
    	      }
	   }
        else
	   {
	   while (bands[nbands] != 0)
	      {
	      if (bands[nbands] > ddr.nbands)
	         {
	         sprintf(errtxt,"More bands specified than exist for %s",
	                 fd->fname);
	         c_errmsg(errtxt,"eopens-nbands",NON_FATAL);
	         return(E_FAIL);
	         }
	      fd->bands[nbands] = bands[nbands];
	      nbands++;
	      }
	   }
        
	fd->nbands = nbands;

	stati = do_open(fd);	
	if (stati != E_SUCC)
	   {
	   c_errmsg("Error returned from doopen","eopens-call",NON_FATAL);
	   return(E_FAIL);
	   }

	if (*dtype == 0)
		{
		*dtype = ddr.dtype;
		fd->dtype = ddr.dtype;
		}

	if (ddr.dtype != fd->dtype)
		{
		fd->flags |= CONVERSION;
		fd->conv_type = ddr.dtype;
		if ((fd->tae) || (fd->compres))
		    fd->cnvlsz = (ddr.ns * datasize[ddr.dtype] + 511) & ~0x1ff;
		else if (fd->dal)
		    fd->cnvlsz = ddr.ns * datasize[ddr.dtype];
		}
	if (nbands == 0)
		for(i=1; i<=ddr.nbands; i++)
			fd->bands[i-1] = i;

	if (*nl == 0)
	 	{
		*nl = ddr.nl;
		fd->nl = *nl;
	 	}

	if (*ns == 0)
	 	{
		*ns = ddr.ns;
		fd->ns = *ns;
	 	}
        if ((fd->tae) || (fd->compres))
            {
            fd->linsiz = (ddr.ns * datasize[ddr.dtype] + 511) & ~0x1ff;
            /*linsiz = (ddr.ns * datasize[ddr.dtype] + 511) & ~0x1ff;*/
            }
        else if (fd->dal)
            {
            fd->linsiz = ddr.ns * datasize[ddr.dtype];
            /*linsiz = ddr.ns * datasize[ddr.dtype];*/
            fd->img_nl = ddr.nl;
            fd->img_ns = ddr.ns;
	    }
		
	if (check_window(fd, &ddr) != E_SUCC)
	   {
	   sprintf(errtxt,"Invalid window for file %s",fd->fname);
	   c_errmsg(errtxt,"eopens-invalwind",NON_FATAL);
	   return(E_FAIL);
	   }
	}  /*  if (fd->acc == IREAD) || (fd->acc == IUPDATE)  */
else
	{  /*  else fd->acc == IWRITE  */
        fd->compres = fd->tae = FALSE;
        fd->dal = TRUE;
	nbands = bands[0];
	fd->nbands = nbands;
	
	if (nbands < 1)
	   {
	   sprintf(errtxt, "No Bands Specified for file %s",
	           fd->fname);
	   c_errmsg(errtxt,"eopens-nobands",NON_FATAL);
	   return(E_FAIL);
	   }
	else
		{
		for (i=0; i<nbands; i++)
			fd->bands[i] = i + 1;
		}
        
        fd->compres = FALSE;

		if (opt[0] != 0)
		    if ((opt[0] > 0) && (opt[0] < NDTYPES))	
			{
		        if (opt[0] != fd->dtype)
                            {
			    fd->flags |= CONVERSION;
			    fd->conv_type = opt[0];
                            if ((fd->tae) || (fd->compres))
                                fd->cnvlsz = (*ns * 
					datasize[opt[0]] +511) & ~0x1ff;
                            else if (fd->dal)
                                fd->cnvlsz = *ns * datasize[opt[0]];
                            }
		        }
		else
	           {
	           c_errmsg("Invalid option specified","eopens-option",
		            NON_FATAL);
	           return(E_FAIL);
	           }
	if (fd->dal)
	    {
            fd->linsiz = *ns * datasize[*dtype];
	    filesize = fd->linsiz * fd->nl * fd->nbands;
	    if (opt[0] != 0 && opt[0] != 5)
		if (opt[0] != fd->dtype)
		    filesize = fd->cnvlsz * fd->nl * fd->nbands;
	    }
	else
	    {
	    filesize = 11 * 512 + fd->linsiz * fd->nl * fd->nbands;
	    if (opt[0] != 0 && opt[0] != 5)
		if (opt[0] != fd->dtype)
		    filesize = 11 * 512 + fd->cnvlsz * fd->nl * fd->nbands;
	    }
	stati = c_dkcre(fd->fname, filesize);
	if (stati != E_SUCC)
	   {
	   c_errmsg("Error returned from dkcre","eopens-call",NON_FATAL);
	   return(E_FAIL);
	   }
	
	stati = do_open(fd);	
	if (stati != E_SUCC)
	   {
	   c_errmsg("Error returned from doopen","eopens-call", NON_FATAL);
	   return(E_FAIL);
	   }

	c_intddr(&ddr);
	ddr.nl = fd->nl;
	ddr.ns = fd->ns;
	ddr.nbands = fd->nbands;
	if (fd->flags & CONVERSION)
		ddr.dtype = fd->conv_type;
	else
		ddr.dtype = fd->dtype;

	stati = c_putddr(fname, &ddr);	
	if (stati != E_SUCC)
	   {
	   c_errmsg("Error returned from putddr","eopens-call", NON_FATAL);
	   return(E_FAIL);
	   }
 }

#ifdef DEBUG_IMAGEIO
pfd(fd);
#endif
if ((fd->tae) || (fd->compres))
    {
    fd->linsiz = (ddr.ns * datasize[*dtype] + 511) & ~0x1ff;
    fd->file_linsiz = (ddr.ns * datasize[ddr.dtype] + 511) & ~0x1ff;
    }
else if (fd->dal)
    {
    fd->linsiz = ddr.ns * datasize[*dtype];
    fd->file_linsiz = ddr.ns * datasize[ddr.dtype];
    }
return(E_SUCC);
}
Ejemplo n.º 15
0
void main(int argc, char *argv[])
{
	int i = 0, cmd = -1, fd = 0; 
	char line[128], cname[64], temp_pathname[124], pathname[124] = "NULL", basename[124] = "NULL",
	     dirname[124] = "NULL", parameter[124] = "NULL", *device;

	//GETS DISK NAME TO MOUNT
	/*
	printf("Enter the name of your disk image\n");
	fgets(device, 128, stdin);
	device[strlen(device)-1] = 0;  // kill the \n char at end	
	*/
	device = "mydisk";
	
	mount_root(device, &fd);

	while(1)
	{
		//printf("P%d running: ", running.uid);
		printf("nick's@linux:");
		pwd(P0.cwd);
		printf("$ ");
		fgets(line, 128, stdin);
		line[strlen(line)-1] = 0;  // kill the \n char at end
		if (line[0]==0) continue;

		sscanf(line, "%s %s %s", cname, pathname, parameter);

		if(strcmp(pathname,"NULL") != 0)		
			strcpy(PATHNAME, pathname);
		
		if(strcmp(parameter,"NULL") != 0)		
			strcpy(PARAMETER, parameter);

		cmd = findCmd(cname); // map cname to an index
		switch(cmd)
		{
			case 0 : menu();		break;
			case 1 : pwd(P0.cwd);printf("\n");			break;
			case 2 : ls();			break;
			case 3 : cd();			break;
			case 4 : make_dir();		break;
			case 5 : rmdir();               break;
			case 6 : creat_file();          break;
			case 7 : link();                break;
			case 8 : unlink();              break;
			case 9 : symlink();             break;
			case 10: rm_file();             break;
			case 11: chmod_file();          break;
			case 12: chown_file();          break;
			case 13: stat_file();           break;
			case 14: touch_file();          break;
			case 20: open_file();           break;		//LEVEL 2
			case 21: close_file((int)PATHNAME);          break;
			case 22: pfd();                 break;
			case 23: lseek_file();          break;
			case 24: //access_file();         break;
				break;
			case 25: //read_file();           
				break;
			case 26: write_file();          break;
			case 27: cat_file();            break;
			case 28: cp_file();             break;
			case 29: mv_file();             break;
			case 30: mount();               break;		//LEVLEL 3
			case 31: //umount();              break;
			case 32: //cs();                  break;
			case 33: //do_fork();             break;
			case 34: //do_ps();               break;
			case 40: //sync();                break; 
			case 41: quit();              	 break;
			case 42 : system("clear");	break; 
			default: printf("invalid command\n");
			break;
			
		}

		//RESET NAMES
		strcpy(parameter, "NULL");
		strcpy(pathname, "NULL");
		strcpy(PATHNAME, "NULL");
	}
	
  }