Welcome to The Fiwix Project
A UNIX-like kernel for the i386 architecture
1 /* 2 * fiwix/kernel/syscalls/fchdir.c 3 * 4 * Copyright 2018, Jordi Sanfeliu. All rights reserved. 5 * Distributed under the terms of the Fiwix License. 6 */ 7 8 #include <fiwix/fs.h> 9 #include <fiwix/process.h> 10 #include <fiwix/stat.h> 11 #include <fiwix/errno.h> 12 13 #ifdef __DEBUG__ 14 #include <fiwix/stdio.h> 15 #endif /*__DEBUG__ */ 16 17 int sys_fchdir(unsigned int ufd) 18 { 19 struct inode *i; 20 21 #ifdef __DEBUG__ 22 printk("(pid %d) sys_fchdir(%d)\n", current->pid, ufd); 23 #endif /*__DEBUG__ */ 24 25 CHECK_UFD(ufd); 26 i = fd_table[current->fd[ufd]].inode; 27 if(!S_ISDIR(i->i_mode)) { 28 return -ENOTDIR; 29 } 30 iput(current->pwd); 31 current->pwd = i; 32 current->pwd->count++; 33 return 0; 34 }