student-distrib/system_call.c
int32_t syscall_close(int32_t fd) {

	//check for invalid input
	if((fd > 7) || (fd < 2))
		return -1;



	//get current file descriptor array from pcb
	pcb_t* pcb = get_pcb(tasks_running);
	file_descriptor_t* fd_array = pcb->fd;

	//already closed
	if(fd_array[fd].flags == 0)
		return -1;

	//error out if fd table is invalid
	if(fd_array == NULL)
		return -1;

	//if close is unused, return -1
	if(fd_array[fd].fops_table->close == NULL)
		return -1;

	//if the called close function returns -1, return -1
	if((*fd_array[fd].fops_table->close)(&fd_array[fd].inode) == -1)
		return -1;

	//reset entry's file_position
	fd_array[fd].file_position = 0;

	//free the fda entry and return 0
	fd_array[fd].flags = 0;
	return 0;
}
/* system_close() - added by mlee148
 * Input: file name to be opened
 * Returns: -1 if cannot be execute
 * Effect:
 */
added by mlee148
Input: file name to be opened
Returns: -1 if cannot be execute
Effect.
added by mlee148 Input : file name to be opened Returns : - 1 if cannot be execute Effect .
int32_t syscall_close(int32_t fd) {
	if((fd > 7) || (fd < 2))
		return -1;
	pcb_t* pcb = get_pcb(tasks_running);
	file_descriptor_t* fd_array = pcb->fd;
	if(fd_array[fd].flags == 0)
		return -1;
	if(fd_array == NULL)
		return -1;
	if(fd_array[fd].fops_table->close == NULL)
		return -1;
	if((*fd_array[fd].fops_table->close)(&fd_array[fd].inode) == -1)
		return -1;
	fd_array[fd].file_position = 0;
	fd_array[fd].flags = 0;
	return 0;
}
int32_t syscall_close ( int32_t fd ) { if ( ( fd > 7 ) || ( fd < 2 ) ) return -1 ; pcb_t * pcb = get_pcb ( tasks_running ) ; file_descriptor_t * fd_array = pcb -> fd ; if ( fd_array [ fd ] . flags == 0 ) return -1 ; if ( fd_array == NULL ) return -1 ; if ( fd_array [ fd ] . fops_table -> close == NULL ) return -1 ; if ( ( * fd_array [ fd ] . fops_table -> close ) ( & fd_array [ fd ] . inode ) == -1 ) return -1 ; fd_array [ fd ] . file_position = 0 ; fd_array [ fd ] . flags = 0 ; return 0 ; }
system_close() - added by mlee148
 Input: file name to be opened
 Returns: -1 if cannot be execute
 Effect:
system_close () - added by mlee148 Input : file name to be opened Returns : - 1 if cannot be execute Effect :
//check for invalid input //get current file descriptor array from pcb //already closed //error out if fd table is invalid //if close is unused, return -1 //if the called close function returns -1, return -1 //reset entry's file_position //free the fda entry and return 0