[1] | 1 | /* |
---|
[23] | 2 | * sys_mkfifo.c - creates a named FIFO file. |
---|
[304] | 3 | * |
---|
[670] | 4 | * Author Alain Greiner (2016,2017,2018,2019,2020) |
---|
[1] | 5 | * |
---|
[23] | 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
[1] | 7 | * |
---|
[23] | 8 | * This file is part of ALMOS-MKH. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
[1] | 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
[23] | 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
[1] | 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
[23] | 20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
[1] | 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
[457] | 24 | #include <hal_kernel_types.h> |
---|
[23] | 25 | #include <hal_uspace.h> |
---|
| 26 | #include <printk.h> |
---|
[1] | 27 | #include <vfs.h> |
---|
[23] | 28 | #include <process.h> |
---|
[1] | 29 | #include <thread.h> |
---|
| 30 | |
---|
[23] | 31 | //////////////////////////////////// |
---|
| 32 | int sys_mkfifo ( char * pathname, |
---|
[670] | 33 | uint32_t mode ) |
---|
[1] | 34 | { |
---|
[670] | 35 | vseg_t * vseg; |
---|
| 36 | error_t error; |
---|
| 37 | xptr_t root_inode_xp; |
---|
| 38 | char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; |
---|
[1] | 39 | |
---|
[670] | 40 | thread_t * this = CURRENT_THREAD; |
---|
| 41 | process_t * process = this->process; |
---|
[1] | 42 | |
---|
[670] | 43 | #if DEBUG_SYS_MKFIFO || DEBUG_SYSCALLS_ERROR || CONFIG_INSTRUMENTATION_SYSCALLS |
---|
[637] | 44 | uint64_t tm_start = hal_get_cycles(); |
---|
| 45 | #endif |
---|
| 46 | |
---|
| 47 | #if DEBUG_SYS_MKFIFO |
---|
| 48 | if( DEBUG_SYS_MKFIFO < tm_end ) |
---|
| 49 | printk("\n[%s] thread[%x,%x] enter for <%s> / cycle %d\n", |
---|
[670] | 50 | __FUNCTION__, process->pid, this->trdid, pathname, (uint32_t)tm_start ); |
---|
[637] | 51 | #endif |
---|
| 52 | |
---|
[670] | 53 | // check pathname in user space |
---|
| 54 | if( vmm_get_vseg( process, (intptr_t)pathname , &vseg ) ) |
---|
| 55 | { |
---|
[637] | 56 | |
---|
| 57 | #if DEBUG_SYSCALLS_ERROR |
---|
[670] | 58 | if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) |
---|
| 59 | printk("\n[ERROR] in %s : user buffer unmapped %x for thread[%x,%x]\n", |
---|
| 60 | __FUNCTION__ , (intptr_t)pathname , process->pid, this->trdid ); |
---|
[637] | 61 | #endif |
---|
[670] | 62 | this->errno = EINVAL; |
---|
[23] | 63 | return -1; |
---|
[670] | 64 | } |
---|
[23] | 65 | |
---|
[407] | 66 | // check pathname length |
---|
| 67 | if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) |
---|
[23] | 68 | { |
---|
[637] | 69 | |
---|
| 70 | #if DEBUG_SYSCALLS_ERROR |
---|
[670] | 71 | if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) |
---|
| 72 | printk("\n[ERROR] in %s : pathname too long for thread[%x,%x]\n", |
---|
| 73 | __FUNCTION__ , process->pid , this->trdid ); |
---|
[637] | 74 | #endif |
---|
[304] | 75 | this->errno = ENFILE; |
---|
[23] | 76 | return -1; |
---|
| 77 | } |
---|
| 78 | |
---|
[407] | 79 | // copy pathname in kernel space |
---|
[637] | 80 | hal_strcpy_from_uspace( XPTR( local_cxy , kbuf ), |
---|
| 81 | pathname, |
---|
| 82 | CONFIG_VFS_MAX_PATH_LENGTH ); |
---|
[407] | 83 | |
---|
[670] | 84 | #if DEBUG_SYS_MKFIFO |
---|
| 85 | if( DEBUG_SYS_MKFIFO < tm_end ) |
---|
| 86 | printk("\n[%s] thread[%x,%x] enter for <%s> / cycle %d\n", |
---|
| 87 | __FUNCTION__, process->pid, this->trdid, kbuf, (uint32_t)tm_start ); |
---|
| 88 | #endif |
---|
| 89 | |
---|
| 90 | // get cluster and local pointer on reference process |
---|
| 91 | xptr_t ref_xp = process->ref_xp; |
---|
| 92 | process_t * ref_ptr = GET_PTR( ref_xp ); |
---|
| 93 | cxy_t ref_cxy = GET_CXY( ref_xp ); |
---|
[23] | 94 | |
---|
[670] | 95 | // get extended pointer on root inode in path |
---|
| 96 | if( kbuf[0] == '/' ) // absolute path |
---|
| 97 | { |
---|
| 98 | // use extended pointer on VFS root inode |
---|
| 99 | root_inode_xp = process->vfs_root_xp; |
---|
| 100 | } |
---|
| 101 | else // relative path |
---|
| 102 | { |
---|
| 103 | // use extended pointer on CWD inode |
---|
| 104 | root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) ); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | // call the relevant VFS function |
---|
| 108 | error = vfs_mkfifo( root_inode_xp, |
---|
| 109 | kbuf, |
---|
| 110 | mode ); |
---|
| 111 | if( error ) |
---|
| 112 | { |
---|
| 113 | |
---|
| 114 | #if DEBUG_SYSCALLS_ERROR |
---|
| 115 | if( DEBUG_SYSCALLS_ERROR < (uint32_t)tm_start ) |
---|
| 116 | printk("\n[ERROR] in %s : thread[%x,%x] cannot create node in VFS for <%s> path\n", |
---|
| 117 | __FUNCTION__ , process->pid , this->trdid , kbuf ); |
---|
| 118 | #endif |
---|
| 119 | this->errno = ENFILE; |
---|
| 120 | return -1; |
---|
| 121 | } |
---|
| 122 | |
---|
[637] | 123 | #if (DEBUG_SYS_MKFIFO || CONFIG_INSTRUMENTATION_SYSCALLS) |
---|
| 124 | uint64_t tm_end = hal_get_cycles(); |
---|
| 125 | #endif |
---|
[23] | 126 | |
---|
[637] | 127 | #if DEBUG_SYS_MKFIFO |
---|
| 128 | if( DEBUG_SYS_MKFIFO < tm_end ) |
---|
| 129 | printk("\n[%s] thread[%x,%x] exit for <%s> / cycle %d\n", |
---|
| 130 | __FUNCTION__, process->pid, this->trdid, pathname, (uint32_t)tm_end ); |
---|
| 131 | #endif |
---|
| 132 | |
---|
| 133 | #if CONFIG_INSTRUMENTATION_SYSCALLS |
---|
| 134 | hal_atomic_add( &syscalls_cumul_cost[SYS_MKFIFO] , tm_end - tm_start ); |
---|
| 135 | hal_atomic_add( &syscalls_occurences[SYS_MKFIFO] , 1 ); |
---|
| 136 | #endif |
---|
[304] | 137 | |
---|
[670] | 138 | return 0; |
---|
| 139 | |
---|
[23] | 140 | } // end sys_mkfifo() |
---|