Fork me on GitHub

root/kernel/syscalls/chmod.c

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

DEFINITIONS

This source file includes following definitions.
  1. sys_chmod

   1 /*
   2  * fiwix/kernel/syscalls/chmod.c
   3  *
   4  * Copyright 2018, Jordi Sanfeliu. All rights reserved.
   5  * Distributed under the terms of the Fiwix License.
   6  */
   7 
   8 #include <fiwix/types.h>
   9 #include <fiwix/kernel.h>
  10 #include <fiwix/fs.h>
  11 #include <fiwix/stat.h>
  12 #include <fiwix/errno.h>
  13 #include <fiwix/string.h>
  14 
  15 #ifdef __DEBUG__
  16 #include <fiwix/stdio.h>
  17 #include <fiwix/process.h>
  18 #endif /*__DEBUG__ */
  19 
  20 int sys_chmod(const char *filename, __mode_t mode)
  21 {
  22         struct inode *i;
  23         char *tmp_name;
  24         int errno;
  25 
  26 #ifdef __DEBUG__
  27         printk("(pid %d) sys_chmod('%s', %d)\n", current->pid, filename, mode);
  28 #endif /*__DEBUG__ */
  29 
  30         if((errno = malloc_name(filename, &tmp_name)) < 0) {
  31                 return errno;
  32         }
  33         if((errno = namei(tmp_name, &i, NULL, FOLLOW_LINKS))) {
  34                 free_name(tmp_name);
  35                 return errno;
  36         }
  37 
  38         if(IS_RDONLY_FS(i)) {
  39                 iput(i);
  40                 free_name(tmp_name);
  41                 return -EROFS;
  42         }
  43         if(check_user_permission(i)) {
  44                 iput(i);
  45                 free_name(tmp_name);
  46                 return -EPERM;
  47         }
  48 
  49         i->i_mode &= S_IFMT;
  50         i->i_mode |= mode & ~S_IFMT;
  51         i->i_ctime = CURRENT_TIME;
  52         i->dirty = 1;
  53         iput(i);
  54         free_name(tmp_name);
  55         return 0;
  56 }

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