Changeset 305
- Timestamp:
- Jul 31, 2017, 2:46:50 PM (7 years ago)
- Location:
- trunk/kernel/syscalls
- Files:
-
- 3 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 } -
trunk/kernel/syscalls/sys_rmdir.c
r23 r305 35 35 { 36 36 error_t error; 37 paddr_t paddr;38 uint32_t length;39 37 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 40 38 … … 42 40 process_t * process = this->process; 43 41 44 // check pathname in userspace45 error = vmm_v2p_translate( false , pathname , &paddr);42 // get pathname copy in kernel space 43 error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 46 44 47 if( error ) 48 { 49 printk("\n[ERROR] in %s : user buffer unmapped for thread %x in process %x\n", 50 __FUNCTION__ , this->trdid , process->pid ); 51 this->errno = EINVAL; 52 return -1; 53 } 54 55 // get pathname length 56 length = hal_strlen_from_uspace( pathname ); 57 58 if( length >= CONFIG_VFS_MAX_PATH_LENGTH ) 45 if( error ) 59 46 { 60 47 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); … … 62 49 return -1; 63 50 } 64 65 // get pathname copy in kernel space66 hal_copy_from_uspace( kbuf, pathname, length );67 51 68 52 // get cluster and local pointer on reference process -
trunk/kernel/syscalls/sys_unlink.c
r23 r305 1 1 /* 2 2 * sys_unlink.c - file unlink 3 * 3 * 4 4 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless 5 5 * Copyright (c) 2011,2012 UPMC Sorbonne Universites … … 31 31 int sys_unlink ( char * pathname ) 32 32 { 33 error_t error; 34 uint32_t length; 33 error_t error; 35 34 char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; 36 35 37 38 36 thread_t * this = CURRENT_THREAD; 37 process_t * process = this->process; 39 38 40 // get pathname length41 length = hal_strlen_from_uspace( pathname);39 // get pathname copy in kernel space 40 error = hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); 42 41 43 if( length >= CONFIG_VFS_MAX_PATH_LENGTH)42 if( error ) 44 43 { 45 44 printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); 46 45 this->errno = ENFILE; 47 46 return -1; 48 47 } 49 50 // get pathname copy in kernel space51 hal_copy_from_uspace( kbuf, pathname, length );52 48 53 49 // get cluster and local pointer on reference process … … 57 53 58 54 // get the cwd lock in read mode from reference process 59 55 remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 60 56 61 57 // get extended pointer on cwd inode … … 66 62 67 63 // release the cwd lock in reference process 68 64 remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); 69 65 70 71 66 if( error ) 67 { 72 68 printk("\n[ERROR] in %s : cannot unlink file/dir %s\n", 73 69 __FUNCTION__ , pathname ); 74 75 76 70 this->errno = ENFILE; 71 return -1; 72 } 77 73 78 74 return 0; 79 75 80 76 } // end sys_unlink()
Note: See TracChangeset
for help on using the changeset viewer.