00001
00002
00003
00004
00005
00006
00007
00008 #include "ad_sfs.h"
00009
00010 void ADIOI_SFS_Open(ADIO_File fd, int *error_code)
00011 {
00012 int perm, old_mask, amode;
00013 #ifndef PRINT_ERR_MSG
00014 static char myname[] = "ADIOI_SFS_OPEN";
00015 #endif
00016
00017 if (fd->perm == ADIO_PERM_NULL) {
00018 old_mask = umask(022);
00019 umask(old_mask);
00020 perm = old_mask ^ 0666;
00021 }
00022 else perm = fd->perm;
00023
00024 amode = 0;
00025 if (fd->access_mode & ADIO_CREATE)
00026 amode = amode | O_CREAT;
00027 if (fd->access_mode & ADIO_RDONLY)
00028 amode = amode | O_RDONLY;
00029 if (fd->access_mode & ADIO_WRONLY)
00030 amode = amode | O_WRONLY;
00031 if (fd->access_mode & ADIO_RDWR)
00032 amode = amode | O_RDWR;
00033 if (fd->access_mode & ADIO_EXCL)
00034 amode = amode | O_EXCL;
00035
00036 fd->fd_sys = open(fd->filename, amode, perm);
00037 fd->fd_direct = -1;
00038
00039 if ((fd->fd_sys != -1) && (fd->access_mode & ADIO_APPEND)) {
00040 fd->fp_ind = llseek(fd->fd_sys, 0, SEEK_END);
00041 fd->fp_sys_posn = fd->fp_ind;
00042 }
00043
00044 if (fd->fd_sys == -1) {
00045 #ifdef MPICH2
00046 *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
00047 "**io %s", strerror(errno));
00048 #elif defined(PRINT_ERR_MSG)
00049 *error_code = MPI_ERR_UNKNOWN;
00050 #else
00051 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00052 myname, "I/O Error", "%s", strerror(errno));
00053 ADIOI_Error(ADIO_FILE_NULL, *error_code, myname);
00054 #endif
00055 }
00056 else *error_code = MPI_SUCCESS;
00057 }