Skip to content

os: ReadFile doesn't work on some /proc-like files #72080

Closed
@bradfitz

Description

@bradfitz

Go 1.24.0, plan9/386

Certain (many) plan9 files get generated on demand and don't have a known length ahead of time. The same situation exists with e.g. Linux /proc or /sys files.

os.ReadFile fails to read some of them.

For example, my /net/iproute on plan9 has length 0, according to ls -l:

term% ls -l /net/iproute
--rw-rw-r-- I 0 network gelnda 0 Mar. 1 16:45 /net/iproute

But I can cat it, and wc says it has 1215 bytes:

term% wc /net/iproute
     23     138    1215 /net/iproute

os.ReadFile, on the other hand, returns (511 bytes, nil) truncating it without any error.

What's happening is that os.ReadFile stats it, sees it has 0 length, assumes it's a special /proc-like file, starts with a minimum 512 byte buffer, and then issues a 512 byte read. The plan9 kernel returns with (511, nil). os.ReadFile then has 1 byte remaining between its capacity and length so it issues a one byte read to the kernel and the read returns (0, io.EOF).

Apparently that /proc-y special file doesn't like small buffers. It looks like the buffer size has to be at least large enough to fit one whole serialized route?

Perhaps os.ReadFile needs to say that at least for files that reported 0 length stat size at the beginning, we never issue a read system call with a buffer smaller than 512 bytes?

/cc @rsc @ianlancetaylor

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions