Fork me on GitHub

root/kernel/syscalls/stat.c

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

DEFINITIONS

This source file includes following definitions.
  1. sys_stat

   1 /*
   2  * fiwix/kernel/syscalls/stat.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/statbuf.h>
  10 #include <fiwix/fs.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_stat(const char *filename, struct old_stat *statbuf)
  19 {
  20         struct inode *i;
  21         char *tmp_name;
  22         int errno;
  23 
  24 #ifdef __DEBUG__
  25         printk("(pid %d) sys_stat(%s, 0x%08x) -> returning structure\n", current->pid, filename, (unsigned int )statbuf);
  26 #endif /*__DEBUG__ */
  27 
  28         if((errno = check_user_area(VERIFY_WRITE, statbuf, sizeof(struct old_stat)))) {
  29                 return errno;
  30         }
  31         if((errno = malloc_name(filename, &tmp_name)) < 0) {
  32                 return errno;
  33         }
  34         if((errno = namei(tmp_name, &i, NULL, FOLLOW_LINKS))) {
  35                 free_name(tmp_name);
  36                 return errno;
  37         }
  38         statbuf->st_dev = i->dev;
  39         statbuf->st_ino = i->inode;
  40         statbuf->st_mode = i->i_mode;
  41         statbuf->st_nlink = i->i_nlink;
  42         statbuf->st_uid = i->i_uid;
  43         statbuf->st_gid = i->i_gid;
  44         statbuf->st_rdev = i->rdev;
  45         statbuf->st_size = i->i_size;
  46         statbuf->st_atime = i->i_atime;
  47         statbuf->st_mtime = i->i_mtime;
  48         statbuf->st_ctime = i->i_ctime;
  49         iput(i);
  50         free_name(tmp_name);
  51         return 0;
  52 }

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