nfs-ganesha 1.4

fsal_access.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  *
00004  * Copyright (C) 2010, The Linux Box Corporation
00005  * Contributor : Adam C. Emerson <aemerson@linuxbox.com>
00006  *
00007  * Some portions Copyright CEA/DAM/DIF  (2008)
00008  * contributeur : Philippe DENIEL   philippe.deniel@cea.fr
00009  *                Thomas LEIBOVICI  thomas.leibovici@cea.fr
00010  *
00011  *
00012  * This program is free software; you can redistribute it and/or
00013  * modify it under the terms of the GNU Lesser General Public
00014  * License as published by the Free Software Foundation; either
00015  * version 3 of the License, or (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020  * Lesser General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU Lesser General Public
00023  * License along with this library; if not, write to the Free Software
00024  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00025  *
00026  * -------------
00027  */
00028 
00035 #ifdef HAVE_CONFIG_H
00036 #include "config.h"
00037 #endif
00038 
00039 #include "fsal.h"
00040 #include "fsal_internal.h"
00041 #include "fsal_convert.h"
00042 
00077 fsal_status_t CEPHFSAL_access(fsal_handle_t * exthandle,
00078                               fsal_op_context_t * extcontext,
00079                               fsal_accessflags_t access_type,
00080                               fsal_attrib_list_t * object_attributes)
00081 {
00082   fsal_status_t status;
00083 
00084   /* sanity checks.
00085    * note : object_attributes is optionnal in VFSFSAL_getattrs.
00086    */
00087   if(!exthandle || !extcontext)
00088     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_access);
00089 
00090   /*
00091    * If an error occures during getattr operation,
00092    * it is returned, even though the access operation succeeded.
00093    */
00094 
00095   if(object_attributes)
00096     {
00097       FSAL_SET_MASK(object_attributes->asked_attributes,
00098                     FSAL_ATTR_OWNER | FSAL_ATTR_GROUP |
00099                     FSAL_ATTR_ACL | FSAL_ATTR_MODE);
00100       status = CEPHFSAL_getattrs(exthandle, extcontext, object_attributes);
00101 
00102       /* on error, we set a special bit in the mask. */
00103       if(FSAL_IS_ERROR(status))
00104         {
00105           FSAL_CLEAR_MASK(object_attributes->asked_attributes);
00106           FSAL_SET_MASK(object_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
00107           Return(status.major, status.minor, INDEX_FSAL_access);
00108         }
00109 
00110       status =
00111            fsal_internal_testAccess((cephfsal_op_context_t*) extcontext,
00112                                     access_type, NULL,
00113                                     object_attributes);
00114     }
00115   else
00116     {                           /* p_object_attributes is NULL */
00117       fsal_attrib_list_t attrs;
00118 
00119       FSAL_CLEAR_MASK(attrs.asked_attributes);
00120       FSAL_SET_MASK(attrs.asked_attributes,
00121                     FSAL_ATTR_OWNER | FSAL_ATTR_GROUP |
00122                     FSAL_ATTR_ACL | FSAL_ATTR_MODE);
00123 
00124       status = CEPHFSAL_getattrs(exthandle, extcontext, &attrs);
00125 
00126       /* on error, we set a special bit in the mask. */
00127       if(FSAL_IS_ERROR(status))
00128         Return(status.major, status.minor, INDEX_FSAL_access);
00129 
00130       status = fsal_internal_testAccess((cephfsal_op_context_t*) extcontext,
00131                                         access_type, NULL, &attrs);
00132     }
00133 
00134   Return(status.major, status.minor, INDEX_FSAL_access);
00135 }