From 30f193b5dfd0148f23d7e5101ad040711685deb8 Mon Sep 17 00:00:00 2001 From: Xu <kexu6@illinois.edu> Date: Sat, 21 Apr 2018 16:40:32 -0500 Subject: [PATCH] fix fd_check --- student-distrib/proc.c | 17 ++++++++++------- student-distrib/terminal.c | 7 +++---- student-distrib/types.h | 7 +++---- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/student-distrib/proc.c b/student-distrib/proc.c index 74c1042..e6589fd 100644 --- a/student-distrib/proc.c +++ b/student-distrib/proc.c @@ -27,10 +27,14 @@ void control_initilization(void) //checking is fd is valid int32_t fd_check(int32_t fd) { - if( control.terminal[control.cur_terminal].pcb->fd[fd].flags != 0 && - fd >= MIN_FILE_NUM && - fd < MAX_FILE_NUM ){ return 1; } - else { return 0; } + if( fd >= MIN_FILE_NUM && + fd < MAX_FILE_NUM ){ return -1; } + + // file not present + if (control.terminal[control.cur_terminal].pcb->fd[fd].flags == 0) + return -1; + + else return 0; } //clearing fd @@ -74,7 +78,6 @@ void pcb_init(pcb_t* pcb , uint8_t* parsed_cmd, uint8_t (*argv)[MAX_ARGUMENT_SIZ //initialize other things in pcb structures pcb->pid = pid; - //pcb->parent_pid = (control.terminal[control.cur_terminal].terminal_prog_count - 1 == 0) ? pid - 1: control.terminal[control.cur_terminal].pcb->pid; // no program other than the shell initiates another program pcb->parent_pid = 0; @@ -224,8 +227,8 @@ int32_t set_pid(void) for (i = 0; i < MAX_PROCESS; i++) { if (control.pid_array[i] == 0){ - control.pid_array[i] = 1; - return i; + control.pid_array[i] = 1; + return i; } } printf("Reached maximum number of processes %d\n", MAX_PROCESS); diff --git a/student-distrib/terminal.c b/student-distrib/terminal.c index 943aa66..5efb86d 100644 --- a/student-distrib/terminal.c +++ b/student-distrib/terminal.c @@ -170,7 +170,7 @@ void init_terminal(void) /* * FUNCTIONALITY: switching terminal * - * INPUT: the terminal id of the ther terminal that we want to switch to + * INPUT: the terminal id of the terminal that we want to switch to * * OUTPUT: -2 - invalid terminal ID or maximum number of processes reached * -1 - trying to switch to same terminal @@ -196,15 +196,14 @@ int32_t switch_terminal(int32_t term_id) control.cur_terminal = term_id; control.visible_terminal = term_id; - //store previous terminal data - //copy_term_data(prev_terminal, 0); + //store previous terminal data into memory memcpy( (void*)control.terminal[prev_terminal].vid_mem, (const void*)TERM_VID, _4_KB ); //remap_term(term_id); clear(); update_cursor(); - //copy_term_data(control.cur_terminal, 1); + //display new terminal video memory memcpy( (void*)TERM_VID, (const void*)control.terminal[term_id].vid_mem, _4_KB ); //check if shell is running on that terminal diff --git a/student-distrib/types.h b/student-distrib/types.h index 069f84f..e7aba01 100644 --- a/student-distrib/types.h +++ b/student-distrib/types.h @@ -161,9 +161,9 @@ typedef struct pcb { /* Terminal structure - Up to 3 terminals supported */ typedef struct terminal { - pcb_t * pcb; - int32_t terminal_x; - int32_t terminal_y; + pcb_t* pcb; + int32_t terminal_x; // cursor location + int32_t terminal_y; // cursor location int32_t vid_mem; int32_t terminal_prog_count; @@ -193,7 +193,6 @@ typedef struct control { /*---------------------------- Global variable -------------------------------*/ -/* Godlike--- */ control_t control; f_table_t dir_jumptable ; -- GitLab