root/ompi/mca/io/romio321/romio/adio/ad_piofs/ad_piofs_open.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ADIOI_PIOFS_Open

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
   2 /* 
   3  *
   4  *   Copyright (C) 1997 University of Chicago. 
   5  *   See COPYRIGHT notice in top-level directory.
   6  */
   7 
   8 #include "ad_piofs.h"
   9 
  10 void ADIOI_PIOFS_Open(ADIO_File fd, int *error_code)
  11 {
  12     int amode, perm, old_mask, err;
  13     piofs_fstat_t piofs_fstat;
  14     char *value;
  15 #ifndef PRINT_ERR_MSG
  16     static char myname[] = "ADIOI_PIOFS_OPEN";
  17 #endif
  18 
  19     if (fd->perm == ADIO_PERM_NULL) {
  20         old_mask = umask(022);
  21         umask(old_mask);
  22         perm = old_mask ^ 0666;
  23     }
  24     else perm = fd->perm;
  25 
  26     amode = 0;
  27     if (fd->access_mode & ADIO_CREATE)
  28         amode = amode | O_CREAT;
  29     if (fd->access_mode & ADIO_RDONLY)
  30         amode = amode | O_RDONLY;
  31     if (fd->access_mode & ADIO_WRONLY)
  32         amode = amode | O_WRONLY;
  33     if (fd->access_mode & ADIO_RDWR)
  34         amode = amode | O_RDWR;
  35     if (fd->access_mode & ADIO_EXCL)
  36         amode = amode | O_EXCL;
  37 
  38     fd->fd_sys = open(fd->filename, amode, perm);
  39     fd->fd_direct = -1;
  40 
  41     llseek(fd->fd_sys, 0, SEEK_SET);
  42 /* required to initiate use of 64-bit offset */
  43 
  44     if (fd->fd_sys != -1) {
  45         value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
  46 
  47         /* get file striping information and set it in info */
  48         err = piofsioctl(fd->fd_sys, PIOFS_FSTAT, &piofs_fstat);
  49 
  50         if (!err) {
  51             ADIOI_Snprintf(value, MPI_MAX_INFO_VAL+1, "%d", piofs_fstat.st_bsu);
  52             ADIOI_Info_set(fd->info, "striping_unit", value);
  53 
  54             ADIOI_Snprintf(value, MPI_MAX_INFO_VAL+1, "%d", piofs_fstat.st_cells);
  55             ADIOI_Info_set(fd->info, "striping_factor", value);
  56 
  57             ADIOI_Snprintf(value, MPI_MAX_INFO_VAL+1, "%d", piofs_fstat.st_base_node);
  58             ADIOI_Info_set(fd->info, "start_iodevice", value);
  59         }
  60         ADIOI_Free(value);
  61 
  62         if (fd->access_mode & ADIO_APPEND)
  63             fd->fp_ind = fd->fp_sys_posn = llseek(fd->fd_sys, 0, SEEK_END);
  64     }
  65 
  66     if (fd->fd_sys == -1) {
  67 #ifdef MPICH
  68         *error_code = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, myname, __LINE__, MPI_ERR_IO, "**io",
  69             "**io %s", strerror(errno));
  70 #elif defined(PRINT_ERR_MSG)
  71         *error_code =  MPI_ERR_UNKNOWN;
  72 #else /* MPICH-1 */
  73         *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
  74                               myname, "I/O Error", "%s", strerror(errno));
  75         ADIOI_Error(ADIO_FILE_NULL, *error_code, myname);           
  76 #endif
  77     }
  78     else *error_code = MPI_SUCCESS;
  79 }

/* [<][>][^][v][top][bottom][index][help] */