Fork me on GitHub

root/kernel/syscalls/chdir.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sys_chdir

   1 /*
   2  * fiwix/kernel/syscalls/chdir.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/stat.h>
  10 #include <fiwix/errno.h>
  11 #include <fiwix/string.h>
  12 
  13 #ifdef __DEBUG__
  14 #include <fiwix/stdio.h>
  15 #include <fiwix/process.h>
  16 #endif /*__DEBUG__ */
  17 
  18 int sys_chdir(const char *dirname)
  19 {
  20         struct inode *i;
  21         char *tmp_name;
  22         int errno;
  23 
  24 #ifdef __DEBUG__
  25         printk("(pid %d) sys_chdir('%s')\n", current->pid, dirname);
  26 #endif /*__DEBUG__ */
  27 
  28         if((errno = malloc_name(dirname, &tmp_name)) < 0) {
  29                 return errno;
  30         }
  31         if((errno = namei(tmp_name, &i, NULL, FOLLOW_LINKS))) {
  32                 free_name(tmp_name);
  33                 return errno;
  34         }
  35         if(!S_ISDIR(i->i_mode)) {
  36                 iput(i);
  37                 free_name(tmp_name);
  38                 return -ENOTDIR;
  39         }
  40         if((errno = check_permission(TO_EXEC, i))) {
  41                 iput(i);
  42                 free_name(tmp_name);
  43                 return errno;
  44         }
  45         iput(current->pwd);
  46         current->pwd = i;
  47         free_name(tmp_name);
  48         return 0;
  49 }

/* [previous][next][first][last][top][bottom][index][help] */