diff --git a/student-distrib/proc.c b/student-distrib/proc.c index 74c104230c7bdb0b4d07012ca25f2d547298bfc0..e6589fd5bb4cfe9fbe5e0eb0813a9d62e81d391c 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 943aa66eaa62fdc9c9ce50e01e450fb1aff4a2f8..5efb86de5c2086ce5c44458b8322d49b5051544a 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 069f84f0d9b94bc42943f7790c2844f1243850ca..e7aba01c8e4da3cccf26e511408fc41fc3d5e130 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 ;