nfs-ganesha 1.4

nfs4_op_readlink.c

Go to the documentation of this file.
00001 /*
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  *
00004  * Copyright CEA/DAM/DIF  (2008)
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 
00037 #ifdef HAVE_CONFIG_H
00038 #include "config.h"
00039 #endif
00040 
00041 #ifdef _SOLARIS
00042 #include "solaris_port.h"
00043 #endif
00044 
00045 #include <stdio.h>
00046 #include <string.h>
00047 #include <pthread.h>
00048 #include <fcntl.h>
00049 #include <sys/file.h>           /* for having FNDELAY */
00050 #include "HashData.h"
00051 #include "HashTable.h"
00052 #include "log.h"
00053 #include "ganesha_rpc.h"
00054 #include "nfs23.h"
00055 #include "nfs4.h"
00056 #include "mount.h"
00057 #include "nfs_core.h"
00058 #include "cache_inode.h"
00059 #include "nfs_exports.h"
00060 #include "nfs_creds.h"
00061 #include "nfs_proto_functions.h"
00062 #include "nfs_proto_tools.h"
00063 #include "nfs_tools.h"
00064 #include "nfs_file_handle.h"
00065 
00083 #define arg_READLINK4 op->nfs_argop4_u.opreadlink
00084 #define res_READLINK4 resp->nfs_resop4_u.opreadlink
00085 
00086 int nfs4_op_readlink(struct nfs_argop4 *op,
00087                      compound_data_t * data, struct nfs_resop4 *resp)
00088 {
00089   char __attribute__ ((__unused__)) funcname[] = "nfs4_op_readlink";
00090 
00091   cache_inode_status_t cache_status;
00092   fsal_path_t          symlink_path;
00093 
00094   resp->resop = NFS4_OP_READLINK;
00095   res_READLINK4.status = NFS4_OK;
00096 
00097   /*
00098    * Do basic checks on a filehandle
00099    * You can readlink only on a link ...
00100    */
00101   res_READLINK4.status = nfs4_sanity_check_FH(data, SYMBOLIC_LINK);
00102   if(res_READLINK4.status != NFS4_OK)
00103     return res_READLINK4.status;
00104 
00105   /* Using cache_inode_readlink */
00106   if(cache_inode_readlink(data->current_entry,
00107                           &symlink_path,
00108                           data->pcontext, &cache_status)
00109      == CACHE_INODE_SUCCESS)
00110     {
00111       /* Alloc read link */
00112 
00113       if((res_READLINK4.READLINK4res_u.resok4.link.utf8string_val =
00114           gsh_malloc(symlink_path.len)) == NULL)
00115         {
00116           res_READLINK4.status = NFS4ERR_INVAL;
00117           return res_READLINK4.status;
00118         }
00119 
00120       /* convert the fsal path to a utf8 string */
00121       if(str2utf8(symlink_path.path, &res_READLINK4.READLINK4res_u.resok4.link)
00122          == -1)
00123         {
00124           res_READLINK4.status = NFS4ERR_INVAL;
00125           return res_READLINK4.status;
00126         }
00127 
00128       res_READLINK4.status = NFS4_OK;
00129       return res_READLINK4.status;
00130     }
00131 
00132   res_READLINK4.status = nfs4_Errno(cache_status);
00133   return res_READLINK4.status;
00134 }                               /* nfs4_op_readlink */
00135 
00146 void nfs4_op_readlink_Free(READLINK4res * resp)
00147 {
00148   if(resp->status == NFS4_OK && resp->READLINK4res_u.resok4.link
00149      .utf8string_len > 0)
00150     gsh_free(resp->READLINK4res_u.resok4.link.utf8string_val);
00151 
00152   return;
00153 }                               /* nfs4_op_readlink_Free */