00001
00002
00003
00004
00005
00006
00007
00008 #include "ad_nfs.h"
00009
00010 void ADIOI_NFS_Open(ADIO_File fd, int *error_code)
00011 {
00012 int perm, amode;
00013 mode_t old_mask;
00014 static char myname[] = "ADIOI_NFS_OPEN";
00015
00016 if (fd->perm == ADIO_PERM_NULL) {
00017 old_mask = umask(022);
00018 umask(old_mask);
00019 perm = old_mask ^ 0666;
00020 }
00021 else perm = fd->perm;
00022
00023 amode = 0;
00024 if (fd->access_mode & ADIO_CREATE)
00025 amode = amode | O_CREAT;
00026 if (fd->access_mode & ADIO_RDONLY)
00027 amode = amode | O_RDONLY;
00028 if (fd->access_mode & ADIO_WRONLY)
00029 amode = amode | O_WRONLY;
00030 if (fd->access_mode & ADIO_RDWR)
00031 amode = amode | O_RDWR;
00032 if (fd->access_mode & ADIO_EXCL)
00033 amode = amode | O_EXCL;
00034
00035 #ifdef ADIOI_MPE_LOGGING
00036 MPE_Log_event( ADIOI_MPE_open_a, 0, NULL );
00037 #endif
00038 fd->fd_sys = open(fd->filename, amode, perm);
00039 #ifdef ADIOI_MPE_LOGGING
00040 MPE_Log_event( ADIOI_MPE_open_b, 0, NULL );
00041 #endif
00042 fd->fd_direct = -1;
00043
00044 if ((fd->fd_sys != -1) && (fd->access_mode & ADIO_APPEND)) {
00045 #ifdef ADIOI_MPE_LOGGING
00046 MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL );
00047 #endif
00048 fd->fp_ind = fd->fp_sys_posn = lseek(fd->fd_sys, 0, SEEK_END);
00049 #ifdef ADIOI_MPE_LOGGING
00050 MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL );
00051 #endif
00052 }
00053
00054 if (fd->fd_sys == -1) {
00055
00056
00057 if (errno == ENAMETOOLONG)
00058 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00059 MPIR_ERR_RECOVERABLE, myname,
00060 __LINE__, MPI_ERR_BAD_FILE,
00061 "**filenamelong",
00062 "**filenamelong %s %d",
00063 fd->filename,
00064 strlen(fd->filename));
00065 else if (errno == ENOENT)
00066 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00067 MPIR_ERR_RECOVERABLE, myname,
00068 __LINE__, MPI_ERR_NO_SUCH_FILE,
00069 "**filenoexist",
00070 "**filenoexist %s",
00071 fd->filename);
00072 else if (errno == ENOTDIR || errno == ELOOP)
00073 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00074 MPIR_ERR_RECOVERABLE, myname,
00075 __LINE__, MPI_ERR_BAD_FILE,
00076 "**filenamedir",
00077 "**filenamedir %s",
00078 fd->filename);
00079 else if (errno == EACCES) {
00080 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00081 MPIR_ERR_RECOVERABLE, myname,
00082 __LINE__, MPI_ERR_ACCESS,
00083 "**fileaccess",
00084 "**fileaccess %s",
00085 fd->filename);
00086 }
00087 else if (errno == EROFS) {
00088
00089 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00090 MPIR_ERR_RECOVERABLE, myname,
00091 __LINE__, MPI_ERR_READ_ONLY,
00092 "**ioneedrd", 0);
00093 }
00094 else {
00095 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00096 MPIR_ERR_RECOVERABLE, myname,
00097 __LINE__, MPI_ERR_IO, "**io",
00098 "**io %s", strerror(errno));
00099 }
00100 }
00101 else *error_code = MPI_SUCCESS;
00102 }