nfs-ganesha 1.4

9p_renameat.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  *
00004  * Copyright CEA/DAM/DIF  (2011)
00005  * contributeur : Philippe DENIEL   philippe.deniel@cea.fr
00006  *                Thomas LEIBOVICI  thomas.leibovici@cea.fr
00007  *
00008  *
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 3 of the License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022  *
00023  * ---------------------------------------
00024  */
00025 
00035 #ifdef HAVE_CONFIG_H
00036 #include "config.h"
00037 #endif
00038 
00039 #ifdef _SOLARIS
00040 #include "solaris_port.h"
00041 #endif
00042 
00043 #include <stdio.h>
00044 #include <string.h>
00045 #include <pthread.h>
00046 #include "nfs_core.h"
00047 #include "log.h"
00048 #include "cache_inode.h"
00049 #include "fsal.h"
00050 #include "9p.h"
00051 
00052 int _9p_renameat( _9p_request_data_t * preq9p, 
00053                 void  * pworker_data,
00054                 u32 * plenout, 
00055                 char * preply)
00056 {
00057   char * cursor = preq9p->_9pmsg + _9P_HDR_SIZE + _9P_TYPE_SIZE ;
00058 
00059   u16  * msgtag      = NULL ;
00060   u32  * oldfid      = NULL ;
00061   u16  * oldname_len = NULL ;
00062   char * oldname_str = NULL ;
00063   u32  * newfid      = NULL ;
00064   u16  * newname_len = NULL ;
00065   char * newname_str = NULL ;
00066 
00067   _9p_fid_t * poldfid = NULL ;
00068   _9p_fid_t * pnewfid = NULL ;
00069 
00070   fsal_attrib_list_t    oldfsalattr ;
00071   fsal_attrib_list_t    newfsalattr ;
00072 
00073   cache_inode_status_t  cache_status ;
00074 
00075   fsal_name_t           oldname ;
00076   fsal_name_t           newname ;
00077 
00078   if ( !preq9p || !pworker_data || !plenout || !preply )
00079    return -1 ;
00080 
00081   /* Get data */
00082   _9p_getptr( cursor, msgtag, u16 ) ; 
00083 
00084   _9p_getptr( cursor, oldfid,   u32 ) ; 
00085   _9p_getstr( cursor, oldname_len, oldname_str ) ;
00086   _9p_getptr( cursor, newfid,   u32 ) ; 
00087   _9p_getstr( cursor, newname_len, newname_str ) ;
00088 
00089   LogDebug( COMPONENT_9P, "TRENAMEAT: tag=%u oldfid=%u oldname=%.*s newfid=%u newname=%.*s",
00090             (u32)*msgtag, *oldfid, *oldname_len, oldname_str, *newfid, *newname_len, newname_str ) ;
00091 
00092   if( *oldfid >= _9P_FID_PER_CONN )
00093    return _9p_rerror( preq9p, msgtag, ERANGE, plenout, preply ) ;
00094 
00095   poldfid = &preq9p->pconn->fids[*oldfid] ;
00096 
00097   if( *newfid >= _9P_FID_PER_CONN )
00098    return _9p_rerror( preq9p, msgtag, ERANGE, plenout, preply ) ;
00099 
00100   pnewfid = &preq9p->pconn->fids[*newfid] ;
00101 
00102   /* Let's do the job */
00103   snprintf( oldname.name, FSAL_MAX_NAME_LEN, "%.*s", *oldname_len, oldname_str ) ;
00104   oldname.len = *oldname_len + 1 ;
00105   snprintf( newname.name, FSAL_MAX_NAME_LEN, "%.*s", *newname_len, newname_str ) ;
00106   newname.len = *newname_len + 1 ;
00107 
00108   if( cache_inode_rename( poldfid->pentry,
00109                           &oldname,
00110                           pnewfid->pentry,
00111                           &newname,
00112                           &oldfsalattr,
00113                           &newfsalattr,
00114                           &poldfid->fsal_op_context, 
00115                           &cache_status) != CACHE_INODE_SUCCESS )
00116     return _9p_rerror( preq9p, msgtag, _9p_tools_errno( cache_status ), plenout, preply ) ;
00117 
00118   /* Build the reply */
00119   _9p_setinitptr( cursor, preply, _9P_RRENAMEAT ) ;
00120   _9p_setptr( cursor, msgtag, u16 ) ;
00121 
00122   _9p_setendptr( cursor, preply ) ;
00123   _9p_checkbound( cursor, preply, plenout ) ;
00124 
00125   LogDebug( COMPONENT_9P, "RRENAMEAT: tag=%u oldfid=%u oldname=%.*s newfid=%u newname=%.*s",
00126             (u32)*msgtag, *oldfid, *oldname_len, oldname_str, *newfid, *newname_len, newname_str ) ;
00127 
00128   return 1 ;
00129 }
00130