]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/findlib/fstype.c
Apply patch from Leo to fix bug 2192
[bacula/bacula] / bacula / src / findlib / fstype.c
index d90e5fd8ba13c2d9d7e89b05b6aa6509bf939d76..07cf94343191c33b1b7014a7b9bb334fb9ceb598 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-2018 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.
@@ -12,7 +11,7 @@
    Public License, v3.0 ("AGPLv3") and some additional permissions and
    terms pursuant to its AGPLv3 Section 7.
 
-   This notice must be preserved when any source code is 
+   This notice must be preserved when any source code is
    conveyed and/or propagated.
 
    Bacula(R) is a registered trademark of Kern Sibbald.
@@ -86,15 +85,6 @@ void add_mtab_item(void *user_ctx, struct stat *st, const char *fstype,
    }
 }
 
-/* Compare directly the FS from a fname with a string */
-bool fstype_cmp(FF_PKT *ff_pkt, const char *fsname)
-{
-   char buf[256];
-   if (fstype(ff_pkt, buf, sizeof(buf))) {
-      return (strcmp(buf, fsname) == 0);
-   }
-   return false;
-}
 
 /*
  * These functions should be implemented for each OS
@@ -103,6 +93,7 @@ bool fstype_cmp(FF_PKT *ff_pkt, const char *fsname)
  */
 #if defined(HAVE_DARWIN_OS) \
    || defined(HAVE_FREEBSD_OS ) \
+   || defined(HAVE_KFREEBSD_OS ) \
    || defined(HAVE_OPENBSD_OS)
 
 #include <sys/param.h>
@@ -303,6 +294,7 @@ bool fstype(FF_PKT *ff_pkt, char *fs, int fslen)
 /* Tru64 */
 #include <sys/stat.h>
 #include <sys/mount.h>
+#include <sys/mnttab.h>
 
 bool fstype(FF_PKT *ff_pkt, char *fs, int fslen)
 {
@@ -324,6 +316,35 @@ bool fstype(FF_PKT *ff_pkt, char *fs, int fslen)
 }
 /* Tru64 */
 
+#elif defined (HAVE_WIN32)
+/* Windows */
+bool fstype(FF_PKT *ff_pkt, char *fs, int fslen)
+{
+   char *fname = ff_pkt->fname;
+   DWORD componentlength;
+   DWORD fsflags;
+   CHAR rootpath[4];
+   UINT oldmode;
+   BOOL result;
+
+   /* Copy Drive Letter, colon, and backslash to rootpath */
+   bstrncpy(rootpath, fname, sizeof(rootpath));
+
+   /* We don't want any popups if there isn't any media in the drive */
+   oldmode = SetErrorMode(SEM_FAILCRITICALERRORS);
+   result = GetVolumeInformation(rootpath, NULL, 0, NULL, &componentlength, &fsflags, fs, fslen);
+   SetErrorMode(oldmode);
+
+   if (result) {
+      /* Windows returns NTFS, FAT, etc.  Make it lowercase to be consistent with other OSes */
+      lcase(fs);
+   } else {
+      Dmsg2(10, "GetVolumeInformation() failed for \"%s\", Error = %d.\n", rootpath, GetLastError());
+   }
+   return result != 0;
+}
+/* Windows */
+
 #else    /* No recognised OS */
 
 bool fstype(FF_PKT *ff_pkt, char *fs, int fslen)
@@ -336,7 +357,10 @@ bool fstype(FF_PKT *ff_pkt, char *fs, int fslen)
 
 /* Read mtab entries  */
 bool read_mtab(mtab_handler_t *mtab_handler, void *user_ctx)
-{ 
+{
+/* Debian stretch GNU/KFreeBSD has both getmntinfo and getmntent, but
+   only the first seems to work, so we skip over getmntent in this case */
+#ifndef HAVE_KFREEBSD_OS
 #ifdef HAVE_GETMNTENT
    FILE *mntfp;
    struct stat st;
@@ -369,7 +393,7 @@ bool read_mtab(mtab_handler_t *mtab_handler, void *user_ctx)
    struct mnttab mnt;
 
    P(mutex);
-   if ((mntfp = fopen(MNTTAB, "r")) == NULL) {
+   if ((mntfp = bfopen(MNTTAB, "r")) == NULL) {
       V(mutex);
       return false;
    }
@@ -389,6 +413,7 @@ bool read_mtab(mtab_handler_t *mtab_handler, void *user_ctx)
 #endif
 
 #endif /* HAVE_GETMNTENT */
+#endif /* HAVE_KFREEBSD_OS */
 
 #ifdef HAVE_GETMNTINFO
    struct stat st;