]> Cypherpunks repositories - gostls13.git/commitdiff
os: allow direntries to have zero inodes on Linux
authorDave Vasilevsky <dave@vasilevsky.ca>
Tue, 25 Nov 2025 03:55:45 +0000 (03:55 +0000)
committerGopher Robot <gobot@golang.org>
Thu, 27 Nov 2025 04:42:22 +0000 (20:42 -0800)
Some Linux filesystems have been known to return valid enties with
zero inodes. This new behavior also puts Go in agreement with recent
glibc.

Fixes #76428

Change-Id: Ieaf50739a294915a3ea2ef8c5a3bb2a91a186881
GitHub-Last-Rev: 8f83d009ef0320fd3fe7cf03e55d5d24df57f015
GitHub-Pull-Request: golang/go#76448
Reviewed-on: https://go-review.googlesource.com/c/go/+/724220
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/os/dir_unix.go
src/syscall/dirent.go

index 6a0135b70b073b2483e0af30a4e92a14ffe2ab09..87df3122d4eada8502b556ee422a4137e8292a7f 100644 (file)
@@ -112,7 +112,8 @@ func (f *File) readdir(n int, mode readdirMode) (names []string, dirents []DirEn
                // or might expose a remote file system which does not have the concept
                // of inodes. Therefore, we cannot make the assumption that it is safe
                // to skip entries with zero inodes.
-               if ino == 0 && runtime.GOOS != "wasip1" {
+               // Some Linux filesystems (old XFS, FUSE) can return valid files with zero inodes.
+               if ino == 0 && runtime.GOOS != "linux" && runtime.GOOS != "wasip1" {
                        continue
                }
                const namoff = uint64(unsafe.Offsetof(syscall.Dirent{}.Name))
index c12b1193356d21a1457ea83149c8d0ce73b6a7fd..0094641270398310dd026730a8a6bbb45f08fdc2 100644 (file)
@@ -73,8 +73,8 @@ func ParseDirent(buf []byte, max int, names []string) (consumed int, count int,
                        break
                }
                // See src/os/dir_unix.go for the reason why this condition is
-               // excluded on wasip1.
-               if ino == 0 && runtime.GOOS != "wasip1" { // File absent in directory.
+               // excluded on wasip1 and linux.
+               if ino == 0 && runtime.GOOS != "linux" && runtime.GOOS != "wasip1" { // File absent in directory.
                        continue
                }
                const namoff = uint64(unsafe.Offsetof(Dirent{}.Name))