nfs-ganesha 1.4

9p_mknod.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 <sys/stat.h>
00047 #include "nfs_core.h"
00048 #include "log.h"
00049 #include "cache_inode.h"
00050 #include "fsal.h"
00051 #include "9p.h"
00052 
00053 int _9p_mknod( _9p_request_data_t * preq9p, 
00054                   void  * pworker_data,
00055                   u32 * plenout, 
00056                   char * preply)
00057 {
00058   char * cursor = preq9p->_9pmsg + _9P_HDR_SIZE + _9P_TYPE_SIZE ;
00059 
00060   u16 * msgtag = NULL ;
00061   u32 * fid    = NULL ;
00062   u32  * mode  = NULL ;
00063   u32  * gid   = NULL ;
00064   u32  * major = NULL ;
00065   u32  * minor = NULL ;
00066   u16  * name_len = NULL ;
00067   char * name_str = NULL ;
00068 
00069   _9p_fid_t * pfid = NULL ;
00070   _9p_qid_t qid_newobj ;
00071 
00072   cache_entry_t       * pentry_newobj = NULL ;
00073   fsal_name_t           obj_name ; 
00074   fsal_attrib_list_t    fsalattr ;
00075   cache_inode_status_t  cache_status ;
00076   cache_inode_file_type_t nodetype;
00077   cache_inode_create_arg_t create_arg;
00078 
00079   if ( !preq9p || !pworker_data || !plenout || !preply )
00080    return -1 ;
00081 
00082   memset(&create_arg, 0, sizeof(create_arg));
00083 
00084   /* Get data */
00085   _9p_getptr( cursor, msgtag, u16 ) ; 
00086 
00087   _9p_getptr( cursor, fid,    u32 ) ; 
00088   _9p_getstr( cursor, name_len, name_str ) ;
00089   _9p_getptr( cursor, mode,   u32 ) ;
00090   _9p_getptr( cursor, major,  u32 ) ;
00091   _9p_getptr( cursor, minor,  u32 ) ;
00092   _9p_getptr( cursor, gid,    u32 ) ;
00093 
00094   LogDebug( COMPONENT_9P, "TMKNOD: tag=%u fid=%u name=%.*s mode=0%o major=%u minor=%u gid=%u",
00095             (u32)*msgtag, *fid, *name_len, name_str, *mode, *major, *minor, *gid ) ;
00096 
00097   if( *fid >= _9P_FID_PER_CONN )
00098    return _9p_rerror( preq9p, msgtag, ERANGE, plenout, preply ) ;
00099  
00100   pfid = &preq9p->pconn->fids[*fid] ;
00101 
00102   snprintf( obj_name.name, FSAL_MAX_NAME_LEN, "%.*s", *name_len, name_str ) ;
00103   obj_name.len = *name_len + 1 ;
00104 
00105   /* Check for bad type */
00106   if( !( *mode & (S_IFCHR|S_IFBLK|S_IFIFO|S_IFSOCK) ) )
00107    return _9p_rerror( preq9p, msgtag, EINVAL, plenout, preply ) ;
00108 
00109   /* Set the nodetype */
00110   if( *mode &  S_IFCHR  ) nodetype = CHARACTER_FILE ;
00111   if( *mode &  S_IFBLK  ) nodetype = BLOCK_FILE ;
00112   if( *mode &  S_IFIFO  ) nodetype = FIFO_FILE ;
00113   if( *mode &  S_IFSOCK ) nodetype = SOCKET_FILE ;
00114 
00115   create_arg.dev_spec.major = *major ;
00116   create_arg.dev_spec.minor = *minor ;
00117 
00118    /* Create the directory */
00120    if( ( pentry_newobj = cache_inode_create( pfid->pentry,
00121                                              &obj_name,
00122                                              nodetype,
00123                                              *mode,
00124                                              &create_arg,
00125                                              &fsalattr,
00126                                              &pfid->fsal_op_context,
00127                                              &cache_status)) == NULL)
00128     return _9p_rerror( preq9p, msgtag, _9p_tools_errno( cache_status ), plenout, preply ) ;
00129 
00130    /* Build the qid */
00131    qid_newobj.type    = _9P_QTTMP ; 
00132    qid_newobj.version = 0 ;
00133    qid_newobj.path    = fsalattr.fileid ;
00134 
00135    /* Build the reply */
00136   _9p_setinitptr( cursor, preply, _9P_RMKNOD ) ;
00137   _9p_setptr( cursor, msgtag, u16 ) ;
00138 
00139   _9p_setqid( cursor, qid_newobj ) ;
00140 
00141   _9p_setendptr( cursor, preply ) ;
00142   _9p_checkbound( cursor, preply, plenout ) ;
00143 
00144   LogDebug( COMPONENT_9P, "TMKNOD: tag=%u fid=%u name=%.*s major=%u minor=%u qid=(type=%u,version=%u,path=%llu)",
00145             (u32)*msgtag, *fid, *name_len, name_str, *major, *minor,
00146             qid_newobj.type, qid_newobj.version, (unsigned long long)qid_newobj.path ) ;
00147 
00148   return 1 ;
00149 }
00150