82a460
diff --git a/configure.ac b/configure.ac
82a460
index daeee728..689667e5 100644
82a460
--- a/configure.ac
82a460
+++ b/configure.ac
82a460
@@ -551,6 +551,11 @@ if test "x$enable_samba" != "xno"; then
82a460
         AC_DEFINE(HAVE_SMBC_SETOPTIONPROTOCOLS, 1, [Define to 1 if smbc_setOptionProtocols() is available]),
82a460
         []
82a460
     )
82a460
+
82a460
+    AC_CHECK_LIB(smbclient, smbc_readdirplus2,
82a460
+        AC_DEFINE(HAVE_SMBC_READDIRPLUS2, 1, [Define to 1 if smbc_readdirplus2() is available]),
82a460
+        []
82a460
+    )
82a460
   fi
82a460
 fi
82a460
 
82a460
diff --git a/daemon/gvfsbackendsmb.c b/daemon/gvfsbackendsmb.c
82a460
index 9571fa0d..ce151648 100644
82a460
--- a/daemon/gvfsbackendsmb.c
82a460
+++ b/daemon/gvfsbackendsmb.c
82a460
@@ -1738,25 +1738,34 @@ do_enumerate (GVfsBackend *backend,
82a460
 	      GFileQueryInfoFlags flags)
82a460
 {
82a460
   GVfsBackendSmb *op_backend = G_VFS_BACKEND_SMB (backend);
82a460
-  struct stat st;
82a460
-  int res;
82a460
+  struct stat st = { 0 };
82a460
   GError *error;
82a460
   SMBCFILE *dir;
82a460
-  char dirents[1024*4];
82a460
-  struct smbc_dirent *dirp;
82a460
   GFileInfo *info;
82a460
   GString *uri;
82a460
-  int uri_start_len;
82a460
   smbc_opendir_fn smbc_opendir;
82a460
+  smbc_closedir_fn smbc_closedir;
82a460
+#ifndef HAVE_SMBC_READDIRPLUS2
82a460
+  int res;
82a460
+  char dirents[1024*4];
82a460
+  struct smbc_dirent *dirp;
82a460
+  int uri_start_len;
82a460
   smbc_getdents_fn smbc_getdents;
82a460
   smbc_stat_fn smbc_stat;
82a460
-  smbc_closedir_fn smbc_closedir;
82a460
+#else
82a460
+  smbc_readdirplus2_fn smbc_readdirplus2;
82a460
+  const struct libsmb_file_info *exstat;
82a460
+#endif
82a460
 
82a460
   uri = create_smb_uri_string (op_backend->server, op_backend->port, op_backend->share, filename);
82a460
   
82a460
   smbc_opendir = smbc_getFunctionOpendir (op_backend->smb_context);
82a460
+#ifndef HAVE_SMBC_READDIRPLUS2
82a460
   smbc_getdents = smbc_getFunctionGetdents (op_backend->smb_context);
82a460
   smbc_stat = smbc_getFunctionStat (op_backend->smb_context);
82a460
+#else
82a460
+  smbc_readdirplus2 = smbc_getFunctionReaddirPlus2 (op_backend->smb_context);
82a460
+#endif
82a460
   smbc_closedir = smbc_getFunctionClosedir (op_backend->smb_context);
82a460
   
82a460
   dir = smbc_opendir (op_backend->smb_context, uri->str);
82a460
@@ -1776,6 +1785,8 @@ do_enumerate (GVfsBackend *backend,
82a460
 
82a460
   if (uri->str[uri->len - 1] != '/')
82a460
     g_string_append_c (uri, '/');
82a460
+
82a460
+#ifndef HAVE_SMBC_READDIRPLUS2
82a460
   uri_start_len = uri->len;
82a460
 
82a460
   while (TRUE)
82a460
@@ -1827,9 +1838,27 @@ do_enumerate (GVfsBackend *backend,
82a460
 	  dirp = (struct smbc_dirent *) (((char *)dirp) + dirlen);
82a460
 	  res -= dirlen;
82a460
 	}
82a460
+   }
82a460
+#else
82a460
+  while ((exstat = smbc_readdirplus2 (op_backend->smb_context, dir, &st)) != NULL)
82a460
+    {
82a460
+      if ((S_ISREG (st.st_mode) ||
82a460
+           S_ISDIR (st.st_mode) ||
82a460
+           S_ISLNK (st.st_mode)) &&
82a460
+          g_strcmp0 (exstat->name, ".") != 0 &&
82a460
+          g_strcmp0 (exstat->name, "..") != 0)
82a460
+        {
82a460
+          info = g_file_info_new ();
82a460
+          set_info_from_stat (op_backend, info, &st, exstat->name, matcher);
82a460
+          g_vfs_job_enumerate_add_info (job, info);
82a460
+          g_object_unref (info);
82a460
+        }
82a460
+
82a460
+      memset (&st, 0, sizeof (struct stat));
82a460
     }
82a460
-      
82a460
-  res = smbc_closedir (op_backend->smb_context, dir);
82a460
+#endif
82a460
+
82a460
+  smbc_closedir (op_backend->smb_context, dir);
82a460
 
82a460
   g_vfs_job_enumerate_done (job);
82a460
 
82a460
diff --git a/meson.build b/meson.build
82a460
index 6ae768d9..d3f59457 100644
82a460
--- a/meson.build
82a460
+++ b/meson.build
82a460
@@ -418,6 +418,7 @@ if enable_samba
82a460
   smbclient_dep = dependency('smbclient')
82a460
 
82a460
   config_h.set('HAVE_SMBC_SETOPTIONPROTOCOLS', cc.has_function('smbc_setOptionProtocols', dependencies: smbclient_dep))
82a460
+  config_h.set('HAVE_SMBC_READDIRPLUS2', cc.has_function('smbc_readdirplus2', dependencies: smbclient_dep))
82a460
 endif
82a460
 
82a460
 # *** Check for libarchive ***
82a460
-- 
82a460
2.26.2
82a460