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