From 4531bc57aefb14b8051e8c8172019cd435500d6b Mon Sep 17 00:00:00 2001
From: Divyam Khandelwal <divyam@wirelessprv-10-194-9-252.near.illinois.edu>
Date: Sun, 22 Apr 2018 12:09:31 -0500
Subject: [PATCH] fd_check updated

---
 student-distrib/pit.c  |  2 +-
 student-distrib/proc.c | 20 +++++++++++---------
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/student-distrib/pit.c b/student-distrib/pit.c
index 81eb0b0..366a558 100644
--- a/student-distrib/pit.c
+++ b/student-distrib/pit.c
@@ -19,7 +19,7 @@ void i8253_init(void){
 void pit_handler(){
 
 	//printf("[PIT] Interrupt Test");
-	scheduler();
+	//scheduler();
 	send_eoi(0);
 
     //todo
diff --git a/student-distrib/proc.c b/student-distrib/proc.c
index e6589fd..c232e2b 100644
--- a/student-distrib/proc.c
+++ b/student-distrib/proc.c
@@ -24,17 +24,19 @@ void control_initilization(void)
     control.running_terminal = 0;
 }
 
-//checking is fd is valid
+/* Checks if FD is valid
+ * Returns -1 for invalid FD
+ * Returns 0 for valid FD */
 int32_t fd_check(int32_t fd)
 {
-    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;
+    /* First check for valid index */
+    if (fd >= MIN_FILE_NUM && fd < MAX_FILE_NUM )
+    {
+        /* Now check if file is present */ 
+        if (control.terminal[control.cur_terminal].pcb->fd[fd].flags != 0)    
+            return 0; 
+    }
+    return -1;
 }
 
 //clearing fd
-- 
GitLab