Skip to content
Snippets Groups Projects
Commit 30f193b5 authored by kexu6's avatar kexu6
Browse files

fix fd_check

parent 6c214cb7
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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
......
......@@ -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 ;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment