nfs-ganesha 1.4
|
00001 /* 00002 * vim:expandtab:shiftwidth=8:tabstop=8: 00003 */ 00004 00013 #ifdef HAVE_CONFIG_H 00014 #include "config.h" 00015 #endif 00016 00017 #include "fsal.h" 00018 #include "fsal_internal.h" 00019 #include "fsal_convert.h" 00020 00057 fsal_status_t FSAL_open(fsal_handle_t * filehandle, /* IN */ 00058 fsal_op_context_t * p_context, /* IN */ 00059 fsal_openflags_t openflags, /* IN */ 00060 fsal_file_t * file_descriptor, /* OUT */ 00061 fsal_attrib_list_t * file_attributes /* [ IN/OUT ] */ 00062 ) 00063 { 00064 00065 int rc; 00066 00067 /* sanity checks. 00068 * note : file_attributes is optional. 00069 */ 00070 if(!filehandle || !p_context || !file_descriptor) 00071 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_open); 00072 00073 /* >> you can check if this is a file if the information 00074 * is stored into the handle << */ 00075 00076 if(filehandle->object_type_reminder != FSAL_TYPE_FILE) 00077 { 00078 Return(ERR_FSAL_INVAL, 0, INDEX_FSAL_open); 00079 } 00080 00081 /* >> convert fsal open flags to your FS open flags 00082 * Take care of conflicting flags << */ 00083 00084 TakeTokenFSCall(); 00085 00086 /* >> call your FS open function << */ 00087 00088 ReleaseTokenFSCall(); 00089 00090 /* >> interpret returned status << */ 00091 00092 /* >> fill output struct << */ 00093 00094 if(file_attributes) 00095 { 00096 /* >> set output attributes if asked << */ 00097 } 00098 00099 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_open); 00100 00101 } 00102 00142 fsal_status_t FSAL_open_by_name(fsal_handle_t * dirhandle, /* IN */ 00143 fsal_name_t * filename, /* IN */ 00144 fsal_op_context_t * p_context, /* IN */ 00145 fsal_openflags_t openflags, /* IN */ 00146 fsal_file_t * file_descriptor, /* OUT */ 00147 fsal_attrib_list_t * file_attributes /* [ IN/OUT ] */ ) 00148 { 00149 fsal_status_t fsal_status; 00150 fsal_handle_t filehandle; 00151 00152 if(!dirhandle || !filename || !p_context || !file_descriptor) 00153 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_open_by_name); 00154 00155 fsal_status = FSAL_lookup(dirhandle, filename, p_context, &filehandle, file_attributes); 00156 if(FSAL_IS_ERROR(fsal_status)) 00157 return fsal_status; 00158 00159 return FSAL_open(&filehandle, p_context, openflags, file_descriptor, file_attributes); 00160 } 00161 00190 fsal_status_t FSAL_read(fsal_file_t * file_descriptor, /* IN */ 00191 fsal_seek_t * seek_descriptor, /* [IN] */ 00192 fsal_size_t buffer_size, /* IN */ 00193 caddr_t buffer, /* OUT */ 00194 fsal_size_t * read_amount, /* OUT */ 00195 fsal_boolean_t * end_of_file /* OUT */ 00196 ) 00197 { 00198 00199 /* sanity checks. */ 00200 00201 if(!file_descriptor || !buffer || !read_amount || !end_of_file) 00202 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_read); 00203 00204 TakeTokenFSCall(); 00205 00206 /* >> read the correct amount of data at the good offset << */ 00207 00208 ReleaseTokenFSCall(); 00209 00210 /* >> interpreted returned status << */ 00211 00212 /* >> dont forget setting output vars : read_amount, end_of_file << */ 00213 00214 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_read); 00215 00216 } 00217 00245 fsal_status_t FSAL_write(fsal_file_t * file_descriptor, /* IN */ 00246 fsal_op_context_t * p_context, /* IN */ 00247 fsal_seek_t * seek_descriptor, /* IN */ 00248 fsal_size_t buffer_size, /* IN */ 00249 caddr_t buffer, /* IN */ 00250 fsal_size_t * write_amount /* OUT */ 00251 ) 00252 { 00253 00254 /* sanity checks. */ 00255 if(!file_descriptor || !buffer || !write_amount) 00256 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_write); 00257 00258 TakeTokenFSCall(); 00259 00260 /* >> write the correct amount of data at the good offset << */ 00261 00262 ReleaseTokenFSCall(); 00263 00264 /* >> interpreted returned status << */ 00265 00266 /* >> dont forget setting output vars : write_amount << */ 00267 00268 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_write); 00269 00270 } 00271 00286 fsal_status_t FSAL_close(fsal_file_t * file_descriptor /* IN */ 00287 ) 00288 { 00289 00290 int rc; 00291 00292 /* sanity checks. */ 00293 if(!file_descriptor) 00294 Return(ERR_FSAL_FAULT, 0, INDEX_FSAL_close); 00295 00296 TakeTokenFSCall(); 00297 00298 /* >> close your file << */ 00299 00300 ReleaseTokenFSCall(); 00301 00302 /* release your read/write internal resources */ 00303 00304 Return(ERR_FSAL_NO_ERROR, 0, INDEX_FSAL_close); 00305 00306 } 00307 00308 /* Some unsupported calls used in FSAL_PROXY, just for permit the ganeshell to compile */ 00309 fsal_status_t FSAL_open_by_fileid(fsal_handle_t * filehandle, /* IN */ 00310 fsal_u64_t fileid, /* IN */ 00311 fsal_op_context_t * p_context, /* IN */ 00312 fsal_openflags_t openflags, /* IN */ 00313 fsal_file_t * file_descriptor, /* OUT */ 00314 fsal_attrib_list_t * file_attributes /* [ IN/OUT ] */ ) 00315 { 00316 Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_open_by_fileid); 00317 } 00318 00319 fsal_status_t FSAL_close_by_fileid(fsal_file_t * file_descriptor /* IN */ , 00320 fsal_u64_t fileid) 00321 { 00322 Return(ERR_FSAL_NOTSUPP, 0, INDEX_FSAL_open_by_fileid); 00323 } 00324 00325 unsigned int XFSFSAL_GetFileno(fsal_file_t * pfile) 00326 { 00327 return fileno(pfile); 00328 }