From 97917fce5828ef0efdae59d7bb6e4dd7f0caeae0 Mon Sep 17 00:00:00 2001 From: John Wolfe Date: Tue, 21 Dec 2021 12:48:50 -0800 Subject: [PATCH] Update open-vm-tools to build with either Fuse 3 or Fuse 2 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. --- open-vm-tools/AUTHORS | 3 + open-vm-tools/configure.ac | 100 +++++++++++++++++--- open-vm-tools/tests/testVmblock/Makefile.am | 14 ++- open-vm-tools/vmblock-fuse/Makefile.am | 4 +- open-vm-tools/vmblock-fuse/fsops.c | 50 ++++++++-- open-vm-tools/vmblock-fuse/fsops.h | 19 +++- open-vm-tools/vmblock-fuse/main.c | 6 +- open-vm-tools/vmhgfs-fuse/Makefile.am | 4 +- open-vm-tools/vmhgfs-fuse/config.c | 24 ++++- open-vm-tools/vmhgfs-fuse/dir.c | 6 +- open-vm-tools/vmhgfs-fuse/main.c | 78 +++++++++++---- open-vm-tools/vmhgfs-fuse/module.h | 10 +- 12 files changed, 262 insertions(+), 56 deletions(-) diff --git a/open-vm-tools/AUTHORS b/open-vm-tools/AUTHORS index 262a99951..bb6d0c663 100644 --- a/open-vm-tools/AUTHORS +++ b/open-vm-tools/AUTHORS @@ -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 diff --git a/open-vm-tools/configure.ac b/open-vm-tools/configure.ac index 1a7b70000..2c4f097f9 100644 --- a/open-vm-tools/configure.ac +++ b/open-vm-tools/configure.ac @@ -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") diff --git a/open-vm-tools/tests/testVmblock/Makefile.am b/open-vm-tools/tests/testVmblock/Makefile.am index 3c44b4046..543b2f813 100644 --- a/open-vm-tools/tests/testVmblock/Makefile.am +++ b/open-vm-tools/tests/testVmblock/Makefile.am @@ -15,12 +15,14 @@ ### 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 diff --git a/open-vm-tools/vmblock-fuse/Makefile.am b/open-vm-tools/vmblock-fuse/Makefile.am index 9018096c4..81ff0acac 100644 --- a/open-vm-tools/vmblock-fuse/Makefile.am +++ b/open-vm-tools/vmblock-fuse/Makefile.am @@ -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 = diff --git a/open-vm-tools/vmblock-fuse/fsops.c b/open-vm-tools/vmblock-fuse/fsops.c index c14d78d47..cedcb7479 100644 --- a/open-vm-tools/vmblock-fuse/fsops.c +++ b/open-vm-tools/vmblock-fuse/fsops.c @@ -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; diff --git a/open-vm-tools/vmblock-fuse/fsops.h b/open-vm-tools/vmblock-fuse/fsops.h index 2f16c8bcd..a067abdf8 100644 --- a/open-vm-tools/vmblock-fuse/fsops.h +++ b/open-vm-tools/vmblock-fuse/fsops.h @@ -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 @@ -30,13 +30,19 @@ #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 #include "vmblock.h" @@ -55,9 +61,18 @@ */ 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); diff --git a/open-vm-tools/vmblock-fuse/main.c b/open-vm-tools/vmblock-fuse/main.c index bc07670a3..c9952473f 100644 --- a/open-vm-tools/vmblock-fuse/main.c +++ b/open-vm-tools/vmblock-fuse/main.c @@ -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 } diff --git a/open-vm-tools/vmhgfs-fuse/Makefile.am b/open-vm-tools/vmhgfs-fuse/Makefile.am index 19089a08e..731431b74 100644 --- a/open-vm-tools/vmhgfs-fuse/Makefile.am +++ b/open-vm-tools/vmhgfs-fuse/Makefile.am @@ -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@ diff --git a/open-vm-tools/vmhgfs-fuse/config.c b/open-vm-tools/vmhgfs-fuse/config.c index c6125e9db..fe0cda9da 100644 --- a/open-vm-tools/vmhgfs-fuse/config.c +++ b/open-vm-tools/vmhgfs-fuse/config.c @@ -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 #include #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; diff --git a/open-vm-tools/vmhgfs-fuse/dir.c b/open-vm-tools/vmhgfs-fuse/dir.c index d5fd1f8b5..b5dcc2945 100644 --- a/open-vm-tools/vmhgfs-fuse/dir.c +++ b/open-vm-tools/vmhgfs-fuse/dir.c @@ -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) { /* diff --git a/open-vm-tools/vmhgfs-fuse/main.c b/open-vm-tools/vmhgfs-fuse/main.c index 1ce970b8b..e6d7812bb 100644 --- a/open-vm-tools/vmhgfs-fuse/main.c +++ b/open-vm-tools/vmhgfs-fuse/main.c @@ -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 @@ -22,10 +22,6 @@ * 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 @@ hgfs_readlink(const char *path, //IN: path to a file *---------------------------------------------------------------------- */ +#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 @@ hgfs_symlink(const char *symname, //IN: symname target *---------------------------------------------------------------------- */ +#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 @@ hgfs_link(const char *from, //IN: From path *---------------------------------------------------------------------- */ +#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 @@ hgfs_chmod(const char *path, //IN: path to a file *---------------------------------------------------------------------- */ +#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 @@ hgfs_chown(const char *path, //IN: Path to a file *---------------------------------------------------------------------- */ +#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 @@ hgfs_truncate(const char *path, //IN: path to a file *---------------------------------------------------------------------- */ -#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 @@ hgfs_release(const char *path, //IN: path to a file *---------------------------------------------------------------------- */ +#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, diff --git a/open-vm-tools/vmhgfs-fuse/module.h b/open-vm-tools/vmhgfs-fuse/module.h index 7d0f1b01d..61f88e100 100644 --- a/open-vm-tools/vmhgfs-fuse/module.h +++ b/open-vm-tools/vmhgfs-fuse/module.h @@ -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 @@ -25,7 +25,13 @@ #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 #include "hgfsUtil.h"