nfs-ganesha 1.4
|
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 00079 #define arg_LINK4 op->nfs_argop4_u.oplink 00080 #define res_LINK4 resp->nfs_resop4_u.oplink 00081 00082 int nfs4_op_link(struct nfs_argop4 *op, compound_data_t * data, struct nfs_resop4 *resp) 00083 { 00084 char __attribute__ ((__unused__)) funcname[] = "nfs4_op_link"; 00085 00086 cache_entry_t * dir_pentry = NULL; 00087 cache_entry_t * file_pentry = NULL; 00088 cache_inode_status_t cache_status; 00089 fsal_attrib_list_t attr; 00090 fsal_name_t newname; 00091 00092 resp->resop = NFS4_OP_LINK; 00093 res_LINK4.status = NFS4_OK; 00094 00095 /* Do basic checks on a filehandle */ 00096 res_LINK4.status = nfs4_sanity_check_FH(data, 0LL); 00097 if(res_LINK4.status != NFS4_OK) 00098 return res_LINK4.status; 00099 00100 /* If there is no FH */ 00101 if(nfs4_Is_Fh_Empty(&(data->savedFH))) 00102 { 00103 res_LINK4.status = NFS4ERR_NOFILEHANDLE; 00104 return res_LINK4.status; 00105 } 00106 00107 /* If the filehandle is invalid */ 00108 if(nfs4_Is_Fh_Invalid(&(data->savedFH))) 00109 { 00110 res_LINK4.status = NFS4ERR_BADHANDLE; 00111 return res_LINK4.status; 00112 } 00113 00114 /* Tests if the Filehandle is expired (for volatile filehandle) */ 00115 if(nfs4_Is_Fh_Expired(&(data->savedFH))) 00116 { 00117 res_LINK4.status = NFS4ERR_FHEXPIRED; 00118 return res_LINK4.status; 00119 } 00120 00121 /* Pseudo Fs is explictely a Read-Only File system */ 00122 if(nfs4_Is_Fh_Pseudo(&(data->currentFH))) 00123 { 00124 res_LINK4.status = NFS4ERR_ROFS; 00125 return res_LINK4.status; 00126 } 00127 00128 /* If data->exportp is null, a junction from pseudo fs was traversed, credp and exportp have to be updated */ 00129 if(data->pexport == NULL) 00130 { 00131 res_LINK4.status = nfs4_SetCompoundExport(data); 00132 if(res_LINK4.status != NFS4_OK) 00133 return res_LINK4.status; 00134 } 00135 00136 /* 00137 * This operation creates a hard link, for the file represented by the saved FH, in directory represented by currentFH under the 00138 * name arg_LINK4.target 00139 */ 00140 00141 /* Crossing device is not allowed */ 00142 if(((file_handle_v4_t *) (data->currentFH.nfs_fh4_val))->exportid != 00143 ((file_handle_v4_t *) (data->savedFH.nfs_fh4_val))->exportid) 00144 { 00145 res_LINK4.status = NFS4ERR_XDEV; 00146 return res_LINK4.status; 00147 } 00148 00149 /* If name is empty, return EINVAL */ 00150 if(arg_LINK4.newname.utf8string_len == 0) 00151 { 00152 res_LINK4.status = NFS4ERR_INVAL; 00153 return res_LINK4.status; 00154 } 00155 00156 /* Check for name to long */ 00157 if(arg_LINK4.newname.utf8string_len > FSAL_MAX_NAME_LEN) 00158 { 00159 res_LINK4.status = NFS4ERR_NAMETOOLONG; 00160 return res_LINK4.status; 00161 } 00162 00163 /* Convert the UFT8 objname to a regular string */ 00164 if((cache_status = 00165 cache_inode_error_convert(FSAL_buffdesc2name 00166 ((fsal_buffdesc_t *) & arg_LINK4.newname, 00167 &newname))) != CACHE_INODE_SUCCESS) 00168 { 00169 res_LINK4.status = nfs4_Errno(cache_status); 00170 return res_LINK4.status; 00171 } 00172 00173 /* Sanity check: never create a link named '.' or '..' */ 00174 if(!FSAL_namecmp(&newname, (fsal_name_t *) & FSAL_DOT) 00175 || !FSAL_namecmp(&newname, (fsal_name_t *) & FSAL_DOT_DOT)) 00176 { 00177 res_LINK4.status = NFS4ERR_BADNAME; 00178 return res_LINK4.status; 00179 } 00180 00181 /* get info from compound data */ 00182 dir_pentry = data->current_entry; 00183 00184 /* Destination FH (the currentFH) must be a directory */ 00185 if(data->current_filetype != DIRECTORY) 00186 { 00187 res_LINK4.status = NFS4ERR_NOTDIR; 00188 return res_LINK4.status; 00189 } 00190 00191 /* Target object (the savedFH) must not be a directory */ 00192 if(data->saved_filetype == DIRECTORY) 00193 { 00194 res_LINK4.status = NFS4ERR_ISDIR; 00195 return res_LINK4.status; 00196 } 00197 00198 /* We have to keep track of the 'change' file attribute for reply structure */ 00199 if((cache_status = cache_inode_getattr(dir_pentry, 00200 &attr, 00201 data->pcontext, 00202 &cache_status)) != CACHE_INODE_SUCCESS) 00203 { 00204 res_LINK4.status = nfs4_Errno(cache_status); 00205 return res_LINK4.status; 00206 } 00207 res_LINK4.LINK4res_u.resok4.cinfo.before 00208 = cache_inode_get_changeid4(dir_pentry); 00209 00210 /* Convert savedFH into a vnode */ 00211 file_pentry = data->saved_entry; 00212 00213 /* make the link */ 00214 if(cache_inode_link(file_pentry, 00215 dir_pentry, 00216 &newname, 00217 &attr, 00218 data->pcontext, &cache_status) != CACHE_INODE_SUCCESS) 00219 { 00220 res_LINK4.status = nfs4_Errno(cache_status); 00221 return res_LINK4.status; 00222 } 00223 00224 res_LINK4.LINK4res_u.resok4.cinfo.after 00225 = cache_inode_get_changeid4(dir_pentry); 00226 res_LINK4.LINK4res_u.resok4.cinfo.atomic = FALSE; 00227 00228 res_LINK4.status = NFS4_OK; 00229 return NFS4_OK; 00230 } /* nfs4_op_link */ 00231 00242 void nfs4_op_link_Free(LINK4res * resp) 00243 { 00244 return; 00245 } /* nfs4_op_link_Free */