root/ompi/mca/io/romio321/romio/adio/common/shfp_fname.c

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

DEFINITIONS

This source file includes following definitions.
  1. ADIOI_Shfp_fname

   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 "adio.h"
   9 
  10 #ifdef HAVE_UNISTD_H
  11 #include <unistd.h>
  12 #endif
  13 #ifdef HAVE_SYS_TYPES_H
  14 #include <sys/types.h>
  15 #endif
  16 
  17 #ifdef HAVE_TIME_H
  18 #include <time.h>
  19 #endif
  20 /* The following function selects the name of the file to be used to 
  21    store the shared file pointer. The shared-file-pointer file is a 
  22    hidden file in the same directory as the real file being accessed.
  23    If the real file is /tmp/thakur/testfile, the shared-file-pointer
  24    file will be /tmp/thakur/.testfile.shfp.yyy.xxxx, where yyy
  25    is rank 0's process id and xxxx is a random number. If the
  26    underlying file system supports shared file pointers
  27    (PVFS does not, for example), the file name is always
  28    constructed. This file is created only if the shared
  29    file pointer functions are used and is deleted when the real
  30    file is closed. */
  31 
  32 void ADIOI_Shfp_fname(ADIO_File fd, int rank, int *error_code)
  33 {
  34     int i;
  35     int len;
  36     char *slash, *ptr, tmp[128];
  37     int pid = 0;
  38 
  39     fd->shared_fp_fname = (char *) ADIOI_Malloc(PATH_MAX);
  40 
  41     if (!rank) {
  42         srand(time(NULL));
  43         i = rand();
  44         pid = (int)getpid();
  45         
  46         if (ADIOI_Strncpy(fd->shared_fp_fname, fd->filename, PATH_MAX)) {
  47             *error_code = ADIOI_Err_create_code("ADIOI_Shfp_fname",
  48                     fd->filename, ENAMETOOLONG);
  49             return;
  50         }
  51         
  52 #ifdef ROMIO_NTFS
  53         slash = strrchr(fd->filename, '\\');
  54 #else
  55         slash = strrchr(fd->filename, '/');
  56 #endif
  57         if (!slash) {
  58             if (ADIOI_Strncpy(fd->shared_fp_fname, ".", 2)) {
  59                 *error_code = ADIOI_Err_create_code("ADIOI_Shfp_fname",
  60                         fd->filename, ENAMETOOLONG);
  61                 return;
  62             }
  63             if (ADIOI_Strncpy(fd->shared_fp_fname + 1, fd->filename, PATH_MAX-1)) {
  64                 *error_code = ADIOI_Err_create_code("ADIOI_Shfp_fname",
  65                         fd->filename, ENAMETOOLONG);
  66                 return;
  67             }
  68         }
  69         else {
  70             ptr = slash;
  71 #ifdef ROMIO_NTFS
  72                 slash = strrchr(fd->shared_fp_fname, '\\');
  73 #else
  74             slash = strrchr(fd->shared_fp_fname, '/');
  75 #endif
  76             if (ADIOI_Strncpy(slash + 1, ".", 2))  {
  77                 *error_code = ADIOI_Err_create_code("ADIOI_Shfp_fname",
  78                         fd->filename, ENAMETOOLONG);
  79                 return;
  80             }
  81             /* ok to cast: file names bounded by PATH_MAX and NAME_MAX */
  82             len = (int) (PATH_MAX - (slash+2 - fd->shared_fp_fname));
  83             if (ADIOI_Strncpy(slash + 2, ptr + 1, len)) {
  84                 *error_code = ADIOI_Err_create_code("ADIOI_Shfp_fname",
  85                         ptr + 1, ENAMETOOLONG);
  86                 return;
  87             }
  88         }
  89             
  90         ADIOI_Snprintf(tmp, 128, ".shfp.%d.%d", pid, i);
  91         /* ADIOI_Strnapp will return non-zero if truncated.  That's ok */
  92         ADIOI_Strnapp(fd->shared_fp_fname, tmp, PATH_MAX);
  93         
  94         len = (int)strlen(fd->shared_fp_fname);
  95         MPI_Bcast(&len, 1, MPI_INT, 0, fd->comm);
  96         MPI_Bcast(fd->shared_fp_fname, len+1, MPI_CHAR, 0, fd->comm);
  97     }
  98     else {
  99         MPI_Bcast(&len, 1, MPI_INT, 0, fd->comm);
 100         MPI_Bcast(fd->shared_fp_fname, len+1, MPI_CHAR, 0, fd->comm);
 101     }
 102 }

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