Skip to content

os: on Unix, Readdirnames skips directory entries with zero inodes #76428

@vasi

Description

@vasi

Go version

go version go1.25.4 X:nodwarf5 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/vasi/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/vasi/.config/go/env'
GOEXE=''
GOEXPERIMENT='nodwarf5'
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1615998593=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/vasi/src/restic/go.mod'
GOMODCACHE='/home/vasi/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/vasi/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/vasi/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.25.4 X:nodwarf5'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

  1. Mount a filesystem that returns direntries with zero inodes. On a Linux system with libfuse 3.17.1 or later, you can do this easily with GVFS:
    # Create many dir entries
    (cd big && printf '%04x ' {0..1023} | xargs mkdir -p)
    gio mount sftp://localhost/$PWD/big
    # Verify that some entries have zero inodes:
    python -c 'import os; import sys; print([d.inode() for d in os.scandir(sys.argv[1])])' /run/user/$UID/gvfs/sftp:host=localhost/$PWD/big
    
  2. List the directory with a tool that uses glibc 2.37 or later. Eg: ls -a /run/user/$UID/gvfs/sftp:host=localhost/$PWD/big | wc -l. It returns all 1026 entries (including . and ..).
  3. List the directory with Go:
    package main
    
    import (
    	"fmt"
    	"os"
    )
    
    func main() {
    				dir := os.Args[1]
    	f, err := os.Open(dir)
    	if err != nil {
    		panic(err)
    	}
    	defer f.Close()
    
    	names, err := f.Readdirnames(-1)
    	if err != nil {
    		panic(err)
    	}
    	fmt.Printf("Readdirnames: %d items\n", len(names))
    }
    
    Run: go run ./main.go /run/user/$UID/gvfs/sftp:host=localhost/$PWD/big

What did you see happen?

Go prints: Readdirnames: 49 items, ignoring the majority of the directory entries.

What did you expect to see?

Go sees all 1024 directory entries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions