Fork me on GitHub

root/kernel/syscalls/newfstat.c

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

DEFINITIONS

This source file includes following definitions.
  1. sys_newfstat

   1 /*
   2  * fiwix/kernel/syscalls/newfstat.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/statbuf.h>
  10 #include <fiwix/process.h>
  11 #include <fiwix/errno.h>
  12 
  13 #ifdef __DEBUG__
  14 #include <fiwix/stdio.h>
  15 #endif /*__DEBUG__ */
  16 
  17 int sys_newfstat(unsigned int ufd, struct new_stat *statbuf)
  18 {
  19         struct inode *i;
  20         int errno;
  21 
  22 #ifdef __DEBUG__
  23         printk("(pid %d) sys_newfstat(%d, 0x%08x) -> returning structure\n", current->pid, ufd, (unsigned int )statbuf);
  24 #endif /*__DEBUG__ */
  25 
  26         CHECK_UFD(ufd);
  27         if((errno = check_user_area(VERIFY_WRITE, statbuf, sizeof(struct new_stat)))) {
  28                 return errno;
  29         }
  30         i = fd_table[current->fd[ufd]].inode;
  31         statbuf->st_dev = i->dev;
  32         statbuf->__pad1 = 0;
  33         statbuf->st_ino = i->inode;
  34         statbuf->st_mode = i->i_mode;
  35         statbuf->st_nlink = i->i_nlink;
  36         statbuf->st_uid = i->i_uid;
  37         statbuf->st_gid = i->i_gid;
  38         statbuf->st_rdev = i->rdev;
  39         statbuf->__pad2 = 0;
  40         statbuf->st_size = i->i_size;
  41         statbuf->st_blksize = i->sb->s_blocksize;
  42         statbuf->st_blocks = i->i_blocks;
  43         if(!i->i_blocks) {
  44                 statbuf->st_blocks = (i->i_size / i->sb->s_blocksize * 2);
  45                 statbuf->st_blocks++;
  46         }
  47         statbuf->st_atime = i->i_atime;
  48         statbuf->__unused1 = 0;
  49         statbuf->st_mtime = i->i_mtime;
  50         statbuf->__unused2 = 0;
  51         statbuf->st_ctime = i->i_ctime;
  52         statbuf->__unused3 = 0;
  53         statbuf->__unused4 = 0;
  54         statbuf->__unused5 = 0;
  55         return 0;
  56 }

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