aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Vasilevsky <dave@vasilevsky.ca>2025-11-25 03:55:45 +0000
committerMichael Knyszek <mknyszek@google.com>2025-12-19 09:55:33 -0800
commit058ca7412ad28c5407a272dbb3b594401a46aba9 (patch)
treee51a5cd9f33649c455c3d9e9042f8b977036e2ae
parentf79c33763ee61b034fa3eda7e3a7a32cd6d9c0b7 (diff)
downloadgo-058ca7412ad28c5407a272dbb3b594401a46aba9.tar.xz
[release-branch.go1.24] os: allow direntries to have zero inodes on Linux
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 #76624 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> Reviewed-on: https://go-review.googlesource.com/c/go/+/725341
-rw-r--r--src/os/dir_unix.go3
-rw-r--r--src/syscall/dirent.go4
2 files changed, 4 insertions, 3 deletions
diff --git a/src/os/dir_unix.go b/src/os/dir_unix.go
index eadc1660c2..17c5799126 100644
--- a/src/os/dir_unix.go
+++ b/src/os/dir_unix.go
@@ -104,7 +104,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))
diff --git a/src/syscall/dirent.go b/src/syscall/dirent.go
index f6e78d9bb5..1c2cf92fc1 100644
--- a/src/syscall/dirent.go
+++ b/src/syscall/dirent.go
@@ -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))