nfs-ganesha 1.4

fsal_symlinks.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  *
00004  * Copyright (C) 2010 The Linux Box, Inc.
00005  * Contributor : Adam C. Emerson <aemerson@linuxbox.com>
00006  *
00007  * 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 
00034 #ifdef HAVE_CONFIG_H
00035 #include "config.h"
00036 #endif
00037 
00038 #include "fsal.h"
00039 #include "fsal_internal.h"
00040 #include "fsal_convert.h"
00041 #include <string.h>
00042 
00071 fsal_status_t CEPHFSAL_readlink(fsal_handle_t * exthandle,
00072                                 fsal_op_context_t * extcontext,
00073                                 fsal_path_t * link_content,
00074                                 fsal_attrib_list_t * link_attributes)
00075 {
00076   int rc;
00077   fsal_status_t st;
00078   cephfsal_handle_t* handle = (cephfsal_handle_t*) exthandle;
00079   cephfsal_op_context_t* context = (cephfsal_op_context_t*) extcontext;
00080   char strcontent[FSAL_MAX_PATH_LEN];
00081   int uid = FSAL_OP_CONTEXT_TO_UID(context);
00082   int gid = FSAL_OP_CONTEXT_TO_GID(context);
00083   struct ceph_mount_info *cmount = context->export_context->cmount;
00084 
00085   /* sanity checks.
00086    * note : link_attributes is optional.
00087    */
00088   if(!handle || !context || !link_content)
00089     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_readlink);
00090 
00091   rc = ceph_ll_readlink(cmount,
00092                         VINODE(handle), (char**) &strcontent, uid, gid);
00093 
00094   if (rc < 0)
00095     Return(posix2fsal_error(rc), 0, INDEX_FSAL_open);
00096 
00097   st = FSAL_str2path(strcontent, FSAL_MAX_PATH_LEN, link_content);
00098 
00099   if(FSAL_IS_ERROR(st))
00100     Return(st.major, st.minor, INDEX_FSAL_readlink);
00101 
00102   /* retrieves object attributes, if asked */
00103 
00104   if(link_attributes)
00105     {
00106       fsal_status_t status =
00107         CEPHFSAL_getattrs(exthandle, extcontext, link_attributes);
00108 
00109       if(FSAL_IS_ERROR(status))
00110         {
00111           FSAL_CLEAR_MASK(link_attributes->asked_attributes);
00112           FSAL_SET_MASK(link_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
00113         }
00114 
00115     }
00116   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_readlink);
00117 }
00118 
00153 fsal_status_t CEPHFSAL_symlink(fsal_handle_t * extparent,
00154                                fsal_name_t * linkname,
00155                                fsal_path_t * linkcontent,
00156                                fsal_op_context_t * extcontext,
00157                                fsal_accessmode_t accessmode,
00158                                fsal_handle_t * extlink,
00159                                fsal_attrib_list_t * link_attributes)
00160 {
00161   int rc;
00162   struct stat st;
00163   cephfsal_handle_t* parent = (cephfsal_handle_t*) extparent;
00164   cephfsal_handle_t* link = (cephfsal_handle_t*) extlink;
00165   cephfsal_op_context_t* context = (cephfsal_op_context_t*) extcontext;
00166   int uid = FSAL_OP_CONTEXT_TO_UID(context);
00167   int gid = FSAL_OP_CONTEXT_TO_GID(context);
00168   char strpath[FSAL_MAX_PATH_LEN];
00169   char strname[FSAL_MAX_NAME_LEN];
00170   struct ceph_mount_info *cmount = context->export_context->cmount;
00171 
00172   /* sanity checks.
00173    * note : link_attributes is optional.
00174    */
00175   if(!parent || !context || !link || !linkname || !linkcontent)
00176     Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_symlink);
00177 
00178   FSAL_path2str(linkcontent, strpath, FSAL_MAX_PATH_LEN);
00179   FSAL_name2str(linkname, strname, FSAL_MAX_NAME_LEN);
00180 
00181   /* Tests if symlinking is allowed by configuration. */
00182 
00183   if(!global_fs_info.symlink_support)
00184     Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_symlink);
00185 
00186   rc = ceph_ll_symlink(cmount,
00187                        VINODE(parent), strname, strpath, &st, uid, gid);
00188   if (rc)
00189     Return(posix2fsal_error(rc), 0, INDEX_FSAL_symlink);
00190 
00191   rc = stat2fsal_fh(cmount, &st, link);
00192   if (rc < 0)
00193     Return(posix2fsal_error(rc), 0, INDEX_FSAL_create);
00194 
00195   if(link_attributes)
00196     {
00197       /* convert attributes */
00198       fsal_status_t status = posix2fsal_attributes(&st, link_attributes);
00199       if(FSAL_IS_ERROR(status))
00200         {
00201           FSAL_CLEAR_MASK(link_attributes->asked_attributes);
00202           FSAL_SET_MASK(link_attributes->asked_attributes, FSAL_ATTR_RDATTR_ERR);
00203           Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_symlink);
00204         }
00205     }
00206 
00207   /* OK */
00208   Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_symlink);
00209 }
00210