Fork me on GitHub

root/kernel/syscalls/symlink.c

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

DEFINITIONS

This source file includes following definitions.
  1. sys_symlink

   1 /*
   2  * fiwix/kernel/syscalls/symlink.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_symlink(const char *oldpath, const char *newpath)
  19 {
  20         struct inode *i, *dir;
  21         char *tmp_oldpath, *tmp_newpath, *basename;
  22         int errno;
  23 
  24 #ifdef __DEBUG__
  25         printk("(pid %d) sys_symlink('%s', '%s')\n", current->pid, oldpath, newpath);
  26 #endif /*__DEBUG__ */
  27 
  28         if((errno = malloc_name(oldpath, &tmp_oldpath)) < 0) {
  29                 return errno;
  30         }
  31         if((errno = malloc_name(newpath, &tmp_newpath)) < 0) {
  32                 free_name(tmp_oldpath);
  33                 return errno;
  34         }
  35         basename = get_basename(tmp_newpath);
  36         if((errno = namei(tmp_newpath, &i, &dir, !FOLLOW_LINKS))) {
  37                 if(!dir) {
  38                         free_name(tmp_oldpath);
  39                         free_name(tmp_newpath);
  40                         return errno;
  41                 }
  42         }
  43         if(!errno) {
  44                 iput(i);
  45                 iput(dir);
  46                 free_name(tmp_oldpath);
  47                 free_name(tmp_newpath);
  48                 return -EEXIST;
  49         }
  50         if(IS_RDONLY_FS(dir)) {
  51                 iput(dir);
  52                 free_name(tmp_oldpath);
  53                 free_name(tmp_newpath);
  54                 return -EROFS;
  55         }
  56 
  57         if(check_permission(TO_EXEC | TO_WRITE, dir) < 0) {
  58                 iput(dir);
  59                 free_name(tmp_oldpath);
  60                 free_name(tmp_newpath);
  61                 return -EACCES;
  62         }
  63 
  64         if(dir->fsop && dir->fsop->symlink) {
  65                 errno = dir->fsop->symlink(dir, basename, tmp_oldpath);
  66         } else {
  67                 errno = -EPERM;
  68         }
  69         iput(dir);
  70         free_name(tmp_oldpath);
  71         free_name(tmp_newpath);
  72         return errno;
  73 }

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