@@ -380,7 +380,8 @@ int vfs_clone_fd(int *fd_src, int *fd_dst)
380380
381381/**************************** Syscall implementation ****************************/
382382
383- SYSCALL_DEFINE3 (read , int , fd , void * , buffer , int , count )
383+ /* Low Level read */
384+ static int do_read (int fd , void * buffer , int count )
384385{
385386 int gfd ;
386387 int ret ;
@@ -421,10 +422,8 @@ SYSCALL_DEFINE3(read, int, fd, void *, buffer, int, count)
421422 return ret ;
422423}
423424
424- /**
425- * @brief This function writes a REGULAR FILE/FOLDER. It only support regular file, dirs and pipes
426- */
427- SYSCALL_DEFINE3 (write , int , fd , const void * , buffer , int , count )
425+ /* Low Level write */
426+ static int do_write (int fd , const void * buffer , int count )
428427{
429428 int gfd ;
430429 int ret ;
@@ -464,6 +463,19 @@ SYSCALL_DEFINE3(write, int, fd, const void *, buffer, int, count)
464463 return ret ;
465464}
466465
466+ SYSCALL_DEFINE3 (read , int , fd , void * , buffer , int , count )
467+ {
468+ return do_read (fd , buffer , count );
469+ }
470+
471+ /**
472+ * @brief This function writes a REGULAR FILE/FOLDER. It only support regular file, dirs and pipes
473+ */
474+ SYSCALL_DEFINE3 (write , int , fd , const void * , buffer , int , count )
475+ {
476+ return do_write (fd , buffer , count );
477+ }
478+
467479/**
468480 * @brief This function opens a file. Not all file types are supported.
469481 */
@@ -655,7 +667,7 @@ SYSCALL_DEFINE2(dup2, int, oldfd, int, newfd)
655667 }
656668
657669 if (vfs_get_gfd (oldfd ) != vfs_get_gfd (newfd ))
658- do_close (newfd );
670+ sys_do_close (newfd );
659671
660672 vfs_link_fd (newfd , vfs_get_gfd (oldfd ));
661673
@@ -824,6 +836,57 @@ SYSCALL_DEFINE3(fcntl, int, fd, unsigned long, cmd, unsigned long, args)
824836 return 0 ;
825837}
826838
839+ /*
840+ * Implementation of the writev syscall
841+ */
842+ SYSCALL_DEFINE3 (writev , unsigned long , fd , const struct iovec * , vec , unsigned long , vlen )
843+ {
844+ int i ;
845+ int ret = 0 ;
846+ int total = 0 ;
847+
848+ for (i = 0 ; i < vlen ; i ++ ) {
849+ ret = do_write (fd , (const void * ) vec [i ].iov_base , vec [i ].iov_len );
850+ if (ret < 0 ) {
851+ break ;
852+ } else if ((ret >= 0 ) && (ret < vec [i ].iov_len )) {
853+ total += ret ;
854+ break ;
855+ }
856+
857+ total += ret ;
858+ }
859+
860+ if (total == 0 )
861+ return ret ;
862+ else
863+ return total ;
864+ }
865+
866+ SYSCALL_DEFINE3 (readv , unsigned long , fd , const struct iovec * , vec , unsigned long , vlen )
867+ {
868+ int i ;
869+ int ret = 0 ;
870+ int total = 0 ;
871+
872+ for (i = 0 ; i < vlen ; i ++ ) {
873+ ret = do_read (fd , vec [i ].iov_base , vec [i ].iov_len );
874+ if (ret < 0 ) {
875+ break ;
876+ } else if ((ret >= 0 ) && (ret < vec [i ].iov_len )) {
877+ total += ret ;
878+ break ;
879+ }
880+
881+ total += ret ;
882+ }
883+
884+ if (total == 0 )
885+ return ret ;
886+ else
887+ return total ;
888+ }
889+
827890static void vfs_gfd_init (void )
828891{
829892 memset (open_fds , 0 , MAX_FDS * sizeof (struct fd * ));
0 commit comments