nfs-ganesha 1.4
|
00001 /* 00002 * vim:expandtab:shiftwidth=8:tabstop=8: 00003 */ 00004 00014 #ifdef HAVE_CONFIG_H 00015 #include "config.h" 00016 #endif 00017 00018 #include "fsal.h" 00019 #include "log.h" 00020 #include <unistd.h> /* for using gethostname */ 00021 #include <stdlib.h> /* for using exit */ 00022 #include <string.h> 00023 #include <sys/types.h> 00024 00025 #define READDIR_SIZE 5 00026 00027 void printmask(fsal_attrib_mask_t mask) 00028 { 00029 00030 if(FSAL_TEST_MASK(mask, FSAL_ATTR_SUPPATTR)) 00031 printf("FSAL_ATTR_SUPPATTR\n"); 00032 if(FSAL_TEST_MASK(mask, FSAL_ATTR_TYPE)) 00033 printf("FSAL_ATTR_TYPE\n"); 00034 if(FSAL_TEST_MASK(mask, FSAL_ATTR_SIZE)) 00035 printf("FSAL_ATTR_SIZE\n"); 00036 if(FSAL_TEST_MASK(mask, FSAL_ATTR_FSID)) 00037 printf("FSAL_ATTR_FSID\n"); 00038 if(FSAL_TEST_MASK(mask, FSAL_ATTR_ACL)) 00039 printf("FSAL_ATTR_ACL \n"); 00040 if(FSAL_TEST_MASK(mask, FSAL_ATTR_FILEID)) 00041 printf("FSAL_ATTR_FILEID\n"); 00042 if(FSAL_TEST_MASK(mask, FSAL_ATTR_MODE)) 00043 printf("FSAL_ATTR_MODE\n"); 00044 if(FSAL_TEST_MASK(mask, FSAL_ATTR_NUMLINKS)) 00045 printf("FSAL_ATTR_NUMLINKS\n"); 00046 if(FSAL_TEST_MASK(mask, FSAL_ATTR_OWNER)) 00047 printf("FSAL_ATTR_OWNER\n"); 00048 if(FSAL_TEST_MASK(mask, FSAL_ATTR_GROUP)) 00049 printf("FSAL_ATTR_GROUP\n"); 00050 if(FSAL_TEST_MASK(mask, FSAL_ATTR_RAWDEV)) 00051 printf("FSAL_ATTR_RAWDEV\n"); 00052 if(FSAL_TEST_MASK(mask, FSAL_ATTR_ATIME)) 00053 printf("FSAL_ATTR_ATIME\n"); 00054 if(FSAL_TEST_MASK(mask, FSAL_ATTR_CREATION)) 00055 printf("FSAL_ATTR_CREATION\n"); 00056 if(FSAL_TEST_MASK(mask, FSAL_ATTR_CTIME)) 00057 printf("FSAL_ATTR_CTIME\n"); 00058 if(FSAL_TEST_MASK(mask, FSAL_ATTR_CHGTIME)) 00059 printf("FSAL_ATTR_CHGTIME\n"); 00060 if(FSAL_TEST_MASK(mask, FSAL_ATTR_MTIME)) 00061 printf("FSAL_ATTR_MTIME\n"); 00062 if(FSAL_TEST_MASK(mask, FSAL_ATTR_SPACEUSED)) 00063 printf("FSAL_ATTR_SPACEUSED\n"); 00064 if(FSAL_TEST_MASK(mask, FSAL_ATTR_MOUNTFILEID)) 00065 printf("FSAL_ATTR_MOUNTFILEID\n"); 00066 00067 } 00068 00069 char *strtype(fsal_nodetype_t type) 00070 { 00071 switch (type) 00072 { 00073 case FSAL_TYPE_FIFO: 00074 return "FSAL_TYPE_FIFO "; 00075 case FSAL_TYPE_CHR: 00076 return "FSAL_TYPE_CHR "; 00077 case FSAL_TYPE_DIR: 00078 return "FSAL_TYPE_DIR "; 00079 case FSAL_TYPE_BLK: 00080 return "FSAL_TYPE_BLK "; 00081 case FSAL_TYPE_FILE: 00082 return "FSAL_TYPE_FILE "; 00083 case FSAL_TYPE_LNK: 00084 return "FSAL_TYPE_LNK "; 00085 case FSAL_TYPE_JUNCTION: 00086 return "FSAL_TYPE_JUNCTION"; 00087 case 0: 00088 return "(null) "; 00089 00090 default: 00091 return "Unknown type"; 00092 } 00093 } 00094 00095 void printattributes(fsal_attrib_list_t attrs) 00096 { 00097 00098 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_RDATTR_ERR)) 00099 printf("FSAL_ATTR_RDATTR_ERR\n"); 00100 00101 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_TYPE)) 00102 printf("Type : %s\n", strtype(attrs.type)); 00103 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_SIZE)) 00104 printf("Size : %llu\n", attrs.filesize); 00105 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_FSID)) 00106 printf("fsId : %llu.%llu\n", attrs.fsid.major, attrs.fsid.minor); 00107 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_ACL)) 00108 printf("ACL List ...\n"); 00109 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_FILEID)) 00110 printf("FileId : %llu\n", attrs.fileid); 00111 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_MODE)) 00112 printf("Mode : %#o\n", attrs.mode); 00113 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_NUMLINKS)) 00114 printf("Numlinks : %u\n", (unsigned int)attrs.numlinks); 00115 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_OWNER)) 00116 printf("uid : %d\n", attrs.owner); 00117 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_GROUP)) 00118 printf("gid : %d\n", attrs.group); 00119 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_RAWDEV)) 00120 printf("Rawdev ...\n"); 00121 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_ATIME)) 00122 printf("atime : %s", ctime((time_t *) & attrs.atime.seconds)); 00123 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_CREATION)) 00124 printf("creation time : %s", ctime((time_t *) & attrs.creation.seconds)); 00125 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_CTIME)) 00126 printf("ctime : %s", ctime((time_t *) & attrs.ctime.seconds)); 00127 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_MTIME)) 00128 printf("mtime : %s", ctime((time_t *) & attrs.mtime.seconds)); 00129 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_CHGTIME)) 00130 printf("chgtime : %s", ctime((time_t *) & attrs.chgtime.seconds)); 00131 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_SPACEUSED)) 00132 printf("spaceused : %llu\n", attrs.spaceused); 00133 if(FSAL_TEST_MASK(attrs.asked_attributes, FSAL_ATTR_MOUNTFILEID)) 00134 printf("mounted_on_fileid : %llu\n", attrs.mounted_on_fileid); 00135 00136 } 00137 00138 void usage() 00139 { 00140 fprintf(stderr, "Usage :\n\ttest_fsal <no_test>\n"); 00141 fprintf(stderr, "\ttests :\n"); 00142 fprintf(stderr, "\t\t1 - getattrs\n"); 00143 fprintf(stderr, "\t\t2 - lookup\n"); 00144 fprintf(stderr, "\t\t3 - lookupPath\n"); 00145 fprintf(stderr, "\t\t4 - readdir (acces par tableau)\n"); 00146 fprintf(stderr, "\t\t5 - readdir (acces liste chainee)\n"); 00147 fprintf(stderr, "\t\t6 - access/test_access\n"); 00148 fprintf(stderr, "\t\t7 - snprintmem/sscanmem\n"); 00149 fprintf(stderr, "\t\t8 - mkdir/rmdir\n"); 00150 fprintf(stderr, "\t\t9 - setattr\n"); 00151 fprintf(stderr, "\t\tA - digest/expend handle\n"); 00152 fprintf(stderr, "\t\tB - dynamic fs info\n"); 00153 return; 00154 } 00155 00156 int main(int argc, char **argv) 00157 { 00158 00159 char localmachine[256]; 00160 char *test; 00161 fsal_parameter_t init_param; 00162 fsal_status_t st; 00163 log_t log_desc = LOG_INITIALIZER; 00164 desc_log_stream_t voie; 00165 uid_t uid; 00166 fsal_export_context_t export_ctx; 00167 fsal_op_context_t op_ctx; 00168 fsal_handle_t root_handle, handle; 00169 fsal_name_t name; 00170 fsal_path_t path; 00171 fsal_attrib_list_t attribs; 00172 fsal_attrib_mask_t mask; 00173 00174 char tracebuff[256]; 00175 00176 if(argc < 2) 00177 { 00178 usage(); 00179 exit(-1); 00180 } 00181 test = argv[1]; 00182 /* retrieving params */ 00183 00184 /* init debug */ 00185 00186 SetNamePgm("test_fsal"); 00187 SetNameFileLog("/dev/tty"); 00188 SetNameFunction("main"); 00189 00190 /* Obtention du nom de la machine */ 00191 if(gethostname(localmachine, sizeof(localmachine)) != 0) 00192 { 00193 DisplayErrorLog(ERR_SYS, ERR_GETHOSTNAME, errno); 00194 exit(1); 00195 } 00196 else 00197 SetNameHost(localmachine); 00198 00199 InitDebug(NIV_FULL_DEBUG); 00200 00201 AddFamilyError(ERR_FSAL, "FSAL related Errors", tab_errstatus_FSAL); 00202 00203 /* creating log */ 00204 voie.fd = fileno(stderr); 00205 AddLogStreamJd(&log_desc, V_FD, voie, NIV_FULL_DEBUG, SUP); 00206 00207 /* prepare fsal_init */ 00208 00209 /* 1 - fs specific info */ 00210 00211 #ifdef _USE_HPSS_51 00212 00213 init_param.fs_specific_info.behaviors.PrincipalName = FSAL_INIT_FORCE_VALUE; 00214 strcpy(init_param.fs_specific_info.hpss_config.PrincipalName, "hpss_nfs"); 00215 00216 init_param.fs_specific_info.behaviors.KeytabPath = FSAL_INIT_FORCE_VALUE; 00217 strcpy(init_param.fs_specific_info.hpss_config.KeytabPath, "/krb5/hpssserver.keytab"); 00218 00219 #elif defined _USE_HPSS_62 00220 init_param.fs_specific_info.behaviors.AuthnMech = FSAL_INIT_FORCE_VALUE; 00221 init_param.fs_specific_info.hpss_config.AuthnMech = hpss_authn_mech_krb5; 00222 00223 init_param.fs_specific_info.behaviors.Principal = FSAL_INIT_FORCE_VALUE; 00224 strcpy(init_param.fs_specific_info.Principal, "hpssfs"); 00225 00226 init_param.fs_specific_info.behaviors.KeytabPath = FSAL_INIT_FORCE_VALUE; 00227 strcpy(init_param.fs_specific_info.KeytabPath, "/var/hpss/etc/hpss.keytab"); 00228 00229 #endif 00230 00231 /* 2-common info (default) */ 00232 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxfilesize); 00233 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxlink); 00234 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxnamelen); 00235 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxpathlen); 00236 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, no_trunc); 00237 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, chown_restricted); 00238 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, case_insensitive); 00239 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, case_preserving); 00240 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, fh_expire_type); 00241 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, link_support); 00242 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, symlink_support); 00243 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, named_attr); 00244 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, unique_handles); 00245 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, lease_time); 00246 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, acl_support); 00247 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, cansettime); 00248 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, homogenous); 00249 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, supported_attrs); 00250 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxread); 00251 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, maxwrite); 00252 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, umask); 00253 FSAL_SET_INIT_DEFAULT(init_param.fs_common_info, auth_exportpath_xdev); 00254 00255 /* 3- fsal info */ 00256 init_param.fsal_info.log_outputs = log_desc; 00257 init_param.fsal_info.max_fs_calls = 0; 00258 00259 /* Init */ 00260 if(FSAL_IS_ERROR(st = FSAL_Init(&init_param))) 00261 { 00262 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00263 } 00264 00265 /* getting creds */ 00266 uid = getuid(); 00267 printf("uid = %d\n", uid); 00268 00269 st = FSAL_BuildExportContext(&export_ctx, NULL, NULL); 00270 if(FSAL_IS_ERROR(st)) 00271 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00272 00273 st = FSAL_InitClientContext(&op_ctx); 00274 00275 if(FSAL_IS_ERROR(st)) 00276 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00277 00278 st = FSAL_GetClientContext(&op_ctx, &export_ctx, uid, -1, NULL, 0); 00279 00280 if(FSAL_IS_ERROR(st)) 00281 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00282 00283 /* getting root handle */ 00284 00285 if(FSAL_IS_ERROR(st = FSAL_lookup(NULL, NULL, &op_ctx, &root_handle, NULL))) 00286 { 00287 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00288 } 00289 00290 snprintHandle(tracebuff, 256, &root_handle); 00291 printf("Root handle = %s\n", tracebuff); 00292 00293 /* getting what are the supported attributes */ 00294 00295 attribs.asked_attributes = 0; 00296 FSAL_SET_MASK(attribs.asked_attributes, FSAL_ATTR_SUPPATTR); 00297 printf("asked attributes :\n"); 00298 printmask(attribs.asked_attributes); 00299 00300 if(FSAL_IS_ERROR(st = FSAL_getattrs(&root_handle, &op_ctx, &attribs))) 00301 { 00302 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00303 } 00304 00305 printf("supported attributes :\n"); 00306 printmask(attribs.supported_attributes); 00307 00308 mask = attribs.supported_attributes; 00309 00310 /* TEST 1 */ 00311 00312 if(test[0] == '1') 00313 { 00314 00315 attribs.asked_attributes = 0; 00316 FSAL_SET_MASK(attribs.asked_attributes, FSAL_ATTR_SUPPATTR); 00317 printf("asked attributes :\n"); 00318 printmask(attribs.asked_attributes); 00319 00320 if(FSAL_IS_ERROR(st = FSAL_getattrs(&root_handle, &op_ctx, &attribs))) 00321 { 00322 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00323 } 00324 00325 printf("supported attributes :\n"); 00326 00327 /* getting all spported attributes of root */ 00328 attribs.asked_attributes = mask; 00329 if(FSAL_IS_ERROR(st = FSAL_getattrs(&root_handle, &op_ctx, &attribs))) 00330 { 00331 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00332 } 00333 00334 printattributes(attribs); 00335 00336 } 00337 else 00338 /* TEST 2 */ 00339 if(test[0] == '2') 00340 { 00341 00342 /* getting handle and attributes for subdirectory "OSF1_V5" */ 00343 if(FSAL_IS_ERROR(st = FSAL_str2name("cea", 4, &name))) 00344 { 00345 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00346 } 00347 00348 attribs.asked_attributes = mask; 00349 if(FSAL_IS_ERROR(st = FSAL_lookup(&root_handle, &name, &op_ctx, &handle, &attribs))) 00350 { 00351 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00352 } 00353 00354 snprintHandle(tracebuff, 256, &handle); 00355 printf("/cea handle = %s\n", tracebuff); 00356 00357 /* displaying attributes */ 00358 printattributes(attribs); 00359 00360 /* getting handle and attributes for subdirectory "bin" */ 00361 if(FSAL_IS_ERROR(st = FSAL_str2name("prot", 5, &name))) 00362 { 00363 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00364 } 00365 root_handle = handle; 00366 attribs.asked_attributes = mask; 00367 if(FSAL_IS_ERROR(st = FSAL_lookup(&root_handle, &name, &op_ctx, &handle, &attribs))) 00368 { 00369 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00370 } 00371 00372 snprintHandle(tracebuff, 256, &handle); 00373 printf("/cea/prot handle = %s\n", tracebuff); 00374 00375 /* displaying attributes */ 00376 printattributes(attribs); 00377 00378 /* getting handle and attributes for symlink "AglaePwrSW" */ 00379 if(FSAL_IS_ERROR(st = FSAL_str2name("lama", 5, &name))) 00380 { 00381 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00382 } 00383 root_handle = handle; 00384 attribs.asked_attributes = mask; 00385 if(FSAL_IS_ERROR(st = FSAL_lookup(&root_handle, &name, &op_ctx, &handle, &attribs))) 00386 { 00387 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00388 } 00389 00390 snprintHandle(tracebuff, 256, &handle); 00391 printf("/cea/prot/lama handle = %s\n", tracebuff); 00392 00393 /* displaying attributes */ 00394 printattributes(attribs); 00395 00396 } 00397 else 00398 /* TEST 3 */ 00399 if(test[0] == '3') 00400 { 00401 00402 /* lookup root */ 00403 if(FSAL_IS_ERROR(st = FSAL_str2path("/", 30, &path))) 00404 { 00405 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00406 } 00407 attribs.asked_attributes = mask; 00408 if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs))) 00409 { 00410 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00411 } 00412 00413 snprintHandle(tracebuff, 256, &handle); 00414 printf("/ handle = %s\n", tracebuff); 00415 00416 /* displaying attributes */ 00417 printattributes(attribs); 00418 00419 /* lookup path */ 00420 if(FSAL_IS_ERROR(st = FSAL_str2path("/cea/prot/lama", 15, &path))) 00421 { 00422 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00423 } 00424 attribs.asked_attributes = mask; 00425 if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs))) 00426 { 00427 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00428 } 00429 00430 snprintHandle(tracebuff, 256, &handle); 00431 printf("/cea/prot/lama handle = %s\n", tracebuff); 00432 00433 /* displaying attributes */ 00434 printattributes(attribs); 00435 00436 } 00437 else 00438 /* TEST 4 */ 00439 if(test[0] == '4') 00440 { 00441 00442 /* readdir on root */ 00443 fsal_dir_t dir; 00444 fsal_cookie_t from, to; 00445 fsal_dirent_t entries[READDIR_SIZE]; 00446 fsal_count_t number; 00447 fsal_boolean_t eod = FALSE; 00448 int error = FALSE; 00449 00450 attribs.asked_attributes = mask; 00451 if(FSAL_IS_ERROR(st = FSAL_opendir(&root_handle, &op_ctx, &dir, &attribs))) 00452 { 00453 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00454 } 00455 printf("'/' attributes :\n"); 00456 00457 /* displaying attributes */ 00458 printattributes(attribs); 00459 00460 from = FSAL_READDIR_FROM_BEGINNING; 00461 00462 while(!error && !eod) 00463 { 00464 unsigned int i; 00465 char cookiebuff[256]; 00466 00467 snprintCookie(cookiebuff, 256, &from); 00468 printf("\nReaddir cookie = %s\n", cookiebuff); 00469 if(FSAL_IS_ERROR(st = FSAL_readdir(&dir, from, 00470 mask, READDIR_SIZE * sizeof(fsal_dirent_t), 00471 entries, &to, &number, &eod))) 00472 { 00473 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00474 error = TRUE; 00475 } 00476 00477 for(i = 0; (!error) && (i < number); i++) 00478 { 00479 00480 snprintHandle(tracebuff, 256, &entries[i].handle); 00481 00482 snprintCookie(cookiebuff, 256, &entries[i].cookie); 00483 00484 printf("\t%s : %s (cookie %s)\n", tracebuff, 00485 entries[i].name.name, cookiebuff); 00486 } 00487 /* preparing next call */ 00488 from = to; 00489 00490 } 00491 printf("Fin de boucle : error=%d ; eod=%d\n", error, eod); 00492 00493 } 00494 else 00495 /* TEST 5 */ 00496 if(test[0] == '5') 00497 { 00498 00499 /* readdir on root */ 00500 fsal_dir_t dir; 00501 fsal_cookie_t from, to; 00502 fsal_dirent_t entries[READDIR_SIZE]; 00503 fsal_count_t number; 00504 fsal_boolean_t eod = FALSE; 00505 int error = FALSE; 00506 00507 attribs.asked_attributes = mask; 00508 if(FSAL_IS_ERROR(st = FSAL_opendir(&root_handle, &op_ctx, &dir, &attribs))) 00509 { 00510 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00511 } 00512 printf("'/' attributes :\n"); 00513 00514 /* displaying attributes */ 00515 printattributes(attribs); 00516 00517 from = FSAL_READDIR_FROM_BEGINNING; 00518 00519 while(!error && !eod) 00520 { 00521 fsal_dirent_t *curr; 00522 00523 char cookiebuff[256]; 00524 00525 snprintCookie(cookiebuff, 256, &from); 00526 00527 printf("\nReaddir cookie = %s\n", cookiebuff); 00528 00529 if(FSAL_IS_ERROR(st = FSAL_readdir(&dir, from, 00530 mask, READDIR_SIZE * sizeof(fsal_dirent_t), 00531 entries, &to, &number, &eod))) 00532 { 00533 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00534 error = TRUE; 00535 } 00536 00537 if(number > 0) 00538 { 00539 curr = entries; 00540 do 00541 { 00542 00543 snprintHandle(tracebuff, 256, &curr->handle); 00544 snprintCookie(cookiebuff, 256, &curr->cookie); 00545 00546 printf("\t%s : %s (cookie %s)\n", tracebuff, 00547 curr->name.name, cookiebuff); 00548 } 00549 while(curr = curr->nextentry); 00550 } 00551 /* preparing next call */ 00552 from = to; 00553 00554 } 00555 printf("Fin de boucle : error=%d ; eod=%d\n", error, eod); 00556 00557 } 00558 else 00559 /* TEST 6 */ 00560 if(test[0] == '6') 00561 { 00562 00563 /* readdir on root */ 00564 fsal_dir_t dir; 00565 fsal_cookie_t from, to; 00566 fsal_dirent_t entries[READDIR_SIZE]; 00567 fsal_count_t number; 00568 fsal_boolean_t eod = FALSE; 00569 int error = FALSE; 00570 00571 attribs.asked_attributes = mask; 00572 if(FSAL_IS_ERROR(st = FSAL_opendir(&root_handle, &op_ctx, &dir, &attribs))) 00573 { 00574 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00575 } 00576 printf("'/' attributes :\n"); 00577 00578 /* displaying attributes */ 00579 printattributes(attribs); 00580 00581 from = FSAL_READDIR_FROM_BEGINNING; 00582 00583 while(!error && !eod) 00584 { 00585 unsigned int i; 00586 00587 snprintCookie(tracebuff, 256, &from); 00588 printf("\nReaddir cookie = %s\n", tracebuff); 00589 00590 st = FSAL_readdir(&dir, from, mask, 00591 READDIR_SIZE * sizeof(fsal_dirent_t), 00592 entries, &to, &number, &eod); 00593 00594 if(FSAL_IS_ERROR(st)) 00595 { 00596 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00597 error = TRUE; 00598 } 00599 00600 /* for each entry, we compare the result of FSAL_access 00601 * to FSAL_test_access. */ 00602 for(i = 0; (!error) && (i < number); i++) 00603 { 00604 00605 fsal_status_t st1, st2; 00606 char cookiebuff[256]; 00607 00608 snprintHandle(tracebuff, 256, &entries[i].handle); 00609 snprintCookie(cookiebuff, 256, &entries[i].cookie); 00610 00611 printf("\t%s : %s (cookie %s)\n", tracebuff, 00612 entries[i].name.name, cookiebuff); 00613 00614 if(FSAL_IS_ERROR(st = FSAL_getattrs(&entries[i].handle, &op_ctx, &attribs))) 00615 { 00616 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00617 } 00618 00619 /* 1 - test R access */ 00620 00621 st1 = FSAL_access(&entries[i].handle, &op_ctx, FSAL_R_OK, NULL); 00622 00623 st2 = FSAL_test_access(&op_ctx, FSAL_R_OK, &attribs); 00624 00625 DisplayErrorJd(log_desc, ERR_FSAL, st1.major, st1.minor); 00626 DisplayErrorJd(log_desc, ERR_FSAL, st2.major, st2.minor); 00627 00628 if(st1.major != st2.major) 00629 { 00630 printf 00631 ("Error : different access permissions given by FSAL_access and FSAL_test_access : %d <>%d\n", 00632 st1.major, st2.major); 00633 } 00634 00635 /* 2 - test W access */ 00636 00637 st1 = FSAL_access(&entries[i].handle, &op_ctx, FSAL_W_OK, NULL); 00638 00639 st2 = FSAL_test_access(&op_ctx, FSAL_W_OK, &attribs); 00640 00641 DisplayErrorJd(log_desc, ERR_FSAL, st1.major, st1.minor); 00642 DisplayErrorJd(log_desc, ERR_FSAL, st2.major, st2.minor); 00643 00644 if(st1.major != st2.major) 00645 { 00646 printf 00647 ("Error : different access permissions given by FSAL_access and FSAL_test_access : %d <>%d\n", 00648 st1.major, st2.major); 00649 } 00650 00651 /* 3 - test X access */ 00652 00653 st1 = FSAL_access(&entries[i].handle, &op_ctx, FSAL_X_OK, NULL); 00654 00655 st2 = FSAL_test_access(&op_ctx, FSAL_X_OK, &attribs); 00656 00657 DisplayErrorJd(log_desc, ERR_FSAL, st1.major, st1.minor); 00658 DisplayErrorJd(log_desc, ERR_FSAL, st2.major, st2.minor); 00659 00660 if(st1.major != st2.major) 00661 { 00662 printf 00663 ("Error : different access permissions given by FSAL_access and FSAL_test_access : %d <>%d\n", 00664 st1.major, st2.major); 00665 } 00666 00667 } 00668 00669 /* preparing next call */ 00670 from = to; 00671 00672 } 00673 printf("Fin de boucle : error=%d ; eod=%d\n", error, eod); 00674 00675 } 00676 else 00677 /* TEST 7 */ 00678 if(test[0] == '7') 00679 { 00680 00681 /* test snprintmem and sscanmem */ 00682 char test_string[] = 00683 "Ceci est une chaine d'essai.\nLes chiffres : 0123456789\nLes lettres : ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 00684 00685 char buffer[256]; 00686 char string[200]; /* 200 suffit car test_string fait <100 */ 00687 00688 int size1, size2, size3, i; 00689 00690 /* we put bad values in string, to see if it is correctly set. */ 00691 for(i = 0; i < 200; i++) 00692 string[i] = (char)i; 00693 00694 printf("Initial data (%d Bytes) = <<%s>>\n", strlen(test_string), test_string); 00695 00696 /* Write test_string to a buffer. */ 00697 /* We don't give the final '\0'. */ 00698 snprintmem(buffer, 256, test_string, strlen(test_string)); 00699 00700 printf("Dest_Buffer (%d Bytes) = <<%s>>\n", strlen(buffer), buffer); 00701 00702 /* read the value from the buffer */ 00703 sscanmem(string, strlen(test_string), buffer); 00704 00705 /* sets the final 0 to print the content of the buffer */ 00706 printf("Retrieved string : following byte = %d\n", 00707 (int)string[strlen(test_string)]); 00708 string[strlen(test_string)] = '\0'; 00709 00710 printf("Retrieved string (%d Bytes) = <<%s>>\n", strlen(string), string); 00711 00712 /* Automatic tests : */ 00713 size1 = strlen(test_string); 00714 size2 = strlen(buffer); 00715 size3 = strlen(string); 00716 00717 printf("-------------------------------------\n"); 00718 00719 if(size1 <= 0) 00720 printf("***** ERROR: source size=0 !!!\n"); 00721 00722 if(size1 != size3) 00723 printf("***** ERROR: source size <> target size\n"); 00724 else 00725 printf("OK: source size = target size\n"); 00726 00727 if((size1 * 2) != size2) 00728 printf("***** ERROR: hexa size <> 2 * source size\n"); 00729 else 00730 printf("OK: hexa size = 2 * source size\n"); 00731 00732 if(strcmp(test_string, string)) 00733 printf("***** ERROR: source string <> target string\n"); 00734 else 00735 printf("OK: source string = target string\n"); 00736 00737 } 00738 else 00739 /* TEST 8 */ 00740 if(test[0] == '8') 00741 { 00742 00743 fsal_handle_t dir_hdl, subdir_hdl; 00744 fsal_name_t subdir_name; 00745 00746 /* lookup on /cea/prot/S/lama/s8/leibovic */ 00747 00748 if(FSAL_IS_ERROR(st = FSAL_str2path("/cea/prot/S/lama/s8/leibovic", 40, &path))) 00749 { 00750 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00751 } 00752 attribs.asked_attributes = mask; 00753 if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs))) 00754 { 00755 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00756 } 00757 00758 snprintHandle(tracebuff, 256, &handle); 00759 printf("/cea/prot/S/lama/s8/leibovic: handle = %s\n", tracebuff); 00760 00761 sleep(1); 00762 00763 /* creates a directory */ 00764 printf("------- Create a directory -------\n"); 00765 00766 if(FSAL_IS_ERROR(st = FSAL_str2name("tests_GANESHA", 30, &name))) 00767 { 00768 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00769 } 00770 00771 attribs.asked_attributes = mask; 00772 00773 if(FSAL_IS_ERROR(st = FSAL_mkdir(&handle, &name, &op_ctx, 00774 FSAL_MODE_RUSR | FSAL_MODE_WUSR 00775 | FSAL_MODE_XUSR | FSAL_MODE_RGRP 00776 | FSAL_MODE_WGRP, &dir_hdl, &attribs))) 00777 { 00778 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00779 } 00780 else 00781 { 00782 00783 snprintHandle(tracebuff, 256, &dir_hdl); 00784 printf("newly created dir handle = %s\n", tracebuff); 00785 00786 printattributes(attribs); 00787 00788 } 00789 00790 sleep(1); 00791 00792 /* Try to create it again */ 00793 printf("------- Try to create it again -------\n"); 00794 00795 if(FSAL_IS_ERROR(st = FSAL_mkdir(&handle, &name, &op_ctx, 00796 FSAL_MODE_RUSR | FSAL_MODE_WUSR 00797 | FSAL_MODE_XUSR | FSAL_MODE_RGRP 00798 | FSAL_MODE_WGRP, &dir_hdl, &attribs))) 00799 { 00800 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00801 } 00802 else 00803 { 00804 00805 printf("**** Error: FSAL should have returned ERR_FSAL_EXIST\n"); 00806 00807 } 00808 00809 sleep(1); 00810 00811 /* creates a subdirectory */ 00812 printf("------- Create a subdirectory -------\n"); 00813 00814 if(FSAL_IS_ERROR(st = FSAL_str2name("subdir_GANESHA", 30, &subdir_name))) 00815 { 00816 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00817 } 00818 00819 if(FSAL_IS_ERROR(st = FSAL_mkdir(&dir_hdl, &subdir_name, &op_ctx, 00820 FSAL_MODE_RUSR | FSAL_MODE_WUSR 00821 | FSAL_MODE_XUSR | FSAL_MODE_RGRP 00822 | FSAL_MODE_WGRP, &subdir_hdl, &attribs))) 00823 { 00824 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00825 } 00826 else 00827 { 00828 00829 snprintHandle(tracebuff, 256, &subdir_hdl); 00830 printf("newly created subdir handle = %s\n", tracebuff); 00831 00832 printattributes(attribs); 00833 00834 } 00835 00836 /* try to removes the parent directory */ 00837 printf("------- Try to removes the parent directory -------\n"); 00838 00839 if(FSAL_IS_ERROR(st = FSAL_unlink(&handle, &name, &op_ctx, &attribs))) 00840 { 00841 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00842 } 00843 else 00844 { 00845 00846 printf("FSAL should not have unlinked %s because it is not empty\n", name.name); 00847 00848 } 00849 00850 sleep(1); 00851 00852 /* removes the subdirectory */ 00853 printf("------- Removes the subdirectory -------\n"); 00854 00855 if(FSAL_IS_ERROR(st = FSAL_unlink(&dir_hdl, &subdir_name, &op_ctx, &attribs))) 00856 { 00857 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00858 } 00859 else 00860 { 00861 00862 printf("New attributes for parent directory:\n"); 00863 printattributes(attribs); 00864 00865 } 00866 00867 /* removes the parent directory */ 00868 printf("------- Removes the parent directory -------\n"); 00869 00870 if(FSAL_IS_ERROR(st = FSAL_unlink(&handle, &name, &op_ctx, &attribs))) 00871 { 00872 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00873 } 00874 else 00875 { 00876 00877 printf("Unlink %s OK\n", name.name); 00878 00879 } 00880 00881 } 00882 /* TEST 9 */ 00883 else if(test[0] == '9') 00884 { 00885 00886 fsal_handle_t dir_hdl, subdir_hdl; 00887 fsal_name_t subdir_name; 00888 fsal_attrib_list_t attr_set; 00889 00890 fsal_fsid_t set_fsid = { 1LL, 2LL }; 00891 00892 #ifdef _LINUX 00893 struct tm jour_heure = { 56, 34, 12, 31, 12, 110, 0, 0, 0, 0, 0 }; 00894 #else 00895 struct tm jour_heure = { 56, 34, 12, 31, 12, 110, 0, 0, 0 }; 00896 #endif 00897 00898 /* lookup on /cea/prot/S/lama/s8/leibovic */ 00899 00900 if(FSAL_IS_ERROR(st = FSAL_str2path("/cea/prot/S/lama/s8/leibovic", 40, &path))) 00901 { 00902 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00903 } 00904 attribs.asked_attributes = mask; 00905 if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs))) 00906 { 00907 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00908 } 00909 00910 snprintHandle(tracebuff, 256, &handle); 00911 printf("/cea/prot/S/lama/s8/leibovic: handle = %s\n", tracebuff); 00912 00913 sleep(1); 00914 00915 /* creates a file */ 00916 printf("------- Create a file -------\n"); 00917 00918 if(FSAL_IS_ERROR(st = FSAL_str2name("tests_GANESHA_setattrs", 30, &name))) 00919 { 00920 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00921 } 00922 00923 attribs.asked_attributes = mask; 00924 00925 if(FSAL_IS_ERROR(st = FSAL_create(&handle, &name, &op_ctx, 00926 FSAL_MODE_RUSR | FSAL_MODE_WUSR 00927 | FSAL_MODE_XUSR | FSAL_MODE_RGRP 00928 | FSAL_MODE_WGRP, &dir_hdl, &attribs))) 00929 { 00930 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 00931 } 00932 else 00933 { 00934 00935 snprintHandle(tracebuff, 256, &dir_hdl); 00936 printf("newly created file handle = %s\n", tracebuff); 00937 00938 printattributes(attribs); 00939 00940 } 00941 00942 sleep(1); 00943 00944 printf("------- Try to change its attributes -------\n"); 00945 00946 /* Macro that try to change the value for an attribute */ 00947 00948 #define CHANGE_ATTRS( str_nom, nom, flag, new_val ) do {\ 00949 memset(&attr_set, 0, sizeof(fsal_attrib_list_t) ); \ 00950 printf("\nTry to change '%s' :\n",str_nom); \ 00951 FSAL_SET_MASK( attr_set.asked_attributes , flag ); \ 00952 attr_set.nom = new_val; \ 00953 attribs.asked_attributes = attr_set.asked_attributes; \ 00954 /* attribs.asked_attributes = mask; */\ 00955 st = FSAL_setattrs( &dir_hdl, &op_ctx, &attr_set, &attribs );\ 00956 if ( FSAL_IS_ERROR(st) ) \ 00957 DisplayErrorJd(log_desc,ERR_FSAL,st.major,st.minor);\ 00958 else \ 00959 printattributes( attribs ); \ 00960 } while(0) 00961 00962 CHANGE_ATTRS("supported_attributes", supported_attributes, 00963 FSAL_ATTR_SUPPATTR, FSAL_ATTRS_MANDATORY); 00964 00965 CHANGE_ATTRS("type", type, FSAL_ATTR_TYPE, FSAL_TYPE_LNK); 00966 00967 sleep(1); /* to see mtime modification by truncate */ 00968 00969 CHANGE_ATTRS("filesize", filesize, FSAL_ATTR_SIZE, (fsal_size_t) 12); 00970 00971 sleep(1); /* to see mtime modification by truncate */ 00972 00973 CHANGE_ATTRS("fsid", fsid, FSAL_ATTR_FSID, set_fsid); 00974 00975 /* @todo : ACLs */ 00976 00977 CHANGE_ATTRS("fileid", fileid, FSAL_ATTR_FILEID, (fsal_u64_t) 1234); 00978 00979 CHANGE_ATTRS("mode", mode, FSAL_ATTR_MODE, 00980 (FSAL_MODE_RUSR | FSAL_MODE_WUSR | FSAL_MODE_RGRP)); 00981 00982 CHANGE_ATTRS("numlinks", numlinks, FSAL_ATTR_NUMLINKS, 7); 00983 00984 /* FSAL_ATTR_RAWDEV */ 00985 00986 CHANGE_ATTRS("atime", atime.seconds, FSAL_ATTR_ATIME, mktime(&jour_heure)); 00987 00988 jour_heure.tm_min++; 00989 00990 CHANGE_ATTRS("creation", creation.seconds, FSAL_ATTR_CREATION, mktime(&jour_heure)); 00991 00992 jour_heure.tm_min++; 00993 00994 CHANGE_ATTRS("mtime", mtime.seconds, FSAL_ATTR_MTIME, mktime(&jour_heure)); 00995 00996 jour_heure.tm_min++; 00997 00998 CHANGE_ATTRS("ctime", ctime.seconds, FSAL_ATTR_CTIME, mktime(&jour_heure)); 00999 01000 CHANGE_ATTRS("spaceused", spaceused, FSAL_ATTR_SPACEUSED, (fsal_size_t) 12345); 01001 01002 CHANGE_ATTRS("mounted_on_fileid", mounted_on_fileid, 01003 FSAL_ATTR_MOUNTFILEID, (fsal_u64_t) 3210); 01004 01005 CHANGE_ATTRS("owner", owner, FSAL_ATTR_OWNER, 3051); /* deniel */ 01006 01007 CHANGE_ATTRS("group", group, FSAL_ATTR_GROUP, 5953); /* sr */ 01008 01009 sleep(1); 01010 01011 /* removes the parent directory */ 01012 printf("------- Removes the directory -------\n"); 01013 01014 if(FSAL_IS_ERROR(st = FSAL_unlink(&handle, &name, &op_ctx, &attribs))) 01015 { 01016 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 01017 } 01018 else 01019 { 01020 01021 printf("Unlink %s OK\n", name.name); 01022 01023 } 01024 01025 } 01026 else if(test[0] == 'A') 01027 { 01028 01029 char digest_buff[FSAL_DIGEST_SIZE_HDLV3]; 01030 01031 /* lookup on /cea/prot/S/lama/s8/leibovic */ 01032 01033 if(FSAL_IS_ERROR(st = FSAL_str2path("/cea/prot/S/lama/s8/leibovic", 40, &path))) 01034 { 01035 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 01036 } 01037 attribs.asked_attributes = mask; 01038 if(FSAL_IS_ERROR(st = FSAL_lookupPath(&path, &op_ctx, &handle, &attribs))) 01039 { 01040 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 01041 } 01042 01043 snprintHandle(tracebuff, 256, &handle); 01044 printf("/cea/prot/S/lama/s8/leibovic: handle = %s\n", tracebuff); 01045 01046 /* building digest */ 01047 01048 st = FSAL_DigestHandle(&export_ctx, FSAL_DIGEST_NFSV3, &handle, digest_buff); 01049 01050 if(FSAL_IS_ERROR(st)) 01051 { 01052 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 01053 } 01054 else 01055 { 01056 /* print digest */ 01057 snprintmem(tracebuff, 256, digest_buff, FSAL_DIGEST_SIZE_HDLV3); 01058 printf("/cea/prot/S/lama/s8/leibovic: handle_digest = %s\n", tracebuff); 01059 } 01060 01061 memset(&handle, 0, sizeof(fsal_handle_t)); 01062 01063 /* expend digest */ 01064 01065 st = FSAL_ExpandHandle(&export_ctx, FSAL_DIGEST_NFSV3, digest_buff, &handle); 01066 01067 if(FSAL_IS_ERROR(st)) 01068 { 01069 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 01070 } 01071 else 01072 { 01073 /* print expended handle */ 01074 snprintHandle(tracebuff, 256, &handle); 01075 printf("/cea/prot/S/lama/s8/leibovic: handle expended = %s\n", tracebuff); 01076 } 01077 01078 } 01079 else if(test[0] == 'B') 01080 { 01081 01082 fsal_dynamicfsinfo_t dyninfo; 01083 01084 if(FSAL_IS_ERROR(st = FSAL_dynamic_fsinfo(&root_handle, &op_ctx, &dyninfo))) 01085 { 01086 DisplayErrorJd(log_desc, ERR_FSAL, st.major, st.minor); 01087 exit(st.major); 01088 } 01089 01090 printf("total_bytes = %llu\n", dyninfo.total_bytes); 01091 printf("free_bytes = %llu\n", dyninfo.free_bytes); 01092 printf("avail_bytes = %llu\n", dyninfo.avail_bytes); 01093 printf("total_files = %llu\n", dyninfo.total_files); 01094 printf("free_files = %llu\n", dyninfo.free_files); 01095 printf("avail_files = %llu\n", dyninfo.avail_files); 01096 printf("time_delta = %u.%u\n", dyninfo.time_delta.seconds, 01097 dyninfo.time_delta.nseconds); 01098 01099 } 01100 else 01101 printf("%s : test inconnu\n", test); 01102 01103 return 0; 01104 01105 }