Changeset 23 for trunk/kernel/syscalls/sys_lseek.c
- Timestamp:
- Jun 18, 2017, 10:06:41 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_lseek.c
r1 r23 21 21 */ 22 22 23 #include <types.h> 23 #include <kernel_config.h> 24 #include <hal_types.h> 25 #include <hal_uspace.h> 26 #include <errno.h> 24 27 #include <vfs.h> 28 #include <vmm.h> 25 29 #include <thread.h> 26 #include < sys-vfs.h>27 #include < task.h>30 #include <printk.h> 31 #include <process.h> 28 32 29 int sys_lseek (uint_t fd, off_t offset, int whence) 33 //////////////////////////////// 34 int sys_lseek (uint32_t file_id, 35 uint32_t offset, 36 uint32_t whence ) 30 37 { 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; 36 41 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 } 40 64 41 65 /* FIXME: file may be closed in parallel 42 66 * of seek/read/write/mmap ..etc 43 67 * 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 ) 45 73 { 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; 53 77 return -1; 54 78 }
Note: See TracChangeset
for help on using the changeset viewer.