Changeset 610 for trunk/kernel/syscalls
- Timestamp:
- Dec 27, 2018, 7:38:58 PM (6 years ago)
- Location:
- trunk/kernel/syscalls
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/shared_include/syscalls_numbers.h
r584 r610 41 41 SYS_MUTEX = 9, 42 42 43 SYS_ EXIT= 10,43 SYS_RENAME = 10, 44 44 SYS_MUNMAP = 11, 45 45 SYS_OPEN = 12, … … 85 85 SYS_IS_FG = 49, 86 86 87 SYSCALLS_NR = 50, 87 SYS_EXIT = 50, 88 89 SYSCALLS_NR = 51, 90 88 91 } syscalls_t; 89 92 -
trunk/kernel/syscalls/sys_chdir.c
r566 r610 1 1 /* 2 * sys_chdir : change process current working directory2 * sys_chdir.c - kernel function implementing the "chdir" syscall. 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 * Copyright (c) 2011,2012UPMC Sorbonne Universites6 * Copyright (c) UPMC Sorbonne Universites 7 7 * 8 8 * This file is part of ALMOS-MKH. … … 38 38 { 39 39 error_t error; 40 vseg_t * vseg; 41 xptr_t root_inode_xp; 42 40 43 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 41 44 42 45 thread_t * this = CURRENT_THREAD; 43 46 process_t * process = this->process; 47 48 #if (DEBUG_SYS_CHDIR || CONFIG_INSTRUMENTATION_SYSCALLS) 49 uint64_t tm_start = hal_get_cycles(); 50 #endif 44 51 45 52 // check pathname length … … 48 55 49 56 #if DEBUG_SYSCALLS_ERROR 50 printk("\n[ERROR] in %s : pathname too long / thread %x in process %x\n",51 __FUNCTION__, this->trdid, process->pid );57 printk("\n[ERROR] in %s : pathname too long / thread[%x,%x]\n", 58 __FUNCTION__, process->pid, this->trdid ); 52 59 #endif 53 this->errno = E NFILE;60 this->errno = EINVAL; 54 61 return -1; 55 62 } 63 64 // check pathname in user space 65 if( vmm_get_vseg( process, (intptr_t)pathname , &vseg ) ) 66 { 67 68 #if DEBUG_SYSCALLS_ERROR 69 printk("\n[ERROR] in %s : user buffer unmapped %x for thread[%x,%x]\n", 70 __FUNCTION__ , (intptr_t)pathname , process->pid, this->trdid ); 71 #endif 72 this->errno = EINVAL; 73 return -1; 74 } 56 75 57 76 // copy pathname in kernel space 58 77 hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 59 78 60 printk("\n[ERROR] in %s : not implemented yet\n", __FUNCTION__ ); 61 return -1; 79 #if DEBUG_SYS_CHDIR 80 if( DEBUG_SYS_CHDIR < tm_start ) 81 printk("\n[%s] thread[%x,%x] enter for <%s> / cycle %d\n", 82 __FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_start ); 83 #endif 62 84 63 // get cluster and local pointer on reference process 64 // xptr_t ref_xp = process->ref_xp; 65 // process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 66 // cxy_t ref_cxy = GET_CXY( ref_xp ); 85 // compute root inode for path 86 if( kbuf[0] == '/' ) // absolute path 87 { 88 // use extended pointer on VFS root inode 89 root_inode_xp = process->vfs_root_xp; 90 } 91 else // relative path 92 { 93 // get cluster and local pointer on reference process 94 xptr_t ref_xp = process->ref_xp; 95 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 96 cxy_t ref_cxy = GET_CXY( ref_xp ); 67 97 68 // get extended pointer on cwd lock in reference process 69 // xptr_t lock_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 98 // use extended pointer on CWD inode 99 root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) ); 100 } 70 101 71 // get cwd lock in read mode 72 // remote_rwlock_rd_acquire( lock_xp ); 73 74 // TODO ce n'et pas au VFS de le faire [AG] 75 // error = vfs_chdir( process->vfs_cwd_xp , kbuf ); 76 77 // release cwd lock 78 // remote_rwlock_rd_release( lock_xp ); 102 // call the relevant VFS function 103 error = vfs_chdir( root_inode_xp , kbuf ); 79 104 80 105 if( error ) 81 106 { 82 printk("\n[ERROR] in %s : cannot change current directory\n", __FUNCTION__ ); 107 108 #if DEBUG_SYSCALLS_ERROR 109 printk("\n[ERROR] in %s / thread[%x,%x] : cannot change CWD\n", 110 __FUNCTION__ , process->pid , this->trdid ); 111 #endif 83 112 this->errno = error; 84 113 return -1; 85 114 } 86 115 116 hal_fence(); 117 118 #if (DEBUG_SYS_CHDIR || CONFIG_INSTRUMENTATION_SYSCALLS) 119 uint64_t tm_end = hal_get_cycles(); 120 #endif 121 122 #if DEBUG_SYS_CHDIR 123 if( DEBUG_SYS_CHDIR < tm_end ) 124 printk("\n[%s] thread[%x,%x] exit / cycle %d\n", 125 __FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end ); 126 #endif 127 128 #if CONFIG_INSTRUMENTATION_SYSCALLS 129 hal_atomic_add( &syscalls_cumul_cost[SYS_CHDIR] , tm_end - tm_start ); 130 hal_atomic_add( &syscalls_occurences[SYS_CHDIR] , 1 ); 131 #endif 132 87 133 return 0; 88 134 } -
trunk/kernel/syscalls/sys_getcwd.c
r566 r610 1 1 /* 2 * sys_getcwd.c - get process current work directory2 * sys_getcwd.c - kernel function implementing the "getcwd" syscall. 3 3 * 4 4 * Author Alain Greiner (2016,2017,2018) … … 35 35 #include <syscalls.h> 36 36 37 /* TODO: user page(s) need to be locked [AG] */ 38 39 //////////////////////////////// 40 int sys_getcwd ( char * buf, 37 /////////////////////////////////// 38 int sys_getcwd ( char * buffer, 41 39 uint32_t nbytes ) 42 40 { 43 error_t error; 44 vseg_t * vseg; 45 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 46 41 error_t error; 42 vseg_t * vseg; 43 char * first; // first character valid in buffer 44 45 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 46 47 47 thread_t * this = CURRENT_THREAD; 48 48 process_t * process = this->process; 49 50 #if (DEBUG_SYS_GETCWD || CONFIG_INSTRUMENTATION_SYSCALLS) 51 uint64_t tm_start = hal_get_cycles(); 52 #endif 49 53 50 54 // check buffer size … … 53 57 54 58 #if DEBUG_SYSCALLS_ERROR 55 printk("\n[ERROR] in %s : buffer too small / thread %x / process %x\n",56 __FUNCTION__ , this->trdid , process->pid );59 printk("\n[ERROR] in %s : buffer too small for thread %x,%x]\n", 60 __FUNCTION__ , process->pid, this->trdid ); 57 61 #endif 58 62 this->errno = EINVAL; … … 61 65 62 66 // check buffer in user space 63 error = vmm_get_vseg( process, (intptr_t)buf , &vseg );67 error = vmm_get_vseg( process, (intptr_t)buffer , &vseg ); 64 68 65 69 if( error ) … … 67 71 68 72 #if DEBUG_SYSCALLS_ERROR 69 printk("\n[ERROR] in %s : user buffer unmapped %x / thread %x / process %x\n",70 __FUNCTION__ , (intptr_t)buf , this->trdid , process->pid );73 printk("\n[ERROR] in %s : user buffer unmapped %x for thread[%x,%x]\n", 74 __FUNCTION__ , (intptr_t)buffer , process->pid, this->trdid ); 71 75 #endif 72 76 this->errno = EINVAL; … … 74 78 } 75 79 76 // get reference process cluster and local pointer 80 #if DEBUG_SYS_GETCWD 81 if( DEBUG_SYS_GETCWD < tm_start ) 82 printk("\n[%s] thread[%x,%x] enter / cycle %d\n", 83 __FUNCTION__, process->pid, this->trdid, (uint32_t)tm_start ); 84 #endif 85 86 // get extended pointer on CWD inode from the reference process 77 87 xptr_t ref_xp = process->ref_xp; 88 process_t * ref_ptr = GET_PTR( ref_xp ); 78 89 cxy_t ref_cxy = GET_CXY( ref_xp ); 79 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 80 81 // get CWD lock in read mode 82 remote_rwlock_rd_acquire( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 90 xptr_t cwd_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) ); 83 91 84 92 // call relevant VFS function 85 error = vfs_get_path( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) , 86 kbuf , CONFIG_VFS_MAX_PATH_LENGTH ); 87 88 // release CWD lock in read mode 89 remote_rwlock_rd_release( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 93 error = vfs_get_path( cwd_xp, 94 kbuf, 95 &first, 96 CONFIG_VFS_MAX_PATH_LENGTH ); 90 97 91 98 // copy kernel buffer to user space 92 hal_ copy_to_uspace( buf , kbuf, CONFIG_VFS_MAX_PATH_LENGTH );99 hal_strcpy_to_uspace( buffer , first , CONFIG_VFS_MAX_PATH_LENGTH ); 93 100 94 101 hal_fence(); 102 103 #if (DEBUG_SYS_GETCWD || CONFIG_INSTRUMENTATION_SYSCALLS) 104 uint64_t tm_end = hal_get_cycles(); 105 #endif 106 107 #if DEBUG_SYS_GETCWD 108 if( DEBUG_SYS_GETCWD < tm_end ) 109 printk("\n[%s] thread[%x,%x] exit / cycle %d\n", 110 __FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end ); 111 #endif 112 113 #if CONFIG_INSTRUMENTATION_SYSCALLS 114 hal_atomic_add( &syscalls_cumul_cost[SYS_GETCWD] , tm_end - tm_start ); 115 hal_atomic_add( &syscalls_occurences[SYS_GETCWD] , 1 ); 116 #endif 95 117 96 118 return 0; -
trunk/kernel/syscalls/sys_mkdir.c
r566 r610 1 1 /* 2 * sys_mkdir.c - Create a new directory in file system.2 * sys_mkdir.c - creates a new directory in VFS 3 3 * 4 * Author Alain Greiner (2016,2017)4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 * Copyright (c) UPMC Sorbonne Universites6 * Copyright (c) UPMC Sorbonne Universites 7 7 * 8 * This file is part of ALMOS- MKH.8 * This file is part of ALMOS-kernel. 9 9 * 10 10 * ALMOS-MKH is free software; you can redistribute it and/or modify it … … 22 22 */ 23 23 24 #include <kernel_config.h> 24 25 #include <hal_kernel_types.h> 25 26 #include <hal_uspace.h> 27 #include <errno.h> 26 28 #include <vfs.h> 27 #include <vmm.h>28 #include <errno.h>29 29 #include <process.h> 30 30 #include <thread.h> 31 31 #include <printk.h> 32 32 33 /////////////////////////////////// 34 int sys_mkdir( char * pathname, 35 uint32_t mode __attribute__((unused)) ) 33 #include <syscalls.h> 34 35 //////////////////////////////////// 36 int sys_mkdir ( char * pathname, 37 uint32_t rights __attribute__((unused)) ) 36 38 { 37 error_t error; 38 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 39 error_t error; 40 xptr_t root_inode_xp; // extended pointer on root inode 41 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 39 42 40 43 thread_t * this = CURRENT_THREAD; 41 44 process_t * process = this->process; 42 45 43 // check fd_array not full 44 if( process_fd_array_full() ) 46 #if (DEBUG_SYS_MKDIR || CONFIG_INSTRUMENTATION_SYSCALLS) 47 uint64_t tm_start = hal_get_cycles(); 48 #endif 49 50 // check pathname length 51 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 45 52 { 46 printk("\n[ERROR] in %s : file descriptor array full for process %x\n", 47 __FUNCTION__ , process->pid ); 53 54 #if DEBUG_SYSCALLS_ERROR 55 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 56 #endif 48 57 this->errno = ENFILE; 49 58 return -1; 50 59 } 51 60 52 // check pathname length 53 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 61 // copy pathname in kernel space 62 hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 63 64 #if DEBUG_SYS_MKDIR 65 if( DEBUG_SYS_MKDIR < tm_start ) 66 printk("\n[%s] thread[%x,%x] enter for <%s> / cycle %d\n", 67 __FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_start ); 68 #endif 69 70 // compute root inode for path 71 if( kbuf[0] == '/' ) // absolute path 54 72 { 55 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 73 // use extended pointer on VFS root inode 74 root_inode_xp = process->vfs_root_xp; 75 } 76 else // relative path 77 { 78 // get cluster and local pointer on reference process 79 xptr_t ref_xp = process->ref_xp; 80 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 81 cxy_t ref_cxy = GET_CXY( ref_xp ); 82 83 // use extended pointer on CWD inode 84 root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) ); 85 } 86 87 // call relevant VFS function 88 error = vfs_mkdir( root_inode_xp , kbuf , rights ); 89 90 if( error ) 91 { 92 93 #if DEBUG_SYSCALLS_ERROR 94 printk("\n[ERROR] in %s : cannot create directory <%s>\n", __FUNCTION__, kbuf ); 95 #endif 56 96 this->errno = ENFILE; 57 97 return -1; 58 98 } 59 99 60 printk("\n[ERROR] in %s : not implemented yet\n", __FUNCTION__ ); 61 return -1; 62 63 // copy pathname in kernel space 64 hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 100 #if (DEBUG_SYS_MKDIR || CONFIG_INSTRUMENTATION_SYSCALLS) 101 uint64_t tm_end = hal_get_cycles(); 102 #endif 65 103 66 // get cluster and local pointer on reference process 67 // xptr_t ref_xp = process->ref_xp; 68 // process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 69 // cxy_t ref_cxy = GET_CXY( ref_xp ); 70 71 // get extended pointer on cwd inode 72 // xptr_t cwd_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) ); 73 74 // get the cwd lock in read mode from reference process 75 // remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 76 77 // call the relevant VFS function 78 // error = vfs_mkdir( cwd_xp, 79 // kbuf, 80 // mode ); 81 82 // release the cwd lock 83 // remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 84 85 if( error ) 86 { 87 printk("\n[ERROR] in %s : cannot create directory %s\n", 88 __FUNCTION__ , kbuf ); 89 this->errno = error; 90 return -1; 91 } 104 #if DEBUG_SYS_MKDIR 105 if( DEBUG_SYS_MKDIR < tm_end ) 106 printk("\n[%s] thread[%x,%x] exit for <%s> / cycle %d\n", 107 __FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_end ); 108 #endif 109 110 #if CONFIG_INSTRUMENTATION_SYSCALLS 111 hal_atomic_add( &syscalls_cumul_cost[SYS_MKDIR] , tm_end - tm_start ); 112 hal_atomic_add( &syscalls_occurences[SYS_MKDIR] , 1 ); 113 #endif 92 114 93 115 return 0; 94 } 116 117 } // end sys_mkdir() -
trunk/kernel/syscalls/sys_open.c
r604 r610 40 40 { 41 41 error_t error; 42 xptr_t file_xp; // extended pointer on vfs_file_t 43 uint32_t file_id; // file descriptor index 42 xptr_t file_xp; // extended pointer on vfs_file_t 43 uint32_t file_id; // file descriptor index 44 xptr_t root_inode_xp; // extended pointer on path root inode 45 44 46 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 45 47 … … 88 90 cxy_t ref_cxy = GET_CXY( ref_xp ); 89 91 90 // get the cwd lock in read mode from reference process 91 remote_rwlock_rd_acquire( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 92 // compute root inode for path 93 if( kbuf[0] == '/' ) // absolute path 94 { 95 // use extended pointer on VFS root inode 96 root_inode_xp = process->vfs_root_xp; 97 } 98 else // relative path 99 { 100 // use extended pointer on CWD inode 101 root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) ); 102 } 92 103 93 104 // call the relevant VFS function 94 error = vfs_open( process,105 error = vfs_open( root_inode_xp, 95 106 kbuf, 107 ref_xp, 96 108 flags, 97 109 mode, 98 110 &file_xp, 99 111 &file_id ); 100 101 // release the cwd lock102 remote_rwlock_rd_release( XPTR( ref_cxy , &ref_ptr->cwd_lock ) );103 112 104 113 if( error ) -
trunk/kernel/syscalls/sys_opendir.c
r473 r610 2 2 * sys_opendir.c - open a directory. 3 3 * 4 * Author Alain Greiner (2016,2017 )4 * Author Alain Greiner (2016,2017,2018) 5 5 * 6 6 * Copyright (c) UPMC Sorbonne Universites … … 23 23 24 24 #include <hal_kernel_types.h> 25 #include <hal_uspace.h> 25 26 #include <thread.h> 26 27 #include <process.h> … … 35 36 DIR ** dirp ) 36 37 { 37 printk("\n[ERROR] in %s : not implemented yet\n", __FUNCTION__, pathname, dirp ); 38 return -1; 39 } // end sys opendir() 38 error_t error; 39 vseg_t * vseg; // for user space checking 40 xptr_t root_inode_xp; // extended pointer on path root inode 41 42 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 43 44 thread_t * this = CURRENT_THREAD; 45 process_t * process = this->process; 46 47 #if (DEBUG_SYS_OPENDIR || CONFIG_INSTRUMENTATION_SYSCALLS) 48 uint64_t tm_start = hal_get_cycles(); 49 #endif 50 51 // check DIR buffer in user space 52 error = vmm_get_vseg( process , (intptr_t)dirp, &vseg ); 53 54 if( error ) 55 { 56 57 #if DEBUG_SYSCALLS_ERROR 58 printk("\n[ERROR] in %s / thread[%x,%x] : DIR buffer %x unmapped\n", 59 __FUNCTION__ , process->pid , this->trdid, dirp ); 60 vmm_display( process , false ); 61 #endif 62 this->errno = EINVAL; 63 return -1; 64 } 65 66 // check pathname length 67 if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) 68 { 69 70 #if DEBUG_SYSCALLS_ERROR 71 printk("\n[ERROR] in %s / thread[%x,%x] : pathname too long\n", 72 __FUNCTION__ , process->pid , this->trdid ); 73 #endif 74 this->errno = ENFILE; 75 return -1; 76 } 77 78 // copy pathname in kernel space 79 hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 80 81 #if DEBUG_SYS_OPENDIR 82 if( DEBUG_SYS_OPENDIR < tm_start ) 83 printk("\n[%s] thread[%x,%x] enter for directory <%s> / cycle %d\n", 84 __FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_start ); 85 #endif 86 87 // compute root inode for path 88 if( kbuf[0] == '/' ) // absolute path 89 { 90 // use extended pointer on VFS root inode 91 root_inode_xp = process->vfs_root_xp; 92 } 93 else // relative path 94 { 95 // get cluster and local pointer on reference process 96 xptr_t ref_xp = process->ref_xp; 97 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 98 cxy_t ref_cxy = GET_CXY( ref_xp ); 99 100 // use extended pointer on CWD inode 101 root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) ); 102 } 103 104 /* 105 // call the relevant VFS function ??? 106 error = vfs_opendir( root_inode_xp, 107 kbuf ); 108 if( error ) 109 { 110 111 #if DEBUG_SYSCALLS_ERROR 112 printk("\n[ERROR] in %s / thread[%x,%x] : cannot open directory <%s>\n", 113 __FUNCTION__ , process->pid , this->trdid , pathname ); 114 #endif 115 this->errno = ENFILE; 116 return -1; 117 } 118 119 // copy to user space ??? 120 */ 121 122 hal_fence(); 123 124 #if (DEBUG_SYS_OPENDIR || CONFIG_INSTRUMENTATION_SYSCALLS) 125 uint64_t tm_end = hal_get_cycles(); 126 #endif 127 128 #if DEBUG_SYS_OPENDIR 129 if( DEBUG_SYS_OPENDIR < tm_end ) 130 printk("\n[%s] thread[%x,%x] exit for directory <%s> / cycle %d\n", 131 __FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_end ); 132 #endif 133 134 #if CONFIG_INSTRUMENTATION_SYSCALLS 135 hal_atomic_add( &syscalls_cumul_cost[SYS_OPENDIR] , tm_end - tm_start ); 136 hal_atomic_add( &syscalls_occurences[SYS_OPENDIR] , 1 ); 137 #endif 138 139 return 0; 140 141 } // end sys_opendir() -
trunk/kernel/syscalls/sys_read.c
r604 r610 78 78 #if DEBUG_SYS_READ 79 79 if( DEBUG_SYS_READ < tm_start ) 80 printk("\n[ DBG] %s :thread[%x,%x] enter / vaddr %x / count %d / cycle %d\n",80 printk("\n[%s] thread[%x,%x] enter / vaddr %x / count %d / cycle %d\n", 81 81 __FUNCTION__, process->pid, this->trdid, vaddr, count, (uint32_t)tm_start ); 82 82 #endif … … 246 246 #if DEBUG_SYS_READ 247 247 if( DEBUG_SYS_READ < tm_end ) 248 printk("\n[ DBG] %s :thread[%x,%x] exit / cycle %d\n",248 printk("\n[%s] thread[%x,%x] exit / cycle %d\n", 249 249 __FUNCTION__ , process->pid, this->trdid, (uint32_t)tm_end ); 250 250 #endif -
trunk/kernel/syscalls/sys_stat.c
r604 r610 1 1 /* 2 * sys_stat.c - Return statistics on a file or directory.2 * sys_stat.c - kernel function implementing the "stat" syscall. 3 3 * 4 4 * Author Alain Greiner (2016,2017,2018) … … 41 41 vseg_t * vseg; // for user space checking 42 42 struct stat k_stat; // in kernel space 43 xptr_t inode_xp; // extended pointer on target inode43 xptr_t root_inode_xp; // extended pointer on path root inode 44 44 45 45 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; … … 59 59 60 60 #if DEBUG_SYSCALLS_ERROR 61 printk("\n[ERROR] in %s / thread[%x,%x] : stat structure unmapped\n",62 __FUNCTION__ , process->pid , this->trdid );61 printk("\n[ERROR] in %s / thread[%x,%x] : stat structure %x unmapped\n", 62 __FUNCTION__ , process->pid , this->trdid, u_stat ); 63 63 vmm_display( process , false ); 64 64 #endif … … 88 88 #endif 89 89 90 // get cluster and local pointer on reference process 91 xptr_t ref_xp = process->ref_xp; 92 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 93 cxy_t ref_cxy = GET_CXY( ref_xp ); 90 // compute root inode for path 91 if( kbuf[0] == '/' ) // absolute path 92 { 93 // use extended pointer on VFS root inode 94 root_inode_xp = process->vfs_root_xp; 95 } 96 else // relative path 97 { 98 // get cluster and local pointer on reference process 99 xptr_t ref_xp = process->ref_xp; 100 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 101 cxy_t ref_cxy = GET_CXY( ref_xp ); 94 102 95 // get extended pointer on cwd inode 96 xptr_t cwd_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) ); 97 98 // get the cwd lock in read mode from reference process 99 remote_rwlock_rd_acquire( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 100 101 // get extended pointer on remote file descriptor 102 error = vfs_lookup( cwd_xp, 103 kbuf, 104 0, 105 &inode_xp ); 106 107 // release the cwd lock 108 remote_rwlock_rd_release( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 109 110 if( error ) 111 { 112 113 #if DEBUG_SYSCALLS_ERROR 114 printk("\n[ERROR] in %s / thread[%x,%x] : cannot found file <%s>\n", 115 __FUNCTION__ , process->pid , this->trdid , pathname ); 116 #endif 117 this->errno = ENFILE; 118 return -1; 103 // use extended pointer on CWD inode 104 root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) ); 119 105 } 120 106 121 #if (DEBUG_SYS_STAT & 1) 122 if( DEBUG_SYS_STAT < tm_start ) 123 printk("\n[%s] thread[%x,%x] got inode %x in cluster %x for <%s>\n", 124 __FUNCTION__, process->pid, this->trdid, GET_PTR(inode_xp), GET_CXY(inode_xp), kbuf ); 125 #endif 126 127 // call VFS function to get stat info 128 error = vfs_stat( inode_xp, 129 &k_stat ); 107 // call the relevant VFS function 108 error = vfs_stat( root_inode_xp, 109 kbuf, 110 &k_stat ); 130 111 if( error ) 131 112 { … … 139 120 } 140 121 141 #if (DEBUG_SYS_STAT & 1)142 if( DEBUG_SYS_STAT < tm_start )143 printk("\n[%s] thread[%x,%x] set kstat : inum %d / size %d / mode %d\n",144 __FUNCTION__, process->pid, this->trdid, k_stat.st_ino, k_stat.st_size, k_stat.st_mode );145 #endif146 147 122 // copy k_stat to u_stat 148 123 hal_copy_to_uspace( u_stat , &k_stat , sizeof(struct stat) ); -
trunk/kernel/syscalls/sys_unlink.c
r604 r610 1 1 /* 2 * sys_unlink.c - file unlink a file2 * sys_unlink.c - unlink a file or directorya from VFS 3 3 * 4 4 * Author Alain Greiner (2016,2017,2018) … … 37 37 { 38 38 error_t error; 39 xptr_t root_inode_xp; // extended pointer on path root inode 40 39 41 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 40 42 … … 66 68 #endif 67 69 68 // get cluster and local pointer on reference process 69 xptr_t ref_xp = process->ref_xp; 70 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 71 cxy_t ref_cxy = GET_CXY( ref_xp ); 70 // compute root inode for path 71 if( kbuf[0] == '/' ) // absolute path 72 { 73 // use extended pointer on VFS root inode 74 root_inode_xp = process->vfs_root_xp; 75 } 76 else // relative path 77 { 78 // get cluster and local pointer on reference process 79 xptr_t ref_xp = process->ref_xp; 80 process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); 81 cxy_t ref_cxy = GET_CXY( ref_xp ); 72 82 73 // get the cwd lock in write mode from reference process 74 remote_rwlock_wr_acquire( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 83 // use extended pointer on CWD inode 84 root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) ); 85 } 75 86 76 // get extended pointer on cwd inode 77 xptr_t cwd_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) ); 78 79 // call relevant VFS function 80 error = vfs_unlink( cwd_xp , kbuf ); 81 82 // release the cwd lock in reference process 83 remote_rwlock_wr_release( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 87 // call the relevant VFS function 88 error = vfs_unlink( root_inode_xp , kbuf ); 84 89 85 90 if( error ) -
trunk/kernel/syscalls/sys_write.c
r604 r610 77 77 tm_start = hal_get_cycles(); 78 78 if( DEBUG_SYS_WRITE < tm_start ) 79 printk("\n[ DBG] %s :thread[%x,%x] enter / vaddr %x / count %d / cycle %d\n",79 printk("\n[%s] thread[%x,%x] enter / vaddr %x / count %d / cycle %d\n", 80 80 __FUNCTION__, process->pid, this->trdid, vaddr, count, (uint32_t)tm_start ); 81 81 #endif … … 223 223 #if DEBUG_SYS_WRITE 224 224 if( DEBUG_SYS_WRITE < tm_end ) 225 printk("\n[ DBG] %s :thread[%x,%x] exit / cycle %d\n",225 printk("\n[%s] thread[%x,%x] exit / cycle %d\n", 226 226 __FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end ); 227 227 #endif -
trunk/kernel/syscalls/syscalls.h
r594 r610 170 170 171 171 /****************************************************************************************** 172 * [10] This function implement the exit system call terminating a POSIX process. 173 * It can be called by any thread running in any cluster. 174 * It uses both remote accesses to access the owner process descriptor, and the 175 * RPC_PROCESS_SIGACTION to delete remote process and thread descriptors. 176 * In the present implementation, this function implements actually the _exit(): 177 * - it does not flush open output streams. 178 * - it does not close open streams. 179 ****************************************************************************************** 180 * @ status : terminaison status (not used in present implementation). 181 *****************************************************************************************/ 182 int sys_exit( uint32_t status ); 172 * [10] This function causes the file named <old> to be renamed as <new>. 173 * If new exists, it is first removed. Both old and new must be of the same type (both 174 * must be either directories or non-directories) and must reside on the same file system. 175 * It guarantees that an instance of <new> will always exist, even if the system should 176 * crash in the middle of the operation. 177 ****************************************************************************************** 178 * @ old : old file name. 179 * @ new : new file name. 180 * @ return 0 if success / return -1 if failure. 181 *****************************************************************************************/ 182 int sys_rename( char *old, 183 char *new ); 183 184 184 185 /****************************************************************************************** … … 301 302 302 303 /****************************************************************************************** 303 * [21] This function creates a new directory in file system. 304 ****************************************************************************************** 305 * @ pathname : pathname (can be relative or absolute). 306 * @ mode : access rights (as defined in chmod). 307 * @ return 0 if success / returns -1 if failure. 308 *****************************************************************************************/ 309 int sys_mkdir( char * pathname, 310 uint32_t mode ); 304 * [21] This function implements the "mkdir" system call, creating a new directory in 305 * the file system, as defined by the <pathname> argument, with the access permission 306 * defined by the <rights> argument. All nodes but the last in the pathname must exist. 307 * It can be called by any thread running in any cluster. 308 ****************************************************************************************** 309 * @ pathname : pathname defining the new directory location in file system. 310 * @ rights : access rights (non used yet). 311 * @ return 0 if success / return -1 if failure. 312 *****************************************************************************************/ 313 int sys_mkdir( char * pathname, 314 uint32_t rights ); 311 315 312 316 /****************************************************************************************** … … 653 657 uint32_t * is_fg ); 654 658 659 /****************************************************************************************** 660 * [50] This function implements the exit system call terminating a POSIX process. 661 * It can be called by any thread running in any cluster. 662 * It uses both remote accesses to access the owner process descriptor, and the 663 * RPC_PROCESS_SIGACTION to delete remote process and thread descriptors. 664 * In the present implementation, this function implements actually the _exit(): 665 * - it does not flush open output streams. 666 * - it does not close open streams. 667 ****************************************************************************************** 668 * @ status : terminaison status. 669 *****************************************************************************************/ 670 int sys_exit( uint32_t status ); 671 655 672 #endif // _SYSCALLS_H_
Note: See TracChangeset
for help on using the changeset viewer.