Ignore:
Timestamp:
Jun 18, 2017, 10:06:41 PM (7 years ago)
Author:
alain
Message:

Introduce syscalls.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kernel/syscalls/sys_lseek.c

    r1 r23  
    2121 */
    2222
    23 #include <types.h>
     23#include <kernel_config.h>
     24#include <hal_types.h>
     25#include <hal_uspace.h>
     26#include <errno.h>
    2427#include <vfs.h>
     28#include <vmm.h>
    2529#include <thread.h>
    26 #include <sys-vfs.h>
    27 #include <task.h>
     30#include <printk.h>
     31#include <process.h>
    2832
    29 int sys_lseek (uint_t fd, off_t offset, int whence)
     33////////////////////////////////
     34int sys_lseek (uint32_t file_id,
     35               uint32_t offset,
     36               uint32_t whence )
    3037{
    31         error_t err = 0;
    32         size_t new_offset;
    33         struct thread_s *this;
    34         struct task_s *task;
    35         struct vfs_file_s *file;
     38        error_t    error;
     39    xptr_t     file_xp;
     40    uint32_t   new_offset;
    3641
    37         file = NULL;
    38         this = current_thread;
    39         task = current_task;
     42        thread_t  * this    = CURRENT_THREAD;
     43        process_t * process = this->process;
     44
     45    // check file_id argument
     46        if( file_id >= CONFIG_PROCESS_FILE_MAX_NR )
     47        {
     48        printk("\n[ERROR] in %s : illegal file descriptor index = %d\n",
     49               __FUNCTION__ , file_id );
     50                this->errno = EBADFD;
     51                return -1;
     52        }
     53
     54    // get extended pointer on remote file descriptor
     55    file_xp = process_fd_get_xptr( process , file_id );
     56
     57    if( file_xp == XPTR_NULL )
     58    {
     59        printk("\n[ERROR] in %s : undefined file descriptor index = %d\n",
     60               __FUNCTION__ , file_id );
     61                this->errno = EBADFD;
     62                return -1;
     63    }
    4064
    4165        /* FIXME: file may be closed in parallel
    4266         * of seek/read/write/mmap ..etc
    4367         * so file may be NULL or invalid */
    44         if((fd >= CONFIG_TASK_FILE_MAX_NR) || (task_fd_lookup(task, fd, &file)))
     68
     69    // call relevant VFS function
     70        error = vfs_lseek( file_xp , offset , whence , &new_offset );
     71
     72        if( error )
    4573        {
    46                 this->info.errno = EBADFD;
    47                 return -1;
    48         }
    49 
    50         if((err = vfs_lseek(file, offset, whence, &new_offset)))
    51         {
    52                 this->info.errno = (err < 0) ? -err : err;
     74        printk("\n[ERROR] in %s : cannot seek file = %d\n",
     75               __FUNCTION__ , file_id );
     76                this->errno = error;
    5377                return -1;
    5478        }
Note: See TracChangeset for help on using the changeset viewer.