Fork me on GitHub

root/kernel/syscalls/readlink.c

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

DEFINITIONS

This source file includes following definitions.
  1. sys_readlink

   1 /*
   2  * fiwix/kernel/syscalls/readlink.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_readlink(const char *filename, char *buffer, __size_t bufsize)
  20 {
  21         struct inode *i;
  22         char *tmp_name;
  23         int errno;
  24 
  25 #ifdef __DEBUG__
  26         printk("(pid %d) sys_readlink(%s, 0x%08x, %d)\n", current->pid, filename, (unsigned int)buffer, bufsize);
  27 #endif /*__DEBUG__ */
  28 
  29         if(bufsize <= 0) {
  30                 return -EINVAL;
  31         }
  32         if((errno = check_user_area(VERIFY_WRITE, buffer, bufsize))) {
  33                 return errno;
  34         }
  35         if((errno = malloc_name(filename, &tmp_name)) < 0) {
  36                 return errno;
  37         }
  38         if((errno = namei(tmp_name, &i, NULL, !FOLLOW_LINKS))) {
  39                 free_name(tmp_name);
  40                 return errno;
  41         }
  42         if(!S_ISLNK(i->i_mode)) {
  43                 iput(i);
  44                 free_name(tmp_name);
  45                 return -EINVAL;
  46         }
  47 
  48         if(i->fsop && i->fsop->readlink) {
  49                 errno = i->fsop->readlink(i, buffer, bufsize);
  50                 iput(i);
  51                 free_name(tmp_name);
  52                 return errno;
  53         }
  54         iput(i);
  55         free_name(tmp_name);
  56         return -EINVAL;
  57 }

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