Ejemplo n.º 1
0
void recv_request(int newfd)
{
	char buf[2048];
	int ret;
	while(1)
	{
		bzero(buf,sizeof(buf));
		ret=recv(newfd,buf,sizeof(buf),0);
		if(ret==0)
		{
			break;
		}
		if(strncmp("cd",buf,2)==0)
		{
			do_cd(newfd,buf);
	}else if(strncmp("ls",buf,2)==0)
	{
		do_ls(newfd,buf);
	}else if(strncmp("puts",buf,4)==0)
	{
		do_puts(newfd);
	}else if(strncmp("gets",buf,4)==0)
	{
		do_gets(newfd,buf);
	}else if(strncmp("remove",buf,6)==0)
	{
		do_remove(newfd,buf);
	}else if(strncmp("pwd",buf,3)==0)
	{
		do_pwd(newfd,buf);
	}else{
		continue;
	}
	}
}
Ejemplo n.º 2
0
/* --------------------------------------------------------
 do_pwd: 
 *      recursively follow a pathname back to a root 
 * 
 *      base case: dir is a ROOT 
 *      if not base case: 
 *              (1) get_block and point DIR* dp to start 
                   of second block, which is ..
 *              (2) use dp to get parent's ino 
 *              (3) load parent MINODE using iget 
 *              (4) Recusively call do_pwd(parent) 
 *              (5) print / and directory name 
 -------------------------------------------------------------*/
void do_pwd(MINODE* dir)
{
    MINODE* parent; 
    int pino, ino;  
    char* cp; 
    DIR* dp; 
    char buf[BLOCK_SIZE]; 
    
    // (1) Base case: DIR is root 
    if(dir == root)
    {
        printf("/"); 
        return; 
    }
    
    // Read in i_block[0], 
    // which contains all of the directories contained in this DIR
    get_block(dir->dev, dir->INODE.i_block[0], buf); 
    
    // Point to the beginning of the datablock 
    cp = buf; 
    dp = (DIR*) cp; 
    
    // Get ino number of current directory 
    ino = dp->inode; 
    
    // go to second data block, get ino of .. 
    cp += dp->rec_len;            
    dp = (DIR* )cp; 
    
    // dp now points to .., the parent's directory 
    pino = dp->inode;           // get parent's ino
    
    // Load the parent MINODE*
    parent = iget(dir->dev, pino);
    
    // Call pwd with parent's MINODE pointer 
    do_pwd(parent);
    
    if(parent == NULL)
    {
        printf("Error: could not load MINODE %s", dp->name); 
        return; 
    }
    
    // (3) Print name followed by /
            // Search parent DIR for an entry with this ino 
            // Get the name associated with this ino 
    char* dirName = findmyname(parent, ino); 
    printf("%s/", dirName);
   
    iput(parent); 
}
Ejemplo n.º 3
0
void client_handle(psession_t ps)
{

	socket_t fd_client = ps -> sess_sfd ;
	int cmd_len = 0 ;
	int recv_ret ;
	while(1 )
	{
		bzero(ps -> sess_buf, BUF_SIZE);
		recv_ret = recv(fd_client, &cmd_len, sizeof(int),0);
		if(cmd_len == 0 || recv_ret == 0)
		{
			printf("client exit !\n");
			close(ps ->sess_sfd);
			free(ps);
			exit(1);
		}
		recvn(fd_client, ps->sess_buf, cmd_len);
		if(strncmp("cd", ps ->sess_buf, 2) == 0)
		{
			do_cd(ps);
		}else if(strncmp("ls", ps ->sess_buf, 2) == 0)
		{
			do_ls(ps);
		}else if( strncmp("puts", ps ->sess_buf, 4)== 0)
		{
			do_puts(ps);
		}else if( strncmp("gets", ps ->sess_buf, 4)== 0)
		{
			do_gets(ps);

		}else if( strncmp("remove", ps ->sess_buf, 6)== 0)
		{
			do_remove(ps);

		}else if(strncmp("pwd", ps ->sess_buf, 3) == 0) 
		{
			do_pwd(ps);

		}else 
		{
			continue ;
		}


	}
}
Ejemplo n.º 4
0
void runbuildin(BuildInType command)
{
	switch(command)
	{
		case CD:
			do_cd();
			break;
		case PWD:
			do_pwd();
			break;
		case EXIT:
			do_exit();
			break;
		case HISTORY:
			do_history();
			break;
		case NO:/* nothing */
		default:break;	
	}
}
Ejemplo n.º 5
0
/* --------------- driver to for recursive do_pwd() --------------*/
void pwd()
{   
    do_pwd(running->cwd); 
    printf("\n"); 
}
Ejemplo n.º 6
0
void runProcess( Proc *proc, pid_t pgid, int fg, int inputFile, int outputFile, int errorFile)
{
    // wrzucenie procesu do grupy procesow i danie przekazanie grupy terminalowu jezeli jest to stosowne
    // utowrzenie grupy lub dolaczenie do juz istniejacej
    pid_t pid = getpid();

    if( pgid == 0 )
        pgid = pid;

    setpgid(pid, pgid);

    // jesli w foreground to oddajemy terminal dla grupy procesow
    if(fg == 1)
    {
        tcsetpgrp( shellTerminal, pgid );
    }

    struct sigaction act;
    act.sa_handler = SIG_DFL;  /* set up signal handler */
    act.sa_flags = 0;

    // kiedy shell przejmuje kontrole, powinien ignorowac ponizsze sygnaly, zeby samemu sie przypadkowo nie killnac
    sigaction(SIGINT, &act, NULL);
    // powrot do ustawien domyslnych (przez nasz shell te sygnaly byly ignorowane)
    sigaction(SIGINT, &act, NULL);
    sigaction(SIGQUIT, &act, NULL);
    sigaction(SIGCHLD, &act, NULL);
    sigaction(SIGTSTP, &act, NULL);
    sigaction(SIGTTIN, &act, NULL);
    sigaction(SIGTTOU, &act, NULL);

    // ustawienie standardowego I/O dla nowego procesu
    // jesli wyjscia sa inne niz standardowe to zamieniamy je - przekierowanie wyjscia
    if(inputFile != STDIN_FILENO)
    {
        dup2(inputFile, STDIN_FILENO);
        close(inputFile);
    }

    if(outputFile != STDOUT_FILENO)
    {
        dup2(outputFile, STDOUT_FILENO);
        close(outputFile);
    }

    if(errorFile != STDERR_FILENO)
    {
        dup2(errorFile, STDERR_FILENO);
        close(errorFile);
    }   if(strcmp(proc->argv[0], "pwd") == 0)
    {
        do_pwd();
    }
    else if(strcmp(proc->argv[0], "cd") == 0)
    {
        do_cd(proc->argv[1]);
    }
    else if(strcmp(proc->argv[0], "ls") == 0)
    {
        do_ls(proc->argv[1]);
    }
    else if(strcmp(proc->argv[0], "mkdir") == 0)
    {
        do_mkdir(proc->argv[1]);
    }
    else if(strcmp(proc->argv[0], "rmdir") == 0)
    {
        do_rmdir(proc->argv[1]);
    }
    else if(strcmp(proc->argv[0], "touch") == 0)
    {
        do_touch(proc->argv[1]);
    }
    else if(strcmp(proc->argv[0], "rm") == 0)
    {
        do_rm(proc->argv[1]);
    }
    else if(strcmp(proc->argv[0], "cp") == 0)
    {
        do_cp(proc->argv[1], proc->argv[2]);
    }
    else if(strcmp(proc->argv[0], "echo") == 0)
    {
        do_echo(proc->argv[1]);
    }
	else 
		run(proc->argv[0], proc->argv);
    //execvp(proc->argv[0], proc->argv);
    // nie powinien wykonac exit'a przy poprawnym wykonaniu
    //exit(-1);
}