root/ompi/mca/fs/base/fs_base_get_parent_dir.c

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

DEFINITIONS

This source file includes following definitions.
  1. mca_fs_base_get_parent_dir
  2. mca_fs_base_get_fstype

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2011 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2008-2016 University of Houston. All rights reserved.
  13  * Copyright (c) 2015-2016 Research Organization for Information Science
  14  *                         and Technology (RIST). All rights reserved.
  15  * Copyright (c) 2018      Cisco Systems, Inc.  All rights reserved
  16  * $COPYRIGHT$
  17  *
  18  * Additional copyrights may follow
  19  *
  20  * $HEADER$
  21  */
  22 
  23 
  24 #include "ompi_config.h"
  25 
  26 #include <stdio.h>
  27 
  28 #include "opal/mca/base/base.h"
  29 #include "opal/util/path.h"
  30 #include "opal/util/printf.h"
  31 #include "opal/util/string_copy.h"
  32 
  33 #include "ompi/mca/mca.h"
  34 #include "ompi/mca/fs/fs.h"
  35 #include "ompi/mca/fs/base/base.h"
  36 #include "ompi/mca/common/ompio/common_ompio.h"
  37 
  38 #ifdef HAVE_SYS_STATFS_H
  39 #include <sys/statfs.h> /* or <sys/vfs.h> */
  40 #endif
  41 #ifdef HAVE_SYS_PARAM_H
  42 #include <sys/param.h>
  43 #endif
  44 #ifdef HAVE_SYS_MOUNT_H
  45 #include <sys/mount.h>
  46 #endif
  47 #ifdef HAVE_SYS_STAT_H
  48 #include <sys/stat.h>
  49 #endif
  50 #ifdef HAVE_UNISTD_H
  51 #include <unistd.h>
  52 #endif
  53 
  54 void mca_fs_base_get_parent_dir ( char *filename, char **dirnamep)
  55 {
  56     int err;
  57     char *dir = NULL, *slash;
  58     struct stat statbuf;
  59 
  60     if (strlen(filename) < 1) {
  61         opal_asprintf(dirnamep, ".%s", OPAL_PATH_SEP);
  62         return;
  63     }
  64 
  65     err = lstat(filename, &statbuf);
  66 
  67     if (err || (!S_ISLNK(statbuf.st_mode))) {
  68         /* no such file, or file is not a link; these are the "normal"
  69          * cases where we can just return the parent directory.
  70          */
  71         dir = strdup(filename);
  72     }
  73     else {
  74         /* filename is a symlink.  we've presumably already tried
  75          * to stat it and found it to be missing (dangling link),
  76          * but this code doesn't care if the target is really there
  77          * or not.
  78          */
  79         int namelen;
  80         char linkbuf[PATH_MAX+1];
  81 
  82         namelen = readlink(filename, linkbuf, PATH_MAX);
  83         if (namelen == -1) {
  84             /* something strange has happened between the time that
  85              * we determined that this was a link and the time that
  86              * we attempted to read it; punt and use the old name.
  87              */
  88             dir = strdup(filename);
  89         }
  90         else {
  91             /* successfully read the link */
  92             linkbuf[namelen] = '\0'; /* readlink doesn't null terminate */
  93             dir = strdup(linkbuf);
  94         }
  95     }
  96 
  97     slash = strrchr(dir, '/');
  98     if (!slash) {
  99         // It is guaranteed in this case that "dir" will be at least 2
 100         // characters long.
 101         opal_string_copy(dir, ".", 2);
 102     } else {
 103         if (slash == dir) {
 104             *(dir + 1) = '\0';
 105         } else {
 106             *slash = '\0';
 107         }
 108     }
 109 
 110     *dirnamep = dir;
 111     return;
 112 }
 113 
 114 int  mca_fs_base_get_fstype(char *fname )
 115 {
 116     int ompio_type = UFS;
 117     char *fstype=NULL;
 118     bool ret = opal_path_nfs ( fname, &fstype );
 119 
 120     if ( false == ret ) {
 121         char *dir;
 122         mca_fs_base_get_parent_dir (fname, &dir );
 123         ret = opal_path_nfs (dir, &fstype);
 124         free(dir);
 125         if ( false == ret ) {
 126             return ompio_type;
 127         }
 128     }
 129     if ( 0 == strncasecmp(fstype, "lustre", sizeof("lustre")) ) {
 130         ompio_type = LUSTRE;
 131     }
 132     else if ( 0 == strncasecmp(fstype, "pvfs2", sizeof("pvfs2"))) {
 133         ompio_type = PVFS2;
 134     }
 135     else if ( 0 == strncasecmp(fstype, "ime", sizeof("ime"))) {
 136         ompio_type = IME;
 137     }
 138 
 139     free (fstype);
 140     return ompio_type;
 141 }
 142 

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