[1] | 1 | /* |
---|
[23] | 2 | * sys_unlink.c - file unlink |
---|
[305] | 3 | * |
---|
[1] | 4 | * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless |
---|
| 5 | * Copyright (c) 2011,2012 UPMC Sorbonne Universites |
---|
| 6 | * |
---|
| 7 | * This file is part of ALMOS-kernel. |
---|
| 8 | * |
---|
| 9 | * ALMOS-kernel is free software; you can redistribute it and/or modify it |
---|
| 10 | * under the terms of the GNU General Public License as published by |
---|
| 11 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 12 | * |
---|
| 13 | * ALMOS-kernel is distributed in the hope that it will be useful, but |
---|
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 16 | * General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with ALMOS-kernel; if not, write to the Free Software Foundation, |
---|
| 20 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 21 | */ |
---|
| 22 | |
---|
[23] | 23 | #include <hal_types.h> |
---|
| 24 | #include <hal_uspace.h> |
---|
[1] | 25 | #include <vfs.h> |
---|
[23] | 26 | #include <process.h> |
---|
[1] | 27 | #include <thread.h> |
---|
[23] | 28 | #include <printk.h> |
---|
[1] | 29 | |
---|
[23] | 30 | ////////////////////////////////// |
---|
| 31 | int sys_unlink ( char * pathname ) |
---|
[1] | 32 | { |
---|
[305] | 33 | error_t error; |
---|
[23] | 34 | char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; |
---|
[1] | 35 | |
---|
[305] | 36 | thread_t * this = CURRENT_THREAD; |
---|
| 37 | process_t * process = this->process; |
---|
[23] | 38 | |
---|
[407] | 39 | // check pathname length |
---|
| 40 | if( hal_strlen_from_uspace( pathname ) >= CONFIG_VFS_MAX_PATH_LENGTH ) |
---|
[23] | 41 | { |
---|
| 42 | printk("\n[ERROR] in %s : pathname too long\n", __FUNCTION__ ); |
---|
[305] | 43 | this->errno = ENFILE; |
---|
[23] | 44 | return -1; |
---|
| 45 | } |
---|
| 46 | |
---|
[407] | 47 | // copy pathname in kernel space |
---|
| 48 | hal_strcpy_from_uspace( kbuf , pathname , CONFIG_VFS_MAX_PATH_LENGTH ); |
---|
| 49 | |
---|
[23] | 50 | // get cluster and local pointer on reference process |
---|
| 51 | xptr_t ref_xp = process->ref_xp; |
---|
| 52 | process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); |
---|
| 53 | cxy_t ref_cxy = GET_CXY( ref_xp ); |
---|
| 54 | |
---|
| 55 | // get the cwd lock in read mode from reference process |
---|
[305] | 56 | remote_rwlock_rd_lock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); |
---|
[23] | 57 | |
---|
| 58 | // get extended pointer on cwd inode |
---|
| 59 | xptr_t cwd_xp = hal_remote_lwd( XPTR( ref_cxy , &ref_ptr->vfs_cwd_xp ) ); |
---|
| 60 | |
---|
| 61 | // call relevant VFS function |
---|
| 62 | error = vfs_unlink( cwd_xp , kbuf ); |
---|
| 63 | |
---|
| 64 | // release the cwd lock in reference process |
---|
[305] | 65 | remote_rwlock_rd_unlock( XPTR( ref_cxy , &ref_ptr->cwd_lock ) ); |
---|
[23] | 66 | |
---|
[305] | 67 | if( error ) |
---|
| 68 | { |
---|
[23] | 69 | printk("\n[ERROR] in %s : cannot unlink file/dir %s\n", |
---|
| 70 | __FUNCTION__ , pathname ); |
---|
[305] | 71 | this->errno = ENFILE; |
---|
| 72 | return -1; |
---|
| 73 | } |
---|
[23] | 74 | |
---|
[305] | 75 | return 0; |
---|
[23] | 76 | |
---|
| 77 | } // end sys_unlink() |
---|