nfs-ganesha 1.4
|
00001 /* 00002 * vim:expandtab:shiftwidth=8:tabstop=8: 00003 */ 00004 00014 #ifdef HAVE_CONFIG_H 00015 #include "config.h" 00016 #endif 00017 00018 #include "fsal.h" 00019 #include "fsal_internal.h" 00020 #include "fsal_convert.h" 00021 #include "fsal_common.h" 00022 00057 fsal_status_t ZFSFSAL_access(fsal_handle_t * obj_handle, /* IN */ 00058 fsal_op_context_t * p_context, /* IN */ 00059 fsal_accessflags_t access_type, /* IN */ 00060 fsal_attrib_list_t * object_attributes /* [ IN/OUT ] */ 00061 ) 00062 { 00063 creden_t cred; 00064 zfsfsal_handle_t * object_handle = (zfsfsal_handle_t *)obj_handle; 00065 00066 /* sanity checks. 00067 * note : object_attributes is optional in FSAL_access. 00068 */ 00069 if(!object_handle || !p_context) 00070 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_access); 00071 00072 /* Get the right VFS */ 00073 ZFSFSAL_VFS_RDLock(); 00074 libzfswrap_vfs_t *p_vfs = ZFSFSAL_GetVFS(object_handle); 00075 if(!p_vfs) 00076 { 00077 ZFSFSAL_VFS_Unlock(); 00078 Return(ERR_FSAL_NOENT, 0, INDEX_FSAL_access); 00079 } 00080 00081 /* >> convert your fsal access type to your FS access type << */ 00082 int mask = fsal2posix_testperm(access_type); 00083 cred.uid = p_context->credential.user; 00084 cred.gid = p_context->credential.group; 00085 TakeTokenFSCall(); 00086 int rc = libzfswrap_access(p_vfs, &cred, 00087 object_handle->data.zfs_handle, mask); 00088 ReleaseTokenFSCall(); 00089 ZFSFSAL_VFS_Unlock(); 00090 00091 /* >> convert the returned code, an return it on error << */ 00092 if(rc) 00093 Return(posix2fsal_error(rc),0, INDEX_FSAL_access); 00094 00095 /* get attributes if object_attributes is not null. 00096 * If an error occures during getattr operation, 00097 * an error bit is set in the output structure. 00098 */ 00099 if(object_attributes) 00100 { 00101 fsal_status_t status; 00102 00103 status = ZFSFSAL_getattrs(object_handle, p_context, object_attributes); 00104 00105 /* on error, we set a special bit in the mask. */ 00106 if(FSAL_IS_ERROR(status)) 00107 { 00108 FSAL_CLEAR_MASK(object_attributes->asked_attributes); 00109 FSAL_SET_MASK(object_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR); 00110 } 00111 } 00112 00113 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_access); 00114 }