Welcome to The Fiwix Project
A UNIX-like kernel for the i386 architecture
1 /* 2 * fiwix/kernel/syscalls/close.c 3 * 4 * Copyright 2018, Jordi Sanfeliu. All rights reserved. 5 * Distributed under the terms of the Fiwix License. 6 */ 7 8 #include <fiwix/syscalls.h> 9 #include <fiwix/locks.h> 10 #include <fiwix/errno.h> 11 #include <fiwix/stdio.h> 12 13 int sys_close(unsigned int ufd) 14 { 15 unsigned int fd; 16 struct inode *i; 17 18 #ifdef __DEBUG__ 19 printk("(pid %d) sys_close(%d)\n", current->pid, ufd); 20 #endif /*__DEBUG__ */ 21 22 CHECK_UFD(ufd); 23 fd = current->fd[ufd]; 24 release_user_fd(ufd); 25 26 if(--fd_table[fd].count) { 27 return 0; 28 } 29 i = fd_table[fd].inode; 30 flock_release_inode(i); 31 if(i->fsop && i->fsop->close) { 32 i->fsop->close(i, &fd_table[fd]); 33 release_fd(fd); 34 iput(i); 35 return 0; 36 } 37 printk("WARNING: %s(): ufd %d without the close() method!\n", __FUNCTION__, ufd); 38 return -EINVAL; 39 }