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