]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Update open-vm-tools to build with either Fuse 3 or Fuse 2
authorJohn Wolfe <jwolfe@vmware.com>
Tue, 21 Dec 2021 20:48:50 +0000 (12:48 -0800)
committerJohn Wolfe <jwolfe@vmware.com>
Tue, 21 Dec 2021 20:48:50 +0000 (12:48 -0800)
Vendors are requesting that open-vm-tools can be built with either
Fuse 2 or Fuse 3.  While both Fuse 2 and Fuse 3 runtime can be
installed on a Linux system, vendors would prefer to switch from
Fuse 2 to Fuse 3 at the same time for all products to be available
with the base OS.

Updating the configure.ac file to check for the presence of the Fuse 3
or Fuse 2 development packages in the build environment.  Providing
configure options to allow users to control the version of Fuse to be
used.
 --without-fuse       - vmblock-fuse and vmhgfs-fuse will be disabled.
 --with-fuse=fuse3|3  - use Fuse 3.x
 --with-fuse=fuse|2   - use Fuse 2.x
 --with-fuse=auto     - check for Fuse 3 or Fuse 2 availability; disable
                        vmblock-fuse and vmhgfs-fuse if unavailable.
 --with-fuse          - implicit "yes".
 --with-fuse=yes      - check for Fuse 3 or Fuse 2 availability; disable
                        vmblock-fuse and vmhgfs-fuse if unavailable.

Pull request: https://github.com/vmware/open-vm-tools/pull/544
Fixes issue:  https://github.com/vmware/open-vm-tools/issues/314

The vmblock-fuse code is also used by WorkStation.  Configure defines
are not available in internal builds.  Reworked preprocessor tests to
use FUSE_MAJOR_VERSION from the fuse headers to determine API to be
used during compilation.

12 files changed:
open-vm-tools/AUTHORS
open-vm-tools/configure.ac
open-vm-tools/tests/testVmblock/Makefile.am
open-vm-tools/vmblock-fuse/Makefile.am
open-vm-tools/vmblock-fuse/fsops.c
open-vm-tools/vmblock-fuse/fsops.h
open-vm-tools/vmblock-fuse/main.c
open-vm-tools/vmhgfs-fuse/Makefile.am
open-vm-tools/vmhgfs-fuse/config.c
open-vm-tools/vmhgfs-fuse/dir.c
open-vm-tools/vmhgfs-fuse/main.c
open-vm-tools/vmhgfs-fuse/module.h

index 262a999518ca7d6b14491e188700ad902fa1959d..bb6d0c663c3bb305f34bede4dab7d2db16785ad9 100644 (file)
@@ -76,3 +76,6 @@ Vincent Milum Jr  Adding FreeBSD on ARM64 support to open-vm-tools.
 
 Miroslav Rezanina   Fix issues using GCC 11 with gtk >= 3.20 and glib >=2.66.3
                 - https://github.com/vmware/open-vm-tools/pull/505
+
+Marco Trevisan  Update open-vm-tools to build with either Fuse 3 or Fuse 2
+                - https://github.com/vmware/open-vm-tools/pull/544
index 1a7b70000c81833c138a59c88313e93a907fa582..2c4f097f9541937ef79bad156db621d5866ba3ed 100644 (file)
@@ -540,16 +540,93 @@ fi
 #
 # Check for fuse.
 #
-AC_VMW_CHECK_LIB([fuse],
-                 [FUSE],
-                 [fuse],
-                 [],
-                 [],
-                 [fuse.h],
-                 [fuse_main],
-                 [have_fuse=yes],
-                 [have_fuse=no;
-                  AC_MSG_WARN([Fuse is missing, vmblock-fuse/vmhgfs-fuse will be disabled.])])
+
+AC_ARG_WITH([fuse],
+   [AS_HELP_STRING([--without-fuse],
+     [compiles without FUSE support (disables vmblock-fuse/vmhgfs-fuse).])],
+   [with_fuse="$withval"],
+   [with_fuse=auto])
+
+case "$with_fuse" in
+   fuse|2)
+      with_fuse="fuse"
+      ;;
+   fuse3|3)
+      with_fuse="fuse3"
+      ;;
+   auto)
+      ;;
+   yes)
+      ;;
+   no)
+      have_fuse3=no;
+      have_fuse=no;
+      ;;
+   *)
+      AC_MSG_FAILURE([--with-fuse was given with an unsupported paramter $with_fuse])
+      ;;
+esac
+
+
+if test "$with_fuse" = "auto" ||
+   test "$with_fuse" = "fuse3" ||
+   test "$with_fuse" = "yes"; then
+   #
+   # Check for fuse3.
+   #
+   # FUSE_USE_VERSION sets the version of the FUSE API that will be exported.
+   AC_VMW_CHECK_LIB([fuse3],
+                    [FUSE3],
+                    [fuse3],
+                    [],
+                    [3.10.0],
+                    [fuse3/fuse.h],
+                    [fuse_main],
+                    [have_fuse3=yes;
+                     AC_DEFINE([HAVE_FUSE3], 1, [Define to 1 if using FUSE3.])
+                     AC_DEFINE([FUSE_USE_VERSION], 35, [FUSE API version to use.])],
+                    [have_fuse3=no])
+
+   if test "$have_fuse3" = "no"; then
+      if test "$with_fuse" = "auto" || test "$with_fuse" = "yes"; then
+         AC_MSG_NOTICE([Fuse3 is missing, trying to use older Fuse library.])
+      else
+         AC_MSG_FAILURE([Fuse3 was requested but unavailable on the system.])
+      fi
+   fi
+fi
+
+if test "$with_fuse" = "fuse" ||
+   ( ( test "$with_fuse" = "auto" || test "$with_fuse" = "yes" ) &&
+     test "$have_fuse3" = "no" ); then
+   #
+   # Check for fuse.
+   #
+   # FUSE_USE_VERSION sets the version of the FUSE API that will be exported.
+   AC_VMW_CHECK_LIB([fuse],
+                    [FUSE],
+                    [fuse],
+                    [],
+                    [],
+                    [fuse.h],
+                    [fuse_main],
+                    [have_fuse=yes;
+                     AC_DEFINE([HAVE_FUSE], 1, [Define to 1 if using FUSE.])
+                     AC_DEFINE([FUSE_USE_VERSION], 29, [FUSE API version to use.])],
+                    [have_fuse=no])
+
+   if test "$have_fuse" = "no"; then
+      if test "$with_fuse" = "auto" || test "$with_fuse" = "yes"; then
+        AC_MSG_NOTICE([Fuse is missing, vmblock-fuse/vmhgfs-fuse will be disabled.])
+      else
+         AC_MSG_FAILURE([Fuse2 was requested but unavailable on the system.])
+      fi
+   fi
+fi
+
+if test "$with_fuse" = "no"; then
+   AC_MSG_WARN([Fuse or Fuse3 is suppressed, vmblock-fuse/vmhgfs-fuse will be disabled.])
+fi
 
 #
 # Check for PAM.
@@ -1607,7 +1684,8 @@ AM_CONDITIONAL(HAVE_XCOMPOSITE, test "$have_xcomposite" = "yes")
 AM_CONDITIONAL(ENABLE_TESTS, test "$have_cunit" = "yes")
 AM_CONDITIONAL(WITH_ROOT_PRIVILEGES, test "$with_root_privileges" = "yes")
 AM_CONDITIONAL(HAVE_DOXYGEN, test "$have_doxygen" = "yes")
-AM_CONDITIONAL(HAVE_FUSE, test "$have_fuse" = "yes")
+AM_CONDITIONAL(HAVE_FUSE, test "$have_fuse" = "yes" || test "$have_fuse3" = "yes")
+AM_CONDITIONAL(HAVE_FUSE3, test "$have_fuse3" = "yes")
 AM_CONDITIONAL(HAVE_GNU_LD, test "$with_gnu_ld" = "yes")
 AM_CONDITIONAL(HAVE_GTKMM, test "$have_x" = "yes" -a \( "$with_gtkmm" = "yes" -o "$with_gtkmm3" = "yes" \) )
 AM_CONDITIONAL(HAVE_PAM, test "$with_pam" = "yes")
index 3c44b4046bae32d8a4c0e1a1b8d59b1198fab29d..543b2f8138fe9c5dd3ba0baa831cb8ba4e173cfc 100644 (file)
 ### Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 ################################################################################
 
+  noinst_PROGRAMS =
 if HAVE_FUSE
-  noinst_PROGRAMS = vmware-testvmblock-fuse
+  noinst_PROGRAMS += vmware-testvmblock-fuse
+  noinst_PROGRAMS += vmware-testvmblock-manual-fuse
+endif
+if HAVE_FUSE3
+  noinst_PROGRAMS += vmware-testvmblock-fuse
   noinst_PROGRAMS += vmware-testvmblock-manual-fuse
-else
-  noinst_PROGRAMS = vmware-testvmblock-legacy
-  noinst_PROGRAMS += vmware-testvmblock-manual-legacy
 endif
 
 AM_CFLAGS =
@@ -30,10 +32,6 @@ AM_CFLAGS += -DVMX86_DEBUG
 AM_LDFLAGS =
 AM_LDFLAGS += -lpthread
 
-vmware_testvmblock_legacy_SOURCES = vmblocktest.c
-
-vmware_testvmblock_manual_legacy_SOURCES = manual-blocker.c
-
 vmware_testvmblock_fuse_CFLAGS = $(AM_CFLAGS) -Dvmblock_fuse
 vmware_testvmblock_fuse_SOURCES = vmblocktest.c
 
index 9018096c40cdcc033bb464a51b2669e7ea30a293..81ff0acacb815e2b08a5d8548912eb010144cf62 100644 (file)
@@ -1,5 +1,5 @@
 ################################################################################
-### Copyright (C) 2008-2016 VMware, Inc.  All rights reserved.
+### Copyright (c) 2008-2016,2021 VMware, Inc.  All rights reserved.
 ###
 ### This program is free software; you can redistribute it and/or modify
 ### it under the terms of version 2 of the GNU General Public License as
@@ -29,12 +29,14 @@ AM_CFLAGS += -D_XOPEN_SOURCE=600
 AM_CFLAGS += -DUSERLEVEL
 AM_CFLAGS += -D_FILE_OFFSET_BITS=64
 AM_CFLAGS += @FUSE_CPPFLAGS@
+AM_CFLAGS += @FUSE3_CPPFLAGS@
 AM_CFLAGS += @GLIB2_CPPFLAGS@
 AM_CFLAGS += -I$(top_srcdir)/modules/shared/vmblock
 AM_CFLAGS += -I$(srcdir)
 
 vmware_vmblock_fuse_LDADD =
 vmware_vmblock_fuse_LDADD += @FUSE_LIBS@
+vmware_vmblock_fuse_LDADD += @FUSE3_LIBS@
 vmware_vmblock_fuse_LDADD += @GLIB2_LIBS@
 
 vmware_vmblock_fuse_SOURCES =
index c14d78d4763d12409b9a136b830b011bf18efbeb..cedcb74790995e58c6dbbb314780e5b81d17d224 100644 (file)
@@ -65,6 +65,14 @@ static vmblockSpecialDirEntry symlinkDirEntry =
 static vmblockSpecialDirEntry notifyDirEntry =
    { NOTIFY_DIR "/*",   S_IFREG | 0444, 1, 0 };
 
+#if FUSE_MAJOR_VERSION == 3
+#define CALL_FUSE_FILLER(buf, name, stbuf, off, flags) \
+   filler(buf, name, stbuf, off, flags)
+#else
+#define CALL_FUSE_FILLER(buf, name, stbuf, off, flags) \
+   filler(buf, name, stbuf, off)
+#endif
+
 /*
  *-----------------------------------------------------------------------------
  *
@@ -248,9 +256,16 @@ SetTimesToNow(struct stat *statBuf)      // OUT
  *-----------------------------------------------------------------------------
  */
 
+#if FUSE_MAJOR_VERSION == 3
+int
+VMBlockGetAttr(const char *path,          // IN: File to get attributes of.
+               struct stat *statBuf,      // OUT: Where to put the attributes.
+               struct fuse_file_info *fi) // IN: Ignored
+#else
 int
 VMBlockGetAttr(const char *path,        // IN: File to get attributes of.
                struct stat *statBuf)    // OUT: Where to put the attributes.
+#endif
 {
    vmblockSpecialDirEntry *dirEntry;
    ASSERT(path != NULL);
@@ -362,7 +377,7 @@ ExternalReadDir(const char *blockPath,           // IN:
    errno = 0;
 
    while ((dentry = readdir(dir)) != NULL) {
-      status = filler(buf, dentry->d_name, &statBuf, 0);
+      status = CALL_FUSE_FILLER(buf, dentry->d_name, &statBuf, 0, 0);
       if (status == 1) {
          break;
       }
@@ -408,6 +423,17 @@ ExternalReadDir(const char *blockPath,           // IN:
  *-----------------------------------------------------------------------------
  */
 
+#if FUSE_MAJOR_VERSION == 3
+int
+VMBlockReadDir(const char *path,                // IN: Directory to read.
+               void *buf,                       // OUT: Where to put directory
+                                                //      listing.
+               fuse_fill_dir_t filler,          // IN: Function to add an entry
+                                                //     to buf.
+               off_t offset,                    // IN: Ignored.
+               struct fuse_file_info *fileInfo, // IN: Ignored.
+               enum fuse_readdir_flags flags)   // IN: Ignored.
+#else
 int
 VMBlockReadDir(const char *path,                // IN: Directory to read.
                void *buf,                       // OUT: Where to put directory
@@ -416,6 +442,7 @@ VMBlockReadDir(const char *path,                // IN: Directory to read.
                                                 //     to buf.
                off_t offset,                    // IN: Ignored.
                struct fuse_file_info *fileInfo) // IN: Ignored.
+#endif
 {
    struct stat fileStat;
    struct stat dirStat;
@@ -433,11 +460,11 @@ VMBlockReadDir(const char *path,                // IN: Directory to read.
    dirStat.st_mode = S_IFDIR;
 
    if (strcmp(path, "/") == 0) {
-      (void)(filler(buf, ".", &dirStat, 0) ||
-             filler(buf, "..", &dirStat, 0) ||
-             filler(buf, VMBLOCK_DEVICE_NAME, &fileStat, 0) ||
-             filler(buf, REDIRECT_DIR_NAME, &dirStat, 0) ||
-             filler(buf, NOTIFY_DIR_NAME, &dirStat, 0));
+      (void)(CALL_FUSE_FILLER(buf, ".", &dirStat, 0, 0) ||
+             CALL_FUSE_FILLER(buf, "..", &dirStat, 0, 0) ||
+             CALL_FUSE_FILLER(buf, VMBLOCK_DEVICE_NAME, &fileStat, 0, 0) ||
+             CALL_FUSE_FILLER(buf, REDIRECT_DIR_NAME, &dirStat, 0, 0) ||
+             CALL_FUSE_FILLER(buf, NOTIFY_DIR_NAME, &dirStat, 0, 0));
       return 0;
    } else if (   (strcmp(path, REDIRECT_DIR) == 0)
               || (strcmp(path, NOTIFY_DIR) == 0)) {
@@ -764,8 +791,19 @@ VMBlockRelease(const char *path,                   // IN: Must be control file.
  *-----------------------------------------------------------------------------
  */
 
+#if FUSE_MAJOR_VERSION == 3
+void *
+VMBlockInit(struct fuse_conn_info *conn,
+            struct fuse_config *config)
+#else
+#if FUSE_USE_VERSION < 26
 void *
 VMBlockInit(void)
+#else
+void *
+VMBlockInit(struct fuse_conn_info *conn)
+#endif
+#endif
 {
    BlockInit();
    return NULL;
index 2f16c8bcd0102423577dfefad729c9f10cb4f979..a067abdf84c8233fe70f316edd58861d77c84e26 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2008-2018 VMware, Inc. All rights reserved.
+ * Copyright (C) 2008-2018,2021 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
 #ifndef _VMBLOCK_FUSE_H_
 #define _VMBLOCK_FUSE_H_
 
+/*
+ *  FUSE_USE_VERSION must be set before the fuse or fuse3 headers are
+ *  included.  If undefined, fall back to previous default used.
+ */
+#ifndef FUSE_USE_VERSION
 /*
  * FUSE_USE_VERSION sets the version of the FUSE API that will be exported.
  * Version 25 is the newest version supported by the libfuse in our toolchain
  * as of 2008-07.
  */
-
 #define FUSE_USE_VERSION 25
+#endif
+
 #include <fuse.h>
 
 #include "vmblock.h"
  */
 
 int VMBlockReadLink(const char *path, char *buf, size_t bufSize);
+
+#if FUSE_MAJOR_VERSION == 3
+int VMBlockGetAttr(const char *path, struct stat *statBuf,
+                   struct fuse_file_info *fi);
+int VMBlockReadDir(const char *path, void *buf, fuse_fill_dir_t filler,
+                   off_t offset, struct fuse_file_info *fileInfo,
+                   enum fuse_readdir_flags);
+#else
 int VMBlockGetAttr(const char *path, struct stat *statBuf);
 int VMBlockReadDir(const char *path, void *buf, fuse_fill_dir_t filler,
                    off_t offset, struct fuse_file_info *fileInfo);
+#endif
 int VMBlockOpen(const char *path, struct fuse_file_info *fileInfo);
 int VMBlockWrite(const char *path, const char *buf, size_t size, off_t offset,
                  struct fuse_file_info *fileInfo);
index bc07670a383b2679a80beeacf77f2e98320c8b10..c9952473f2aa7d4c4185deeab39e93b28e788617 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2008-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 2008-2016,2021 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -66,5 +66,9 @@ main(int argc,           // IN
          LOGLEVEL_THRESHOLD = 4;
       }
    }
+#if FUSE_USE_VERSION < 26
    return fuse_main(argc, argv, &vmblockOperations);
+#else
+   return fuse_main(argc, argv, &vmblockOperations, NULL);
+#endif
 }
index 19089a08e95efd865209d5f51b3c8b2926efa49c..731431b74c0523df1f0bbf6e0cd245907009c14e 100644 (file)
@@ -1,5 +1,5 @@
 ################################################################################
-### Copyright (C) 2015-2016 VMware, Inc.  All rights reserved.
+### Copyright (c) 2015-2016,2021 VMware, Inc.  All rights reserved.
 ###
 ### This program is free software; you can redistribute it and/or modify
 ### it under the terms of version 2 of the GNU General Public License as
@@ -19,10 +19,12 @@ bin_PROGRAMS = vmhgfs-fuse
 
 AM_CFLAGS =
 AM_CFLAGS += @FUSE_CPPFLAGS@
+AM_CFLAGS += @FUSE3_CPPFLAGS@
 AM_CFLAGS += @GLIB2_CPPFLAGS@
 
 vmhgfs_fuse_LDADD =
 vmhgfs_fuse_LDADD += @FUSE_LIBS@
+vmhgfs_fuse_LDADD += @FUSE3_LIBS@
 vmhgfs_fuse_LDADD += @GLIB2_LIBS@
 vmhgfs_fuse_LDADD += @VMTOOLS_LIBS@
 
index c6125e9db79f9a0814ae391702c731c843997932..fe0cda9da2b6267b932d81d3830448f53c6b061e 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2015-2018 VMware, Inc. All rights reserved.
+ * Copyright (C) 2015-2018,2021 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -22,6 +22,7 @@
  */
 
 #include "module.h"
+#include <fuse_lowlevel.h>
 #include <sys/utsname.h>
 
 #ifdef VMX86_DEVEL
@@ -76,8 +77,10 @@ const struct fuse_opt vmhgfsOpts[] = {
      VMHGFS_OPT("-l %i",            logLevel, 4),
 #endif
      /* We will change the default value, unless it is specified explicitly. */
+#if FUSE_MAJOR_VERSION != 3
      FUSE_OPT_KEY("big_writes",     KEY_BIG_WRITES),
      FUSE_OPT_KEY("nobig_writes",   KEY_NO_BIG_WRITES),
+#endif
 
      FUSE_OPT_KEY("-V",             KEY_VERSION),
      FUSE_OPT_KEY("--version",      KEY_VERSION),
@@ -131,8 +134,13 @@ Usage(char *prog_name)  // IN
 
 #define LIB_MODULEPATH         "/lib/modules"
 #define MODULES_DEP            "modules.dep"
+#if FUSE_MAJOR_VERSION == 3
+#define FUSER_MOUNT_BIN        "/bin/fusermount3"
+#define FUSER_MOUNT_USR_BIN    "/usr/bin/fusermount3"
+#else
 #define FUSER_MOUNT_BIN        "/bin/fusermount"
 #define FUSER_MOUNT_USR_BIN    "/usr/bin/fusermount"
+#endif
 #define PROC_FILESYSTEMS       "/proc/filesystems"
 #define FUSER_KERNEL_FS        "fuse"
 
@@ -406,7 +414,9 @@ vmhgfsOptProc(void *data,                // IN
               int key,                   // IN
               struct fuse_args *outargs) // OUT
 {
+#if FUSE_MAJOR_VERSION != 3
    struct vmhgfsConfig *config = data;
+#endif
 
    switch (key) {
    case FUSE_OPT_KEY_NONOPT:
@@ -434,6 +444,7 @@ vmhgfsOptProc(void *data,                // IN
       }
       return 1;
 
+#if FUSE_MAJOR_VERSION != 3
    case KEY_BIG_WRITES:
       config->addBigWrites = TRUE;
       return 0;
@@ -441,11 +452,18 @@ vmhgfsOptProc(void *data,                // IN
    case KEY_NO_BIG_WRITES:
       config->addBigWrites = FALSE;
       return 0;
+#endif
 
    case KEY_HELP:
       Usage(outargs->argv[0]);
+#if FUSE_MAJOR_VERSION != 3
       fuse_opt_add_arg(outargs, "-ho");
       fuse_main(outargs->argc, outargs->argv, NULL, NULL);
+#else
+      fprintf(stdout, "FUSE options:\n");
+      fuse_cmdline_help();
+      fuse_lib_help(outargs);
+#endif
       exit(1);
 
    case KEY_ENABLED_FUSE: {
@@ -496,8 +514,8 @@ vmhgfsPreprocessArgs(struct fuse_args *outargs)    // IN/OUT
 #ifdef VMX86_DEVEL
    config.logLevel = LOGLEVEL_THRESHOLD;
 #endif
-#ifdef __APPLE__
-   /* osxfuse does not have option 'big_writes'. */
+#if defined(__APPLE__) || FUSE_MAJOR_VERSION == 3
+   /* osxfuse and fuse3 does not have option 'big_writes'. */
    config.addBigWrites = FALSE;
 #else
    config.addBigWrites = TRUE;
index d5fd1f8b5d8cc5c4d7d6a16ab5218feedfb33a79..b5dcc2945d1d632bc7b19cd9439aeb896f24dfdd 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2013,2019 VMware, Inc. All rights reserved.
+ * Copyright (C) 2013,2019,2021 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -396,7 +396,11 @@ HgfsReadDirFromReply(uint32 *f_pos,     // IN/OUT: Offset
       st.st_size = attr.size;
       st.st_ino = ino;
       st.st_mode = d_type << 12;
+#if FUSE_MAJOR_VERSION == 3
+      result = filldir(vfsDirent, escName, &st, 0, 0);
+#else
       result = filldir(vfsDirent, escName, &st, 0);
+#endif
 
       if (result) {
          /*
index 1ce970b8b5af2ff4cba415ec3a31272634e39a7f..e6d7812bb85be689169c12dea3846dd0773fbcdb 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2013 VMware, Inc. All rights reserved.
+ * Copyright (C) 2013,2021 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
  * Main entry points for fuse file operations for HGFS
  */
 
-#if FUSE_USE_VERSION >= 26
-#define HAVE_UTIMENSAT 1
-#endif
-
 #include "module.h"
 #include "cache.h"
 #include "filesystem.h"
@@ -119,9 +115,16 @@ freeAbsPath(char *abspath)  // IN
  *----------------------------------------------------------------------
  */
 
+#if FUSE_MAJOR_VERSION == 3
+static int
+hgfs_getattr(const char *path,           //IN: path of a file/directory
+             struct stat *stbuf,         //IN/OUT: file/directoy attribute
+             struct fuse_file_info *fi)  //IN/OUT: Unused
+#else
 static int
 hgfs_getattr(const char *path,    //IN: path of a file/directory
              struct stat *stbuf)  //IN/OUT: file/directoy attribute
+#endif
 {
    HgfsHandle fileHandle = HGFS_INVALID_HANDLE;
    HgfsAttrInfo newAttr = {0};
@@ -365,12 +368,22 @@ exit:
  *----------------------------------------------------------------------
  */
 
+#if FUSE_MAJOR_VERSION == 3
+static int
+hgfs_readdir(const char *path,              //IN: path to a directory
+             void *buf,                     //OUT: buffer to fill the dir entry
+             fuse_fill_dir_t filler,        //IN: function pointer to fill buf
+             off_t offset,                  //IN: offset to read the dir
+             struct fuse_file_info *fi,     //IN: file info set by open call
+             enum fuse_readdir_flags flags) //IN: unused
+#else
 static int
 hgfs_readdir(const char *path,          //IN: path to a directory
              void *buf,                 //OUT: buffer to fill the dir entry
              fuse_fill_dir_t filler,    //IN: function pointer to fill buf
              off_t offset,              //IN: offset to read the dir
              struct fuse_file_info *fi) //IN: file info set by open call
+#endif
 {
    char *abspath = NULL;
    int res = 0;
@@ -602,9 +615,16 @@ exit:
  *----------------------------------------------------------------------
  */
 
+#if FUSE_MAJOR_VERSION == 3
+static int
+hgfs_rename(const char *from,    //IN: from path name
+            const char *to,      //IN: to path name
+            unsigned int flags)  //IN: unused
+#else
 static int
 hgfs_rename(const char *from,  //IN: from path name
             const char *to)    //IN: to path name
+#endif
 {
    char *absfrom = NULL;
    char *absto = NULL;
@@ -695,9 +715,16 @@ exit:
  *----------------------------------------------------------------------
  */
 
+#if FUSE_MAJOR_VERSION == 3
+static int
+hgfs_chmod(const char *path,          //IN: path to a file
+           mode_t mode,               //IN: mode to set
+           struct fuse_file_info *fi) //IN/OUT: unused
+#else
 static int
 hgfs_chmod(const char *path,   //IN: path to a file
            mode_t mode)        //IN: mode to set
+#endif
 {
    char *abspath = NULL;
    int res;
@@ -760,10 +787,18 @@ exit:
  *----------------------------------------------------------------------
  */
 
+#if FUSE_MAJOR_VERSION == 3
+static int
+hgfs_chown(const char *path,           //IN: Path to a file
+           uid_t uid,                  //IN: User id
+           gid_t gid,                  //IN: Group id
+           struct fuse_file_info *fi)  //IN/OUT: unused
+#else
 static int
 hgfs_chown(const char *path,  //IN: Path to a file
            uid_t uid,         //IN: User id
            gid_t gid)         //IN: Group id
+#endif
 {
    HgfsHandle fileHandle = HGFS_INVALID_HANDLE;
    HgfsAttrInfo newAttr = {0};
@@ -823,9 +858,16 @@ exit:
  *----------------------------------------------------------------------
  */
 
+#if FUSE_MAJOR_VERSION == 3
+static int
+hgfs_truncate(const char *path,           //IN: path to a file
+              off_t size,                 //IN: new size
+              struct fuse_file_info *fi)  //IN/OUT: unused
+#else
 static int
 hgfs_truncate(const char *path,  //IN: path to a file
               off_t size)        //IN: new size
+#endif
 {
    HgfsHandle fileHandle = HGFS_INVALID_HANDLE;
    HgfsAttrInfo newAttr = {0};
@@ -884,14 +926,15 @@ exit:
  *----------------------------------------------------------------------
  */
 
-#ifdef HAVE_UTIMENSAT
+#if FUSE_MAJOR_VERSION == 3
 static int
 hgfs_utimens(const char *path,              //IN: path to a file
-             const struct timespec ts[2])   //IN: new time
+             const struct timespec ts[2],   //IN: new time
+             struct fuse_file_info *fi)     //IN/OUT: unused
 #else
 static int
-hgfs_utime(const char *path,        //IN: path to a file
-           struct utimbuf *times)   //IN: new time
+hgfs_utimens(const char *path,              //IN: path to a file
+             const struct timespec ts[2])   //IN: new time
 #endif
 {
    HgfsHandle fileHandle = HGFS_INVALID_HANDLE;
@@ -936,17 +979,10 @@ hgfs_utime(const char *path,        //IN: path to a file
    attr->mask = (HGFS_ATTR_VALID_WRITE_TIME |
                  HGFS_ATTR_VALID_ACCESS_TIME);
 
-#ifdef HAVE_UTIMENSAT
    accessTimeSec = ts[0].tv_sec;
    accessTimeNsec = ts[0].tv_nsec;
    writeTimeSec = ts[1].tv_sec;
    writeTimeNsec = ts[1].tv_nsec;
-#else
-   accessTimeSec = times->actime;
-   accessTimeNsec = 0;
-   writeTimeSec = times->modtime;
-   writeTimeNsec = 0;
-#endif
    attr->accessTime = HgfsConvertToNtTime(accessTimeSec, accessTimeNsec);
    attr->writeTime = HgfsConvertToNtTime(writeTimeSec, writeTimeNsec);
 
@@ -1249,8 +1285,14 @@ exit:
  *----------------------------------------------------------------------
  */
 
+#if FUSE_MAJOR_VERSION == 3
+static void*
+hgfs_init(struct fuse_conn_info *conn, // IN: unused
+          struct fuse_config *cfg)     // IN/OUT: unused
+#else
 static void*
 hgfs_init(struct fuse_conn_info *conn) // IN: unused
+#endif
 {
    pthread_t purgeCacheThread;
    int dummy;
@@ -1335,11 +1377,7 @@ static struct fuse_operations vmhgfs_operations = {
    .chmod       = hgfs_chmod,
    .chown       = hgfs_chown,
    .truncate    = hgfs_truncate,
-#ifdef HAVE_UTIMENSAT
    .utimens     = hgfs_utimens,
-#else // HAVE_UTIMENSAT
-   .utime       = hgfs_utime,
-#endif // defined HAVE_UTIMENSAT
    .open        = hgfs_open,
    .read        = hgfs_read,
    .write       = hgfs_write,
index 7d0f1b01d2ad696c4041e22afcc50c6432b4d2ce..61f88e10025d56a12e63d2d93e941a246fb5cb43 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 2013 VMware, Inc. All rights reserved.
+ * Copyright (C) 2013,2021 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
 #ifndef _VMHGFS_FUSE_MODULE_H_
 #define _VMHGFS_FUSE_MODULE_H_
 
-#define FUSE_USE_VERSION 29
+/*
+ * FUSE_USE_VERSION must be set before the fuse or fuse3 headers are
+ * included.  If undefined, fall back to previous default used.
+ */
+#ifndef FUSE_USE_VERSION
+#   define FUSE_USE_VERSION 29
+#endif
 
 #include <sys/types.h>
 #include "hgfsUtil.h"