diff --git a/lib/fts.c b/lib/fts.c
index ceb8935..5e4b55f 100644
--- a/lib/fts.c
+++ b/lib/fts.c
@@ -924,6 +924,13 @@ fts_children (register FTS *sp, int instr)
  * The former skips all stat calls.  The latter skips stat calls in any leaf
  * directories and for any files after the subdirectories in the directory have
  * been found, cutting the stat calls by about 2/3.
+ *
+ * There exist file systems on some Unix systems in fact don't provide this
+ * link count property, for example HSFS on some versions of Solaris.  If a
+ * directory link count is less than 2, we avoid the assumption that the
+ * link count means anything.  Some sections of the /proc filesystem on some
+ * versions of the Linux kernel provide directory link counts greater than 2
+ * but which are still inaccurate, but those cases are bugs.
  */
 static FTSENT *
 internal_function
@@ -975,23 +982,34 @@ fts_build (register FTS *sp, int type)
        if (cur->fts_info == FTS_NSOK)
 	 cur->fts_info = fts_stat(sp, cur, false);
 
-	/*
-	 * Nlinks is the number of possible entries of type directory in the
-	 * directory if we're cheating on stat calls, 0 if we're not doing
-	 * any stat calls at all, (nlink_t) -1 if we're statting everything.
-	 */
-	if (type == BNAMES) {
-		nlinks = 0;
-		/* Be quiet about nostat, GCC. */
-		nostat = false;
-	} else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) {
-		nlinks = (cur->fts_statp->st_nlink
-			  - (ISSET(FTS_SEEDOT) ? 0 : 2));
-		nostat = true;
-	} else {
-		nlinks = -1;
-		nostat = false;
-	}
+        /*
+         * Nlinks is the number of possible entries of type directory in the
+         * directory if we're cheating on stat calls, 0 if we're not doing
+         * any stat calls at all, (nlink_t) -1 if we're statting everything.
+         */
+        if (type == BNAMES) {
+                nlinks = 0;
+                /* Be quiet about nostat, GCC. */
+                nostat = false;
+        } else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) {
+                nlinks = cur->fts_statp->st_nlink;
+                if (nlinks < 2) {
+                        /* Looks like this directory is on a file system
+                         * which does not offer traditional Unix semantics.
+                         * We cannot assume that the directory's link count
+                         * tells us anything about the number of
+                         * subdirectories it contains.
+                         */
+                        nostat = false;
+                        nlinks = -1;
+                } else {
+                        nlinks -= (ISSET(FTS_SEEDOT) ? 0 : 2);
+                        nostat = true;
+                }
+        } else {
+                nlinks = -1;
+                nostat = false;
+        }
 
 	/*
 	 * If we're going to need to stat anything or we want to descend
