nfs-ganesha 1.4
|
00001 /* 00002 * vim:expandtab:shiftwidth=4:tabstop=4: 00003 */ 00004 00013 #ifdef HAVE_CONFIG_H 00014 #include "config.h" 00015 #endif 00016 00017 #include "fsal.h" 00018 #include <string.h> 00019 00044 fsal_status_t FSAL_str2name(const char *string, /* IN */ 00045 fsal_mdsize_t in_str_maxlen, /* IN */ 00046 fsal_name_t * name /* OUT */ 00047 ) 00048 { 00049 00050 unsigned int i; 00051 char *output; 00052 00053 /* sanity checks */ 00054 if(!name || !string) 00055 ReturnCode(ERR_FSAL_FAULT, 0); 00056 00057 output = (*name).name; 00058 00059 /* computes input strlen */ 00060 for(i = 0; (i < in_str_maxlen) && (string[i] != '\0'); i++) ; 00061 00062 /* the value of i doesn't include terminating '\0', 00063 * thus, FSAL_MAX_NAME_LEN is excluded. 00064 */ 00065 if(i >= FSAL_MAX_NAME_LEN) 00066 ReturnCode(ERR_FSAL_NAMETOOLONG, 0); 00067 00068 (*name).len = i; 00069 00070 /* copies the string */ 00071 for(i = 0; i < (*name).len; i++) 00072 { 00073 output[i] = string[i]; 00074 } 00075 /* sets the terminating \0 */ 00076 output[i] = '\0'; 00077 00078 ReturnCode(ERR_FSAL_NO_ERROR, 0); 00079 00080 } 00081 00098 fsal_status_t FSAL_str2path(char *string, /* IN */ 00099 fsal_mdsize_t in_str_maxlen, /* IN */ 00100 fsal_path_t * p_path /* OUT */ 00101 ) 00102 { 00103 00104 unsigned int i; 00105 char *output; 00106 00107 /* sanity checks */ 00108 if(!p_path || !string) 00109 ReturnCode(ERR_FSAL_FAULT, 0); 00110 00111 output = p_path->path; 00112 00113 /* computes input strlen */ 00114 for(i = 0; (i < in_str_maxlen) && (string[i] != '\0'); i++) ; 00115 00116 /* the value of i doesn't include terminating '\0', 00117 * thus, FSAL_MAX_PATH_LEN is excluded. 00118 */ 00119 if(i >= FSAL_MAX_PATH_LEN) 00120 ReturnCode(ERR_FSAL_NAMETOOLONG, 0); 00121 00122 p_path->len = i; 00123 00124 /* copies the string */ 00125 for(i = 0; i < p_path->len; i++) 00126 { 00127 output[i] = string[i]; 00128 } 00129 /* sets the terminating \0 */ 00130 output[i] = '\0'; 00131 00132 ReturnCode(ERR_FSAL_NO_ERROR, 0); 00133 00134 } 00135 00152 fsal_status_t FSAL_name2str(fsal_name_t * p_name, /* IN */ 00153 char *string, /* OUT */ 00154 fsal_mdsize_t out_str_maxlen /* IN */ 00155 ) 00156 { 00157 00158 unsigned int i; 00159 char *input; 00160 00161 /* sanity checks */ 00162 if(!string || !p_name) 00163 ReturnCode(ERR_FSAL_FAULT, 0); 00164 00165 input = p_name->name; 00166 00167 i = p_name->len; 00168 00169 /* the value of i doesn't include terminating '\0', 00170 * thus, last value is excluded. 00171 */ 00172 if(i >= out_str_maxlen) 00173 ReturnCode(ERR_FSAL_TOOSMALL, 0); 00174 00175 /* copies the value */ 00176 strncpy(string, input, out_str_maxlen); 00177 00178 ReturnCode(ERR_FSAL_NO_ERROR, 0); 00179 } 00180 00197 fsal_status_t FSAL_path2str(fsal_path_t * p_path, /* IN */ 00198 char *string, /* OUT */ 00199 fsal_mdsize_t out_str_maxlen /* IN */ 00200 ) 00201 { 00202 00203 unsigned int i; 00204 char *input; 00205 00206 /* sanity checks */ 00207 if(!string || !p_path) 00208 ReturnCode(ERR_FSAL_FAULT, 0); 00209 00210 input = p_path->path; 00211 00212 i = p_path->len; 00213 00214 /* the value of i doesn't include terminating '\0', 00215 * thus, last value is excluded. 00216 */ 00217 if(i >= out_str_maxlen) 00218 ReturnCode(ERR_FSAL_TOOSMALL, 0); 00219 00220 /* copies the value */ 00221 strncpy(string, input, out_str_maxlen); 00222 00223 ReturnCode(ERR_FSAL_NO_ERROR, 0); 00224 } 00225 00232 int FSAL_namecmp(const fsal_name_t *p_name1, 00233 const fsal_name_t *p_name2) 00234 { 00235 00236 return (strncmp(p_name1->name, p_name2->name, FSAL_MAX_NAME_LEN)); 00237 00238 } 00239 00246 int FSAL_pathcmp(fsal_path_t * p_path1, fsal_path_t * p_path2) 00247 { 00248 00249 return (strncmp(p_path1->path, p_path2->path, FSAL_MAX_PATH_LEN)); 00250 00251 } 00252 00261 fsal_status_t FSAL_namecpy(fsal_name_t * p_tgt_name, fsal_name_t * p_src_name) 00262 { 00263 00264 char *output; 00265 00266 /* sanity check */ 00267 if(!p_tgt_name || !p_src_name) 00268 ReturnCode(ERR_FSAL_FAULT, 0); 00269 00270 output = p_tgt_name->name; 00271 00272 /* copy */ 00273 strncpy(output, p_src_name->name, FSAL_MAX_NAME_LEN); 00274 00275 p_tgt_name->len = p_src_name->len; 00276 00277 ReturnCode(ERR_FSAL_NO_ERROR, 0); 00278 00279 } 00280 00289 fsal_status_t FSAL_pathcpy(fsal_path_t * p_tgt_path, fsal_path_t * p_src_path) 00290 { 00291 00292 char *output; 00293 00294 /* sanity check */ 00295 if(!p_tgt_path || !p_src_path) 00296 ReturnCode(ERR_FSAL_FAULT, 0); 00297 00298 output = p_tgt_path->path; 00299 00300 /* copy */ 00301 strncpy(output, p_src_path->path, FSAL_MAX_PATH_LEN); 00302 00303 p_tgt_path->len = p_src_path->len; 00304 00305 ReturnCode(ERR_FSAL_NO_ERROR, 0); 00306 00307 } 00308 00313 fsal_status_t FSAL_buffdesc2name(fsal_buffdesc_t * in_buf, fsal_name_t * out_name) 00314 { 00315 00316 if(!in_buf || !out_name) 00317 ReturnCode(ERR_FSAL_FAULT, 0); 00318 00319 return FSAL_str2name(in_buf->pointer, in_buf->len, out_name); 00320 00321 } 00322 00327 fsal_status_t FSAL_buffdesc2path(fsal_buffdesc_t * in_buf, fsal_path_t * out_path) 00328 { 00329 00330 if(!in_buf || !out_path) 00331 ReturnCode(ERR_FSAL_FAULT, 0); 00332 00333 return FSAL_str2path(in_buf->pointer, in_buf->len, out_path); 00334 00335 } 00336 00351 fsal_status_t FSAL_path2buffdesc(fsal_path_t * in_path, fsal_buffdesc_t * out_buff) 00352 { 00353 00354 if(!out_buff || !in_path) 00355 ReturnCode(ERR_FSAL_FAULT, 0); 00356 00357 out_buff->pointer = in_path->path; 00358 out_buff->len = in_path->len; 00359 00360 ReturnCode(ERR_FSAL_NO_ERROR, 0); 00361 00362 } 00363 00378 fsal_status_t FSAL_name2buffdesc(fsal_name_t * in_name, fsal_buffdesc_t * out_buff) 00379 { 00380 00381 if(!out_buff || !in_name) 00382 ReturnCode(ERR_FSAL_FAULT, 0); 00383 00384 out_buff->pointer = in_name->name; 00385 out_buff->len = in_name->len; 00386 00387 ReturnCode(ERR_FSAL_NO_ERROR, 0); 00388 00389 } 00390 00391 /* @} */