Changeset 305 for trunk/kernel/syscalls/sys_open.c
- Timestamp:
- Jul 31, 2017, 2:46:50 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/syscalls/sys_open.c
r23 r305 1 1 /* 2 2 * sys_open.c - open a file. 3 * 3 * 4 4 * Author Alain Greiner (2016,2017) 5 5 * … … 38 38 uint32_t mode ) 39 39 { 40 41 error_t error; 42 xptr_t file_xp; // extended pointer on vfs_file_t 43 uint32_t file_id; // file descriptor index 44 uint32_t length; // pathname length (bytes) 40 error_t error; 41 xptr_t file_xp; // extended pointer on vfs_file_t 42 uint32_t file_id; // file descriptor index 45 43 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 46 44 47 thread_t * this = CURRENT_THREAD; 48 process_t * process = this->process; 49 50 if( pathname == NULL ) 51 { 52 printk("\n[ERROR] in %s : pathname is NULL\n", __FUNCTION__ ); 53 this->errno = EINVAL; 54 return -1; 55 } 45 thread_t * this = CURRENT_THREAD; 46 process_t * process = this->process; 56 47 57 48 // check fd_array not full 58 59 49 if( process_fd_array_full() ) 50 { 60 51 printk("\n[ERROR] in %s : file descriptor array full for process %x\n", 61 52 __FUNCTION__ , process->pid ); 62 53 this->errno = ENFILE; 63 54 return -1; 64 } 65 66 // get pathname length 67 length = hal_strlen_from_uspace( pathname ); 55 } 68 56 69 if( length >= CONFIG_VFS_MAX_PATH_LENGTH ) 57 // get pathname copy in kernel space 58 error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 59 60 if( error ) 70 61 { 71 62 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 72 63 this->errno = ENFILE; 73 64 return -1; 74 65 } 75 76 // get pathname copy in kernel space77 hal_copy_from_uspace( kbuf, pathname, length );78 66 79 67 // get cluster and local pointer on reference process … … 84 72 // get extended pointer on cwd inode 85 73 xptr_t cwd_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) ); 86 74 87 75 // get the cwd lock in read mode from reference process 88 76 remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 89 77 90 78 // call the relevant VFS function 91 79 error = vfs_open( cwd_xp, 92 80 kbuf, 93 81 flags, … … 97 85 98 86 // release the cwd lock 99 87 remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 100 88 101 102 89 if( error ) 90 { 103 91 printk("\n[ERROR] in %s : cannot create file descriptor\n", __FUNCTION__ ); 104 105 106 92 this->errno = ENFILE; 93 return -1; 94 } 107 95 108 96 // update local fd_array 109 97 remote_spinlock_lock( XPTR( local_cxy , &process->fd_array.lock ) ); 110 98 process->fd_array.array[file_id] = file_xp; 111 99 remote_spinlock_unlock( XPTR( local_cxy , &process->fd_array.lock ) ); 112 100 113 101 return file_id; 114 102 }
Note: See TracChangeset
for help on using the changeset viewer.