Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

vmdfsinfo.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr
00003  *cr            (C) Copyright 1995-2019 The Board of Trustees of the
00004  *cr                        University of Illinois
00005  *cr                         All Rights Reserved
00006  *cr
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  * RCS INFORMATION:
00011  *
00012  *      $RCSfile: vmdfsinfo.c,v $
00013  *      $Author: johns $        $Locker:  $             $State: Exp $
00014  *      $Revision: 1.2 $      $Date: 2019/05/22 18:54:04 $
00015  *
00016  ***************************************************************************
00017  * DESCRIPTION:
00018  *   Routines for file and filesystem locality determination.
00019  *
00020  * LICENSE:
00021  *   UIUC Open Source License
00022  *   http://www.ks.uiuc.edu/Research/vmd/plugins/pluginlicense.html
00023  *
00024  ***************************************************************************/
00025 
00026 #include <stdio.h>
00027 #include <string.h>
00028 
00029 #if defined(__sun)
00030 #include <sys/types.h>
00031 #include <sys/statvfs.h>
00032 #endif
00033 
00034 #if defined(__linux__) || defined(__ANDROID__)
00035 #include <sys/statfs.h>
00036 #include <sys/vfs.h>
00037 #endif
00038 
00039 #if defined(__linux__) || defined(__ANDROID__)
00040 /* Linux-specific constants from coreutils' src/fs.h */
00041 #define  S_MAGIC_ACFS      0x61636673 
00042 #define  S_MAGIC_AFS       0x5346414F
00043 #define  S_MAGIC_AUFS      0x61756673 
00044 #define  S_MAGIC_CEPH      0x00C36400
00045 #define  S_MAGIC_CIFS      0xFF534D42
00046 #define  S_MAGIC_CODA      0x73757245
00047 #define  S_MAGIC_FHGFS     0x19830326
00048 #define  S_MAGIC_FUSEBLK   0x65735546
00049 #define  S_MAGIC_FUSECTL   0x65735543
00050 #define  S_MAGIC_GFS       0x01161970
00051 #define  S_MAGIC_GPFS      0x47504653
00052 #define  S_MAGIC_IBRIX     0x013111A8
00053 #define  S_MAGIC_KAFS      0x6B414653
00054 #define  S_MAGIC_LUSTRE    0x0BD00BD0
00055 #define  S_MAGIC_NCP       0x564C
00056 #define  S_MAGIC_NFS       0x6969
00057 #define  S_MAGIC_NFSD      0x6E667364
00058 #define  S_MAGIC_OCFS2     0x7461636F
00059 #define  S_MAGIC_OVERLAYFS 0x794C7630
00060 #define  S_MAGIC_PANFS     0xAAD7AAEA
00061 #define  S_MAGIC_PIPEFS    0x50495045
00062 #define  S_MAGIC_PRL_FS    0x7C7C6673
00063 #define  S_MAGIC_SMB       0x517B
00064 #define  S_MAGIC_SMB2      0xFE534D42
00065 #define  S_MAGIC_SNFS      0xBEEFDEAD
00066 #define  S_MAGIC_VMHGFS    0xBACBACBC
00067 #define  S_MAGIC_VXFS      0xA501FCF5
00068 #endif
00069 
00070 
00071 #define FS_ERROR       -1
00072 #define FS_IS_LOCAL     1
00073 #define FS_IS_REMOTE    2
00074 #define FS_IS_UNKNOWN   4
00075 
00076 
00077 /*
00078  * Determine locality of the specified file's filesystem.
00079  * Some systems have statfvs.f_basetype[FSTYPSZ] (AIX, HP-UX, and Solaris).
00080  * Others have statvfs.f_fstypename[_VFS_NAMELEN] (NetBSD 3.0).
00081  * Others have statfs.f_fstypename[MFSNAMELEN] (NetBSD 1.5.2).
00082  * Still others have neither and have to get by with f_type (GNU/Linux).
00083  * But f_type may only exist in statfs (Cygwin).  
00084  */
00085 int vmd_fstype_locality(const char *pathname) {
00086   int fstype = FS_IS_UNKNOWN;
00087 
00088 #if defined(__sun)
00089   struct statvfs svfs;
00090 
00091   /* check filesystem info for the listed file, determine */
00092   /* if the file is on a local or remote filesystem       */
00093   memset(&svfs, 0, sizeof(svfs));
00094   if (statvfs(pathname, &svfs) < 0)
00095     return FS_ERROR;
00096 
00097 #if 0
00098   printf("VFS basetype: %s\n", svfs.f_basetype);
00099 #endif
00100   if (!strcmp(svfs.f_basetype, "nfs"))
00101     fstype = FS_IS_REMOTE;
00102   else 
00103     fstype = FS_IS_LOCAL;
00104 #endif
00105 
00106 #if defined(__linux__) || defined(__ANDROID__)
00107   struct statfs sfs;
00108 
00109   // check filesystem info for the listed file, determine
00110   // if the file is on a local or remote filesystem
00111   memset(&sfs, 0, sizeof(sfs));
00112   if (statfs(pathname, &sfs) < 0)
00113     return FS_ERROR;
00114 
00115   switch (sfs.f_type) { 
00116 #if defined(__linux__) || defined(__ANDROID__)
00117     /* Linux-specific constants from coreutils' src/fs.h */
00118     case S_MAGIC_ACFS:      /* 0x61636673 remote */
00119     case S_MAGIC_AFS:       /* 0x5346414F remote */
00120     case S_MAGIC_AUFS:      /* 0x61756673 remote */
00121     case S_MAGIC_CEPH:      /* 0x00C36400 remote */ 
00122     case S_MAGIC_CIFS:      /* 0xFF534D42 remote */
00123     case S_MAGIC_CODA:      /* 0x73757245 remote */
00124     case S_MAGIC_FHGFS:     /* 0x19830326 remote */
00125     case S_MAGIC_FUSEBLK:   /* 0x65735546 remote */
00126     case S_MAGIC_FUSECTL:   /* 0x65735543 remote */
00127     case S_MAGIC_GFS:       /* 0x01161970 remote */
00128     case S_MAGIC_GPFS:      /* 0x47504653 remote */
00129     case S_MAGIC_IBRIX:     /* 0x013111A8 remote */
00130     case S_MAGIC_KAFS:      /* 0x6B414653 remote */
00131     case S_MAGIC_LUSTRE:    /* 0x0BD00BD0 remote */
00132     case S_MAGIC_NCP:       /* 0x564C remote */
00133     case S_MAGIC_NFS:       /* 0x6969 remote */
00134     case S_MAGIC_NFSD:      /* 0x6E667364 remote */
00135     case S_MAGIC_OCFS2:     /* 0x7461636F remote */
00136     case S_MAGIC_OVERLAYFS: /* 0x794C7630 remote */
00137     case S_MAGIC_PANFS:     /* 0xAAD7AAEA remote */
00138     case S_MAGIC_PIPEFS:    /* 0x50495045 remote */ 
00139     case S_MAGIC_PRL_FS:    /* 0x7C7C6673 remote */
00140     case S_MAGIC_SMB:       /* 0x517B remote */
00141     case S_MAGIC_SMB2:      /* 0xFE534D42 remote */
00142     case S_MAGIC_SNFS:      /* 0xBEEFDEAD remote */
00143     case S_MAGIC_VMHGFS:    /* 0xBACBACBC remote */
00144     case S_MAGIC_VXFS:      /* 0xA501FCF5 remote */
00145 #endif
00146 #if __GNU__
00147     case FSTYPE_NFS:
00148     case FSTYPE_AFS:
00149     case FSTYPE_FTP:
00150     case FSTYPE_HTTP:
00151 #endif
00152 #if defined(__linux__) || defined(__ANDROID__) || defined (__GNU__)
00153       fstype = FS_IS_REMOTE;
00154 #endif
00155 
00156     default:
00157       fstype = FS_IS_LOCAL;
00158   }
00159 #endif
00160 
00161   return fstype;
00162 }
00163 

Generated on Fri Nov 8 02:45:45 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002