00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
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 
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 
00079 
00080 
00081 
00082 
00083 
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   
00092   
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   
00110   
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     
00118     case S_MAGIC_ACFS:      
00119     case S_MAGIC_AFS:       
00120     case S_MAGIC_AUFS:      
00121     case S_MAGIC_CEPH:       
00122     case S_MAGIC_CIFS:      
00123     case S_MAGIC_CODA:      
00124     case S_MAGIC_FHGFS:     
00125     case S_MAGIC_FUSEBLK:   
00126     case S_MAGIC_FUSECTL:   
00127     case S_MAGIC_GFS:       
00128     case S_MAGIC_GPFS:      
00129     case S_MAGIC_IBRIX:     
00130     case S_MAGIC_KAFS:      
00131     case S_MAGIC_LUSTRE:    
00132     case S_MAGIC_NCP:       
00133     case S_MAGIC_NFS:       
00134     case S_MAGIC_NFSD:      
00135     case S_MAGIC_OCFS2:     
00136     case S_MAGIC_OVERLAYFS: 
00137     case S_MAGIC_PANFS:     
00138     case S_MAGIC_PIPEFS:     
00139     case S_MAGIC_PRL_FS:    
00140     case S_MAGIC_SMB:       
00141     case S_MAGIC_SMB2:      
00142     case S_MAGIC_SNFS:      
00143     case S_MAGIC_VMHGFS:    
00144     case S_MAGIC_VXFS:      
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