Fork me on GitHub

root/kernel/syscalls/access.c

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

DEFINITIONS

This source file includes following definitions.
  1. sys_access

   1 /*
   2  * fiwix/kernel/syscalls/access.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/fs.h>
  10 #include <fiwix/stat.h>
  11 #include <fiwix/errno.h>
  12 #include <fiwix/string.h>
  13 
  14 #ifdef __DEBUG__
  15 #include <fiwix/stdio.h>
  16 #include <fiwix/process.h>
  17 #endif /*__DEBUG__ */
  18 
  19 int sys_access(const char *filename, __mode_t mode)
  20 {
  21         struct inode *i;
  22         char *tmp_name;
  23         int errno;
  24 
  25 #ifdef __DEBUG__
  26         printk("(pid %d) sys_access('%s', %d)", current->pid, filename, mode);
  27 #endif /*__DEBUG__ */
  28 
  29         if((mode & S_IRWXO) != mode) {
  30                 return -EINVAL;
  31         }
  32         if((errno = malloc_name(filename, &tmp_name)) < 0) {
  33                 return errno;
  34         }
  35         current->flags |= PF_USEREAL;
  36         if((errno = namei(tmp_name, &i, NULL, FOLLOW_LINKS))) {
  37                 current->flags &= ~PF_USEREAL;
  38                 free_name(tmp_name);
  39                 return errno;
  40         }
  41         if(mode & TO_WRITE) {
  42                 if(S_ISREG(i->i_mode) || S_ISDIR(i->i_mode) || S_ISLNK(i->i_mode)) {
  43                         if(IS_RDONLY_FS(i)) {
  44                                 current->flags &= ~PF_USEREAL;
  45                                 iput(i);
  46                                 free_name(tmp_name);
  47                                 return -EROFS;
  48                         }
  49                 }
  50         }
  51         errno = check_permission(mode, i);
  52 
  53 #ifdef __DEBUG__
  54         printk(" -> returning %d\n", errno);
  55 #endif /*__DEBUG__ */
  56 
  57         current->flags &= ~PF_USEREAL;
  58         iput(i);
  59         free_name(tmp_name);
  60         return errno;
  61 }

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