nfs-ganesha 1.4

9p_getattr.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 u32 zero32 = 0 ;
00054 u64 zero64 = 0LL ;
00055 
00056 int _9p_getattr( _9p_request_data_t * preq9p, 
00057                   void  * pworker_data,
00058                   u32 * plenout, 
00059                   char * preply)
00060 {
00061   char * cursor = preq9p->_9pmsg + _9P_HDR_SIZE + _9P_TYPE_SIZE ;
00062 
00063   u16 * msgtag = NULL ;
00064   u32 * fid    = NULL ;
00065   u64 * request_mask = NULL ;
00066 
00067   _9p_fid_t * pfid = NULL ;
00068 
00069   u64 * valid        = NULL ;
00070   u32   mode         = 0    ; /* Not a pointer */
00071   u32 * uid          = NULL ;
00072   u32 * gid          = NULL ;
00073   u64 * nlink        = NULL ;
00074   u64 * rdev         = NULL ;
00075   u64 * size         = NULL ;
00076   u64   blksize      = 0LL  ; /* Be careful, this one is no pointer */
00077   u64   blocks       = 0LL  ; /* And so does this one...            */
00078   u64 * atime_sec    = NULL ;
00079   u64 * atime_nsec   = NULL ;
00080   u64 * mtime_sec    = NULL ;
00081   u64 * mtime_nsec   = NULL ;
00082   u64 * ctime_sec    = NULL ;
00083   u64 * ctime_nsec   = NULL ;
00084   u64 * btime_sec    = NULL ;
00085   u64 * btime_nsec   = NULL ;
00086   u64 * gen          = NULL ;
00087   u64 * data_version = NULL ;
00088 
00089   if ( !preq9p || !pworker_data || !plenout || !preply )
00090    return -1 ;
00091   /* Get data */
00092   _9p_getptr( cursor, msgtag, u16 ) ; 
00093   _9p_getptr( cursor, fid,    u32 ) ; 
00094   _9p_getptr( cursor, request_mask, u64 ) ; 
00095 
00096   LogDebug( COMPONENT_9P, "TGETATTR: tag=%u fid=%u request_mask=0x%llx",
00097             (u32)*msgtag, *fid, (unsigned long long)*request_mask ) ;
00098  
00099   if( *fid >= _9P_FID_PER_CONN )
00100     return _9p_rerror( preq9p, msgtag, ERANGE, plenout, preply ) ;
00101 
00102   pfid = &preq9p->pconn->fids[*fid] ;
00103 
00104   /* Attach point is found, build the requested attributes */
00105   
00106   valid = request_mask ; /* FSAL covers all 9P attributes */
00107 
00108   if( *request_mask & _9P_GETATTR_RDEV )
00109    {  
00110      mode   = (u32)pfid->pentry->attributes.mode ;
00111      if( pfid->pentry->attributes.type == FSAL_TYPE_DIR )  mode |= __S_IFDIR  ;
00112      if( pfid->pentry->attributes.type == FSAL_TYPE_FILE ) mode |= __S_IFREG  ;
00113      if( pfid->pentry->attributes.type == FSAL_TYPE_LNK )  mode |= __S_IFLNK  ;
00114      if( pfid->pentry->attributes.type == FSAL_TYPE_SOCK ) mode |= __S_IFSOCK ;
00115      if( pfid->pentry->attributes.type == FSAL_TYPE_BLK )  mode |= __S_IFBLK  ;
00116      if( pfid->pentry->attributes.type == FSAL_TYPE_CHR )  mode |= __S_IFCHR  ;
00117      if( pfid->pentry->attributes.type == FSAL_TYPE_FIFO ) mode |= __S_IFIFO  ;
00118    }
00119  else
00120    mode = 0 ;
00121 
00122   uid        = (*request_mask & _9P_GETATTR_UID)    ? (u32 *)&pfid->pentry->attributes.owner:&zero32 ;
00123   gid        = (*request_mask & _9P_GETATTR_GID)    ? (u32 *)&pfid->pentry->attributes.group:&zero32 ;
00124   nlink      = (*request_mask & _9P_GETATTR_NLINK)  ? (u64 *)&pfid->pentry->attributes.numlinks:&zero64 ;  
00125   rdev       = (*request_mask & _9P_GETATTR_RDEV)   ? (u64 *)&pfid->pentry->attributes.rawdev.major:&zero64 ; 
00126   size       = (*request_mask & _9P_GETATTR_SIZE)   ? (u64 *)&pfid->pentry->attributes.filesize:&zero64 ; 
00127   blksize    = (*request_mask & _9P_GETATTR_BLOCKS) ? (u64)_9p_BLK_SIZE:0LL ; 
00128   blocks     = (*request_mask & _9P_GETATTR_BLOCKS) ? (u64)(pfid->pentry->attributes.filesize/_9p_BLK_SIZE):0LL ; 
00129   atime_sec  = (*request_mask & _9P_GETATTR_ATIME ) ? (u64 *)&pfid->pentry->attributes.atime.seconds:&zero64 ;
00130   atime_nsec = &zero64 ;
00131   mtime_sec  = (*request_mask & _9P_GETATTR_MTIME ) ? (u64 *)&pfid->pentry->attributes.mtime.seconds:&zero64 ;
00132   mtime_nsec = &zero64 ;
00133   ctime_sec  = (*request_mask & _9P_GETATTR_CTIME ) ? (u64 *)&pfid->pentry->attributes.ctime.seconds:&zero64 ;
00134   ctime_nsec = &zero64 ;
00135 
00136   /* Not yet supported attributes */
00137   btime_sec    = &zero64 ;
00138   btime_nsec   = &zero64 ;
00139   gen          = &zero64 ;
00140   data_version = &zero64 ;
00141 
00142    /* Build the reply */
00143   _9p_setinitptr( cursor, preply, _9P_RGETATTR ) ;
00144   _9p_setptr( cursor, msgtag, u16 ) ;
00145 
00146   _9p_setptr( cursor, valid,               u64 ) ;
00147   _9p_setqid( cursor, pfid->qid ) ;
00148   _9p_setvalue( cursor, mode,              u32 ) ;
00149   _9p_setptr( cursor, uid,                 u32 ) ;
00150   _9p_setptr( cursor, gid,                 u32 ) ;
00151   _9p_setptr( cursor, nlink,               u64 ) ;
00152   _9p_setptr( cursor, rdev,                u64 ) ;
00153   _9p_setptr( cursor, size,                u64 ) ;
00154   _9p_setvalue( cursor, blksize,           u64 ) ;
00155   _9p_setvalue( cursor, blocks,            u64 ) ;
00156   _9p_setptr( cursor, atime_sec,           u64 ) ;
00157   _9p_setptr( cursor, atime_nsec,          u64 ) ;
00158   _9p_setptr( cursor, mtime_sec,           u64 ) ;
00159   _9p_setptr( cursor, mtime_nsec,          u64 ) ;
00160   _9p_setptr( cursor, ctime_sec,           u64 ) ;
00161   _9p_setptr( cursor, ctime_nsec,          u64 ) ;
00162   _9p_setptr( cursor, btime_sec,           u64 ) ;
00163   _9p_setptr( cursor, btime_nsec,          u64 ) ;
00164   _9p_setptr( cursor, gen,                 u64 ) ;
00165   _9p_setptr( cursor, data_version,        u64 ) ;
00166 
00167   _9p_setendptr( cursor, preply ) ;
00168   _9p_checkbound( cursor, preply, plenout ) ;
00169 
00170   LogDebug( COMPONENT_9P, 
00171             "RGETATTR: tag=%u valid=0x%llx qid=(type=%u,version=%u,path=%llu) mode=0%o uid=%u gid=%u nlink=%llu"
00172             " rdev=%llu size=%llu blksize=%llu blocks=%llu atime=(%llu,%llu) mtime=(%llu,%llu) ctime=(%llu,%llu)"
00173             " btime=(%llu,%llu) gen=%llu, data_version=%llu", 
00174             *msgtag, (unsigned long long)*valid, (u32)pfid->qid.type, pfid->qid.version, (unsigned long long)pfid->qid.path,
00175             mode, *uid, *gid, (unsigned long long)*nlink, (unsigned long long)*rdev, (unsigned long long)*size,
00176             (unsigned long long)blksize, (unsigned long long)blocks,
00177             (unsigned long long)*atime_sec, (unsigned long long)*atime_nsec,
00178             (unsigned long long)*mtime_sec, (unsigned long long)*mtime_nsec, 
00179             (unsigned long long)*ctime_sec, (unsigned long long)*ctime_nsec,    
00180             (unsigned long long)*btime_sec, (unsigned long long)*btime_nsec, 
00181             (unsigned long long)*gen, (unsigned long long)*data_version )  ;
00182   return 1 ;
00183 }
00184