00001
00002
00003
00004
00005
00006
00007
00008 #include "ad_piofs.h"
00009
00010 void ADIOI_PIOFS_Open(ADIO_File fd, int *error_code)
00011 {
00012 int amode, perm, old_mask, err;
00013 piofs_fstat_t piofs_fstat;
00014 char *value;
00015 #ifndef PRINT_ERR_MSG
00016 static char myname[] = "ADIOI_PIOFS_OPEN";
00017 #endif
00018
00019 if (fd->perm == ADIO_PERM_NULL) {
00020 old_mask = umask(022);
00021 umask(old_mask);
00022 perm = old_mask ^ 0666;
00023 }
00024 else perm = fd->perm;
00025
00026 amode = 0;
00027 if (fd->access_mode & ADIO_CREATE)
00028 amode = amode | O_CREAT;
00029 if (fd->access_mode & ADIO_RDONLY)
00030 amode = amode | O_RDONLY;
00031 if (fd->access_mode & ADIO_WRONLY)
00032 amode = amode | O_WRONLY;
00033 if (fd->access_mode & ADIO_RDWR)
00034 amode = amode | O_RDWR;
00035 if (fd->access_mode & ADIO_EXCL)
00036 amode = amode | O_EXCL;
00037
00038 fd->fd_sys = open(fd->filename, amode, perm);
00039 fd->fd_direct = -1;
00040
00041 llseek(fd->fd_sys, 0, SEEK_SET);
00042
00043
00044 if (fd->fd_sys != -1) {
00045 value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
00046
00047
00048 err = piofsioctl(fd->fd_sys, PIOFS_FSTAT, &piofs_fstat);
00049
00050 if (!err) {
00051 ADIOI_Snprintf(value, MPI_MAX_INFO_VAL+1, "%d", piofs_fstat.st_bsu);
00052 ADIOI_Info_set(fd->info, "striping_unit", value);
00053
00054 ADIOI_Snprintf(value, MPI_MAX_INFO_VAL+1, "%d", piofs_fstat.st_cells);
00055 ADIOI_Info_set(fd->info, "striping_factor", value);
00056
00057 ADIOI_Snprintf(value, MPI_MAX_INFO_VAL+1, "%d", piofs_fstat.st_base_node);
00058 ADIOI_Info_set(fd->info, "start_iodevice", value);
00059 }
00060 ADIOI_Free(value);
00061
00062 if (fd->access_mode & ADIO_APPEND)
00063 fd->fp_ind = fd->fp_sys_posn = llseek(fd->fd_sys, 0, SEEK_END);
00064 }
00065
00066 if (fd->fd_sys == -1) {
00067 #ifdef MPICH2
00068 *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
00069 "**io %s", strerror(errno));
00070 #elif defined(PRINT_ERR_MSG)
00071 *error_code = MPI_ERR_UNKNOWN;
00072 #else
00073 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00074 myname, "I/O Error", "%s", strerror(errno));
00075 ADIOI_Error(ADIO_FILE_NULL, *error_code, myname);
00076 #endif
00077 }
00078 else *error_code = MPI_SUCCESS;
00079 }