Fork me on GitHub

root/kernel/syscalls/write.c

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

DEFINITIONS

This source file includes following definitions.
  1. sys_write

   1 /*
   2  * fiwix/kernel/syscalls/write.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/fcntl.h>
  10 #include <fiwix/errno.h>
  11 
  12 #ifdef __DEBUG__
  13 #include <fiwix/stdio.h>
  14 #include <fiwix/process.h>
  15 #endif /*__DEBUG__ */
  16 
  17 int sys_write(unsigned int ufd, const char *buf, int count)
  18 {
  19         struct inode *i;
  20         int errno;
  21 
  22 #ifdef __DEBUG__
  23 /*      printk("(pid %d) sys_write(%d, '%s', %d)\n", current->pid, ufd, buf, count);*/
  24         printk("(pid %d) sys_write(%d, 0x%08x, %d) -> ", current->pid, ufd, buf, count);
  25 #endif /*__DEBUG__ */
  26 
  27         CHECK_UFD(ufd);
  28         if((errno = check_user_area(VERIFY_READ, buf, count))) {
  29                 return errno;
  30         }
  31         if(fd_table[current->fd[ufd]].flags & O_RDONLY) {
  32                 return -EBADF;
  33         }
  34         if(!count) {
  35                 return 0;
  36         }
  37         if(count < 0) {
  38                 return -EINVAL;
  39         }
  40         i = fd_table[current->fd[ufd]].inode;
  41         if(i->fsop && i->fsop->write) {
  42                 errno = i->fsop->write(i, &fd_table[current->fd[ufd]], buf, count);
  43 #ifdef __DEBUG__
  44                 printk("%d\n", errno);
  45 #endif /*__DEBUG__ */
  46                 return errno;
  47         }
  48         return -EINVAL;
  49 }

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