00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "adio.h"
00014
00015 #if (defined(HPUX) || defined(SPPUX) || defined(IRIX) || defined(SOLARIS) || defined(AIX) || defined(DEC) || defined(CRAY))
00016 #include <sys/statvfs.h>
00017 #endif
00018 #ifdef LINUX
00019 #include <sys/vfs.h>
00020
00021 #define NFS_SUPER_MAGIC 0x6969
00022 #endif
00023 #ifdef FREEBSD
00024 #include <sys/param.h>
00025 #include <sys/mount.h>
00026 #endif
00027 #ifdef PARAGON
00028 #include <nx.h>
00029 #include <pfs/pfs.h>
00030 #include <sys/mount.h>
00031 #endif
00032 #ifdef SX4
00033 #include <sys/stat.h>
00034 #endif
00035 #ifdef ROMIO_PVFS
00036 #include "pvfs_config.h"
00037 #include <sys/param.h>
00038 #endif
00039 #ifdef tflops
00040 #include <sys/mount.h>
00041 #endif
00042
00043 #ifdef HAVE_UNISTD_H
00044
00045 #include <unistd.h>
00046 #endif
00047
00048 #ifndef ROMIO_NTFS
00049 static void ADIO_FileSysType_parentdir(char *filename, char **dirnamep);
00050 #endif
00051 static void ADIO_FileSysType_prefix(char *filename, int *fstype,
00052 int *error_code);
00053 static void ADIO_FileSysType_fncall(char *filename, int *fstype,
00054 int *error_code);
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #ifndef ROMIO_NTFS
00070 #ifndef PATH_MAX
00071 #define PATH_MAX 65535
00072 #endif
00073 static void ADIO_FileSysType_parentdir(char *filename, char **dirnamep)
00074 {
00075 int err;
00076 char *dir, *slash;
00077 struct stat statbuf;
00078
00079 err = lstat(filename, &statbuf);
00080
00081 if (err || (!S_ISLNK(statbuf.st_mode))) {
00082
00083
00084
00085 dir = strdup(filename);
00086 }
00087 else {
00088
00089
00090
00091
00092
00093 char *linkbuf;
00094
00095 linkbuf = ADIOI_Malloc(PATH_MAX+1);
00096 err = readlink(filename, linkbuf, PATH_MAX+1);
00097 if (err) {
00098
00099
00100
00101
00102 dir = strdup(filename);
00103 }
00104 else {
00105
00106 dir = strdup(linkbuf);
00107 ADIOI_Free(linkbuf);
00108 }
00109 }
00110
00111 slash = strrchr(dir, '/');
00112 if (!slash) strcpy(dir, ".");
00113 else {
00114 if (slash == dir) *(dir + 1) = 0;
00115 else *slash = '\0';
00116 }
00117
00118 *dirnamep = dir;
00119 return;
00120 }
00121 #endif
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 static void ADIO_FileSysType_fncall(char *filename, int *fstype, int *error_code)
00141 {
00142 #ifndef ROMIO_NTFS
00143 char *dir;
00144 int err;
00145 #endif
00146 #if (defined(HPUX) || defined(SPPUX) || defined(IRIX) || defined(SOLARIS) || defined(AIX) || defined(DEC) || defined(CRAY))
00147 struct statvfs vfsbuf;
00148 #endif
00149 #if (defined(LINUX) || defined(FREEBSD) || defined(tflops))
00150 struct statfs fsbuf;
00151 #endif
00152 #ifdef PARAGON
00153 struct estatfs ebuf;
00154 #endif
00155 #ifdef SX4
00156 struct stat sbuf;
00157 #endif
00158
00159 *error_code = MPI_SUCCESS;
00160
00161 #if (defined(HPUX) || defined(SPPUX) || defined(IRIX) || defined(SOLARIS) || defined(AIX) || defined(DEC) || defined(CRAY))
00162 do {
00163 err = statvfs(filename, &vfsbuf);
00164 } while (err && (errno == ESTALE));
00165
00166 if (err && (errno == ENOENT)) {
00167 ADIO_FileSysType_parentdir(filename, &dir);
00168 err = statvfs(dir, &vfsbuf);
00169 free(dir);
00170 }
00171
00172 if (err) *error_code = MPI_ERR_UNKNOWN;
00173 else {
00174
00175 if (!strncmp(vfsbuf.f_basetype, "nfs", 3)) *fstype = ADIO_NFS;
00176 else {
00177 # if (defined(HPUX) || defined(SPPUX))
00178 # ifdef HFS
00179 *fstype = ADIO_HFS;
00180 # else
00181 *fstype = ADIO_UFS;
00182 # endif
00183 # else
00184 if (!strncmp(vfsbuf.f_basetype, "xfs", 3)) *fstype = ADIO_XFS;
00185 else if (!strncmp(vfsbuf.f_basetype, "piofs", 4)) *fstype = ADIO_PIOFS;
00186 else *fstype = ADIO_UFS;
00187 # endif
00188 }
00189 }
00190 #elif defined(LINUX)
00191 do {
00192 err = statfs(filename, &fsbuf);
00193 } while (err && (errno == ESTALE));
00194
00195 if (err && (errno == ENOENT)) {
00196 ADIO_FileSysType_parentdir(filename, &dir);
00197 err = statfs(dir, &fsbuf);
00198 free(dir);
00199 }
00200
00201 if (err) *error_code = MPI_ERR_UNKNOWN;
00202 else {
00203
00204 if (fsbuf.f_type == NFS_SUPER_MAGIC) *fstype = ADIO_NFS;
00205 # ifdef ROMIO_PVFS
00206 else if (fsbuf.f_type == PVFS_SUPER_MAGIC) *fstype = ADIO_PVFS;
00207 # endif
00208 else *fstype = ADIO_UFS;
00209 }
00210 #elif (defined(FREEBSD) && defined(HAVE_MOUNT_NFS))
00211 do {
00212 err = statfs(filename, &fsbuf);
00213 } while (err && (errno == ESTALE));
00214
00215 if (err && (errno == ENOENT)) {
00216 ADIO_FileSysType_parentdir(filename, &dir);
00217 err = statfs(dir, &fsbuf);
00218 free(dir);
00219 }
00220
00221 if (err) *error_code = MPI_ERR_UNKNOWN;
00222 else {
00223 # if (__FreeBSD_version>300004)
00224 if ( !strncmp("nfs",fsbuf.f_fstypename,3) ) *fstype = ADIO_NFS;
00225 # else
00226 if (fsbuf.f_type == MOUNT_NFS) *fstype = ADIO_NFS;
00227 # endif
00228 else *fstype = ADIO_UFS;
00229 }
00230 #elif defined(PARAGON)
00231 do {
00232 err = statpfs(filename, &ebuf, 0, 0);
00233 } while (err && (errno == ESTALE));
00234
00235 if (err && (errno == ENOENT)) {
00236 ADIO_FileSysType_parentdir(filename, &dir);
00237 err = statpfs(dir, &ebuf, 0, 0);
00238 free(dir);
00239 }
00240
00241 if (err) *error_code = MPI_ERR_UNKNOWN;
00242 else {
00243 if (ebuf.f_type == MOUNT_NFS) *fstype = ADIO_NFS;
00244 else if (ebuf.f_type == MOUNT_PFS) *fstype = ADIO_PFS;
00245 else *fstype = ADIO_UFS;
00246 }
00247 #elif defined(tflops)
00248 do {
00249 err = statfs(filename, &fsbuf);
00250 } while (err && (errno == ESTALE));
00251
00252 if (err && (errno == ENOENT)) {
00253 ADIO_FileSysType_parentdir(filename, &dir);
00254 err = statfs(dir, &fsbuf);
00255 free(dir);
00256 }
00257
00258 if (err) *error_code = MPI_ERR_UNKNOWN;
00259 else {
00260 if (fsbuf.f_type == MOUNT_NFS) *fstype = ADIO_NFS;
00261 else if (fsbuf.f_type == MOUNT_PFS) *fstype = ADIO_PFS;
00262 else *fstype = ADIO_UFS;
00263 }
00264 #elif defined(SX4)
00265 do {
00266 err = stat(filename, &sbuf);
00267 } while (err && (errno == ESTALE));
00268
00269 if (err && (errno == ENOENT)) {
00270 ADIO_FileSysType_parentdir(filename, &dir);
00271 err = stat(dir, &sbuf);
00272 free(dir);
00273 }
00274
00275 if (err) *error_code = MPI_ERR_UNKNOWN;
00276 else {
00277 if (!strcmp(sbuf.st_fstype, "nfs")) *fstype = ADIO_NFS;
00278 else *fstype = ADIO_SFS;
00279 }
00280 #else
00281
00282 # ifdef ROMIO_NTFS
00283 *fstype = ADIO_NTFS;
00284 # else
00285 *fstype = ADIO_NFS;
00286 # endif
00287 *error_code = MPI_SUCCESS;
00288 #endif
00289 }
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 static void ADIO_FileSysType_prefix(char *filename, int *fstype, int *error_code)
00308 {
00309 *error_code = MPI_SUCCESS;
00310
00311 if (!strncmp(filename, "pfs:", 4) || !strncmp(filename, "PFS:", 4)) {
00312 *fstype = ADIO_PFS;
00313 }
00314 else if (!strncmp(filename, "piofs:", 6) || !strncmp(filename, "PIOFS:", 6)) {
00315 *fstype = ADIO_PIOFS;
00316 }
00317 else if (!strncmp(filename, "ufs:", 4) || !strncmp(filename, "UFS:", 4)) {
00318 *fstype = ADIO_UFS;
00319 }
00320 else if (!strncmp(filename, "nfs:", 4) || !strncmp(filename, "NFS:", 4)) {
00321 *fstype = ADIO_NFS;
00322 }
00323 else if (!strncmp(filename, "hfs:", 4) || !strncmp(filename, "HFS:", 4)) {
00324 *fstype = ADIO_HFS;
00325 }
00326 else if (!strncmp(filename, "xfs:", 4) || !strncmp(filename, "XFS:", 4)) {
00327 *fstype = ADIO_XFS;
00328 }
00329 else if (!strncmp(filename, "sfs:", 4) || !strncmp(filename, "SFS:", 4)) {
00330 *fstype = ADIO_SFS;
00331 }
00332 else if (!strncmp(filename, "pvfs:", 5) || !strncmp(filename, "PVFS:", 5)) {
00333 *fstype = ADIO_PVFS;
00334 }
00335 else if (!strncmp(filename, "testfs:", 7)
00336 || !strncmp(filename, "TESTFS:", 7))
00337 {
00338 *fstype = ADIO_TESTFS;
00339 }
00340 else {
00341 #ifdef ROMIO_NTFS
00342 *fstype = ADIO_NTFS;
00343 #else
00344 *fstype = 0;
00345 *error_code = MPI_ERR_UNKNOWN;
00346 #endif
00347 }
00348 }
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369 void ADIO_ResolveFileType(MPI_Comm comm, char *filename, int *fstype,
00370 ADIOI_Fns **ops, int *error_code)
00371 {
00372 #ifndef PRINT_ERR_MSG
00373 static char myname[] = "ADIO_RESOLVEFILETYPE";
00374 #endif
00375 int myerrcode, file_system, min_code;
00376 char *tmp;
00377
00378 file_system = -1;
00379 tmp = strchr(filename, ':');
00380 if (!tmp) {
00381
00382 ADIO_FileSysType_fncall(filename, &file_system, &myerrcode);
00383 if (myerrcode != MPI_SUCCESS) {
00384 #ifdef PRINT_ERR_MSG
00385 FPRINTF(stderr, "ADIO_ResolveFileType: Can't determine the file-system type. Check the filename/path you provided and try again. Otherwise, prefix the filename with a string to indicate the type of file sytem (piofs:, pfs:, nfs:, ufs:, hfs:, xfs:, sfs:, pvfs:).\n");
00386 MPI_Abort(MPI_COMM_WORLD, 1);
00387 #else
00388 myerrcode = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ERR_NO_FSTYPE,
00389 myname, (char *) 0, (char *) 0);
00390 *error_code = ADIOI_Error(MPI_FILE_NULL, myerrcode, myname);
00391 return;
00392 #endif
00393 }
00394
00395
00396 MPI_Allreduce(&file_system, &min_code, 1, MPI_INT, MPI_MIN, comm);
00397 if (min_code == ADIO_NFS) file_system = ADIO_NFS;
00398
00399 }
00400 else {
00401
00402
00403
00404
00405
00406 ADIO_FileSysType_prefix(filename, &file_system, &myerrcode);
00407 if (myerrcode != MPI_SUCCESS) {
00408 #ifdef PRINT_ERR_MSG
00409 FPRINTF(stderr, "ADIO_ResolveFileType: Can't determine the file-system type from the specified prefix. Check the filename/path and prefix you provided and try again.\n");
00410 MPI_Abort(MPI_COMM_WORLD, 1);
00411 #else
00412 myerrcode = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ERR_NO_FSTYPE,
00413 myname, (char *) 0, (char *) 0);
00414 *error_code = ADIOI_Error(MPI_FILE_NULL, myerrcode, myname);
00415 return;
00416 #endif
00417 }
00418 }
00419
00420
00421 if (file_system == ADIO_PFS) {
00422 #ifndef PFS
00423 # ifdef PRINT_ERR_MSG
00424 FPRINTF(stderr, "ADIO_ResolveFileType: ROMIO has not been configured to use the PFS file system\n");
00425 MPI_Abort(MPI_COMM_WORLD, 1);
00426 # else
00427 myerrcode = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ERR_NO_PFS,
00428 myname, (char *) 0, (char *) 0);
00429 *error_code = ADIOI_Error(MPI_FILE_NULL, myerrcode, myname);
00430 return;
00431 # endif
00432 #else
00433 *ops = &ADIO_PFS_operations;
00434 #endif
00435 }
00436 if (file_system == ADIO_PIOFS) {
00437 #ifndef PIOFS
00438 # ifdef PRINT_ERR_MSG
00439 FPRINTF(stderr, "ADIO_ResolveFileType: ROMIO has not been configured to use the PIOFS file system\n");
00440 MPI_Abort(MPI_COMM_WORLD, 1);
00441 # else
00442 myerrcode = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ERR_NO_PIOFS,
00443 myname, (char *) 0, (char *) 0);
00444 *error_code = ADIOI_Error(MPI_FILE_NULL, myerrcode, myname);
00445 return;
00446 # endif
00447 #else
00448 *ops = &ADIO_PIOFS_operations;
00449 #endif
00450 }
00451 if (file_system == ADIO_UFS) {
00452 #ifndef UFS
00453 # ifdef PRINT_ERR_MSG
00454 FPRINTF(stderr, "ADIO_ResolveFileType: ROMIO has not been configured to use the UFS file system\n");
00455 MPI_Abort(MPI_COMM_WORLD, 1);
00456 # else
00457 myerrcode = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ERR_NO_UFS,
00458 myname, (char *) 0, (char *) 0);
00459 *error_code = ADIOI_Error(MPI_FILE_NULL, myerrcode, myname);
00460 return;
00461 # endif
00462 #else
00463 *ops = &ADIO_UFS_operations;
00464 #endif
00465 }
00466 if (file_system == ADIO_NFS) {
00467 #ifndef NFS
00468 # ifdef PRINT_ERR_MSG
00469 FPRINTF(stderr, "ADIO_ResolveFileType: ROMIO has not been configured to use the NFS file system\n");
00470 MPI_Abort(MPI_COMM_WORLD, 1);
00471 # else
00472 myerrcode = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ERR_NO_NFS,
00473 myname, (char *) 0, (char *) 0);
00474 *error_code = ADIOI_Error(MPI_FILE_NULL, myerrcode, myname);
00475 return;
00476 # endif
00477 #else
00478 *ops = &ADIO_NFS_operations;
00479 #endif
00480 }
00481 if (file_system == ADIO_HFS) {
00482 #ifndef HFS
00483 # ifdef PRINT_ERR_MSG
00484 FPRINTF(stderr, "ADIO_ResolveFileType: ROMIO has not been configured to use the HFS file system\n");
00485 MPI_Abort(MPI_COMM_WORLD, 1);
00486 # else
00487 myerrcode = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ERR_NO_HFS,
00488 myname, (char *) 0, (char *) 0);
00489 *error_code = ADIOI_Error(MPI_FILE_NULL, myerrcode, myname);
00490 return;
00491 # endif
00492 #else
00493 *ops = &ADIO_HFS_operations;
00494 #endif
00495 }
00496 if (file_system == ADIO_XFS) {
00497 #ifndef XFS
00498 # ifdef PRINT_ERR_MSG
00499 FPRINTF(stderr, "ADIO_ResolveFileType: ROMIO has not been configured to use the XFS file system\n");
00500 MPI_Abort(MPI_COMM_WORLD, 1);
00501 # else
00502 myerrcode = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ERR_NO_XFS,
00503 myname, (char *) 0, (char *) 0);
00504 *error_code = ADIOI_Error(MPI_FILE_NULL, myerrcode, myname);
00505 return;
00506 # endif
00507 #else
00508 *ops = &ADIO_XFS_operations;
00509 #endif
00510 }
00511 if (file_system == ADIO_SFS) {
00512 #ifndef SFS
00513 # ifdef PRINT_ERR_MSG
00514 FPRINTF(stderr, "ADIO_ResolveFileType: ROMIO has not been configured to use the SFS file system\n");
00515 MPI_Abort(MPI_COMM_WORLD, 1);
00516 # else
00517 myerrcode = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ERR_NO_SFS,
00518 myname, (char *) 0, (char *) 0);
00519 *error_code = ADIOI_Error(MPI_FILE_NULL, myerrcode, myname);
00520 return;
00521 # endif
00522 #else
00523 *ops = &ADIO_SFS_operations;
00524 #endif
00525 }
00526 if (file_system == ADIO_PVFS) {
00527 #ifndef ROMIO_PVFS
00528 # ifdef PRINT_ERR_MSG
00529 FPRINTF(stderr, "ADIO_ResolveFileType: ROMIO has not been configured to use the PVFS file system\n");
00530 MPI_Abort(MPI_COMM_WORLD, 1);
00531 # else
00532 myerrcode = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ERR_NO_PVFS,
00533 myname, (char *) 0, (char *) 0);
00534 *error_code = ADIOI_Error(MPI_FILE_NULL, myerrcode, myname);
00535 return;
00536 # endif
00537 #else
00538 *ops = &ADIO_PVFS_operations;
00539 #endif
00540 }
00541 if (file_system == ADIO_NTFS) {
00542 #ifndef ROMIO_NTFS
00543 # ifdef PRINT_ERR_MSG
00544 FPRINTF(stderr, "ADIO_ResolveFileType: ROMIO has not been configured to use the NTFS file system\n");
00545 MPI_Abort(MPI_COMM_WORLD, 1);
00546 # else
00547 myerrcode = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ERR_NO_NTFS,
00548 myname, (char *) 0, (char *) 0);
00549 *error_code = ADIOI_Error(MPI_FILE_NULL, myerrcode, myname);
00550 return;
00551 # endif
00552 #else
00553 *ops = &ADIO_NTFS_operations;
00554 #endif
00555 }
00556 if (file_system == ADIO_TESTFS) {
00557 #ifndef ROMIO_TESTFS
00558 # ifdef PRINT_ERR_MSG
00559 FPRINTF(stderr, "ADIO_ResolveFileType: ROMIO has not been configured to use the TESTFS file system\n");
00560 MPI_Abort(MPI_COMM_WORLD, 1);
00561 # else
00562 myerrcode = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ERR_NO_TESTFS,
00563 myname, (char *) 0, (char *) 0);
00564 *error_code = ADIOI_Error(MPI_FILE_NULL, myerrcode, myname);
00565 return;
00566 # endif
00567 #else
00568 *ops = &ADIO_TESTFS_operations;
00569 #endif
00570 }
00571 *error_code = MPI_SUCCESS;
00572 *fstype = file_system;
00573 return;
00574 }