00001
00002
00003
00004
00005
00006
00007
00008 #include "ad_ufs.h"
00009
00010 void ADIOI_UFS_Open(ADIO_File fd, int *error_code)
00011 {
00012 int perm, old_mask, amode;
00013 static char myname[] = "ADIOI_UFS_OPEN";
00014
00015 if (fd->perm == ADIO_PERM_NULL) {
00016 old_mask = umask(022);
00017 umask(old_mask);
00018 perm = old_mask ^ 0666;
00019 }
00020 else perm = fd->perm;
00021
00022 amode = 0;
00023 if (fd->access_mode & ADIO_CREATE)
00024 amode = amode | O_CREAT;
00025 if (fd->access_mode & ADIO_RDONLY)
00026 amode = amode | O_RDONLY;
00027 if (fd->access_mode & ADIO_WRONLY)
00028 amode = amode | O_WRONLY;
00029 if (fd->access_mode & ADIO_RDWR)
00030 amode = amode | O_RDWR;
00031 if (fd->access_mode & ADIO_EXCL)
00032 amode = amode | O_EXCL;
00033
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
00055 if (fd->fd_sys == -1) {
00056 if (errno == ENAMETOOLONG)
00057 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00058 MPIR_ERR_RECOVERABLE, myname,
00059 __LINE__, MPI_ERR_BAD_FILE,
00060 "**filenamelong",
00061 "**filenamelong %s %d",
00062 fd->filename,
00063 strlen(fd->filename));
00064 else if (errno == ENOENT)
00065 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00066 MPIR_ERR_RECOVERABLE, myname,
00067 __LINE__, MPI_ERR_NO_SUCH_FILE,
00068 "**filenoexist",
00069 "**filenoexist %s",
00070 fd->filename);
00071 else if (errno == ENOTDIR || errno == ELOOP)
00072 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00073 MPIR_ERR_RECOVERABLE,
00074 myname, __LINE__,
00075 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
00102 else *error_code = MPI_SUCCESS;
00103 }