]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/findlib/fstype.c
Fix Solaris 10 problems reported by Phil Stracchino
[bacula/bacula] / bacula / src / findlib / fstype.c
index 41c874445f41058357c7a81ec58673112e19807a..1ae6909436337baf4064e080fd24f57edb6f02cc 100644 (file)
@@ -1,8 +1,7 @@
 /*
    Bacula(R) - The Network Backup Solution
 
-   Copyright (C) 2000-2015 Kern Sibbald
-   Copyright (C) 2004-2014 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2017 Kern Sibbald
 
    The original author of Bacula is Kern Sibbald, with contributions
    from many others, a complete list can be found in the file AUTHORS.
@@ -68,9 +67,9 @@ static int compare_mtab_items(void *item1, void *item2)
    return 0;
 }
 
-void add_mtab_item(void *user_ctx, struct stat *st, const char *fstype,
-                      const char *mountpoint, const char *mntopts,
-                      const char *fsname)
+static void add_mtab_item(void *user_ctx, struct stat *st, const char *fstype,
+               const char *mountpoint, const char *mntopts,
+               const char *fsname)
 {
    rblist *mtab_list = (rblist *)user_ctx;
    mtab_item *item, *ritem;
@@ -191,7 +190,7 @@ bool fstype(FF_PKT *ff_pkt, char *fs, int fslen)
          ff_pkt->last_fstype = st.f_type;
          bstrncpy(ff_pkt->last_fstypename, item->fstype, sizeof(ff_pkt->last_fstypename));
          bstrncpy(fs, ff_pkt->last_fstypename, fslen);
-         return true;
+         return true; 
       }
       /*
        * Values obtained from statfs(2), testing and
@@ -273,7 +272,7 @@ bool fstype(FF_PKT *ff_pkt, char *fs, int fslen)
       case 0x858458f6:     fstype = "tmpfs"; break;         /* RAMFS_MAGIC */
       case 0x01021994:     fstype = "tmpfs"; break;         /* TMPFS_MAGIC */
 #endif
-
       default:
          Dmsg2(10, "Unknown file system type \"0x%x\" for \"%s\".\n", st.f_type,
                fname);
@@ -292,6 +291,7 @@ bool fstype(FF_PKT *ff_pkt, char *fs, int fslen)
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/mtab.h>
 
 bool fstype(FF_PKT *ff_pkt, char *fs, int fslen)
 {
@@ -304,7 +304,7 @@ bool fstype(FF_PKT *ff_pkt, char *fs, int fslen)
 /* Tru64 */
 #include <sys/stat.h>
 #include <sys/mount.h>
-
 bool fstype(FF_PKT *ff_pkt, char *fs, int fslen)
 {
    char *fname = ff_pkt->fname;
@@ -338,7 +338,41 @@ bool fstype(FF_PKT *ff_pkt, char *fs, int fslen)
 /* Read mtab entries  */
 bool read_mtab(mtab_handler_t *mtab_handler, void *user_ctx)
 { 
-#ifdef HAVE_GETMNTENT
+/* Debian stretch GNU/KFreeBSD has both getmntinfo and getmntent, but
+   only the first seems to work, so ordering is important here */
+#ifdef HAVE_GETMNTINFO
+   struct stat st;
+#if defined(ST_NOWAIT)
+   int flags = ST_NOWAIT;
+#elif defined(MNT_NOWAIT)
+   int flags = MNT_NOWAIT;
+#else
+   int flags = 0;
+#endif
+#if defined(HAVE_NETBSD_OS)
+   struct statvfs *mntinfo;
+#else
+   struct statfs *mntinfo;
+#endif
+   int nument;
+
+   P(mutex);
+   if ((nument = getmntinfo(&mntinfo, flags)) > 0) {
+      while (nument-- > 0) {
+         if (is_rootfs(mntinfo->f_fstypename)) {
+            continue;
+         }
+         if (stat(mntinfo->f_mntonname, &st) < 0) {
+            continue;
+         }
+         mtab_handler(user_ctx, &st, mntinfo->f_mntfromname,
+            mntinfo->f_mntonname, mntinfo->f_fstypename, NULL);
+         mntinfo++;
+      }
+   }
+   V(mutex);
+/* HAVE_GETMNTINFO */
+#elif defined(HAVE_GETMNTENT)
    FILE *mntfp;
    struct stat st;
  
@@ -390,42 +424,9 @@ bool read_mtab(mtab_handler_t *mtab_handler, void *user_ctx)
 #endif
 
 #endif /* HAVE_GETMNTENT */
-
-#ifdef HAVE_GETMNTINFO
-   struct stat st;
-#if defined(ST_NOWAIT)
-   int flags = ST_NOWAIT;
-#elif defined(MNT_NOWAIT)
-   int flags = MNT_NOWAIT;
-#else
-   int flags = 0;
-#endif
-#if defined(HAVE_NETBSD_OS)
-   struct statvfs *mntinfo;
-#else
-   struct statfs *mntinfo;
-#endif
-   int nument;
-
-   P(mutex);
-   if ((nument = getmntinfo(&mntinfo, flags)) > 0) {
-      while (nument-- > 0) {
-         if (is_rootfs(mntinfo->f_fstypename)) {
-            continue;
-         }
-         if (stat(mntinfo->f_mntonname, &st) < 0) {
-            continue;
-         }
-         mtab_handler(user_ctx, &st, mntinfo->f_mntfromname,
-            mntinfo->f_mntonname, mntinfo->f_fstypename, NULL);
-         mntinfo++;
-      }
-   }
-   V(mutex);
-#endif /* HAVE_GETMNTINFO */
    return true;
 } 
-
 #ifdef TEST_PROGRAM
 int main(int argc, char **argv)
 {