os: allow direntries to have zero inodes on Linux

While such entries have often been skipped, some Linux
filesystems return valid enties with zero inodes.
This new behavior also puts Go in agreement with recent
glibc.

Fixes #76428
This commit is contained in:
Dave Vasilevsky 2025-11-24 22:04:34 -05:00
parent 0921e1db83
commit 8f83d009ef
2 changed files with 4 additions and 3 deletions

View 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 // 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 // of inodes. Therefore, we cannot make the assumption that it is safe
// to skip entries with zero inodes. // 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 continue
} }
const namoff = uint64(unsafe.Offsetof(syscall.Dirent{}.Name)) const namoff = uint64(unsafe.Offsetof(syscall.Dirent{}.Name))

View file

@ -73,8 +73,8 @@ func ParseDirent(buf []byte, max int, names []string) (consumed int, count int,
break break
} }
// See src/os/dir_unix.go for the reason why this condition is // See src/os/dir_unix.go for the reason why this condition is
// excluded on wasip1. // excluded on wasip1 and linux.
if ino == 0 && runtime.GOOS != "wasip1" { // File absent in directory. if ino == 0 && runtime.GOOS != "linux" && runtime.GOOS != "wasip1" { // File absent in directory.
continue continue
} }
const namoff = uint64(unsafe.Offsetof(Dirent{}.Name)) const namoff = uint64(unsafe.Offsetof(Dirent{}.Name))