Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syscall: TestDirentRepeat broken on FreeBSD 11.2 #31403

Closed
bradfitz opened this issue Apr 11, 2019 · 3 comments
Closed

syscall: TestDirentRepeat broken on FreeBSD 11.2 #31403

bradfitz opened this issue Apr 11, 2019 · 3 comments
Assignees
Milestone

Comments

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Apr 11, 2019

https://go-review.googlesource.com/c/go/+/171477 broke:

https://build.golang.org/log/659cce8aef83ace25901509984f0d41e0bf1833b

--- FAIL: TestDirentRepeat (0.00s)
    dirent_bsd_test.go:131: bad file list: want
        ["file0" "file1" "file10" "file11" "file12" "file13" "file14" "file15" "file16" "file17" "file18" "file19" "file2" "file20" "file21" "file22" "file23" "file24" "file25" "file26" "file27" "file28" "file29" "file3" "file30" "file31" "file32" "file33" "file34" "file35" "file36" "file37" "file38" "file39" "file4" "file40" "file41" "file42" "file43" "file44" "file45" "file46" "file47" "file48" "file49" "file5" "file50" "file51" "file52" "file53" "file54" "file55" "file56" "file57" "file58" "file59" "file6" "file60" "file61" "file62" "file63" "file64" "file65" "file66" "file67" "file68" "file69" "file7" "file70" "file71" "file72" "file73" "file74" "file75" "file76" "file77" "file78" "file79" "file8" "file80" "file81" "file82" "file83" "file84" "file85" "file86" "file87" "file88" "file89" "file9" "file90" "file91" "file92" "file93" "file94" "file95" "file96" "file97" "file98" "file99"]
        got
        ["file0" "file1" "file10" "file11" "file12" "file13" "file14" "file15" "file2" "file3" "file4" "file5" "file6" "file62" "file63" "file64" "file65" "file66" "file67" "file68" "file69" "file7" "file70" "file71" "file72" "file73" "file74" "file75" "file76" "file77" "file78" "file79" "file8" "file9"]
FAIL
FAIL	syscall	0.058s
@bradfitz bradfitz added the NeedsFix label Apr 11, 2019
@bradfitz bradfitz added this to the Go1.13 milestone Apr 11, 2019
@eliasnaur
Copy link
Contributor

@eliasnaur eliasnaur commented Apr 11, 2019

I believe both netbsd also broke by the same change, in a different way:

https://build.golang.org/log/08ee3b794c5871f4778b426526f5072f3083bed7

@paulzhol
Copy link
Member

@paulzhol paulzhol commented Apr 11, 2019

// Note: the buf is small enough that this loop will need to
// execute multiple times. See issue #31368.
buf := make([]byte, N*unsafe.Offsetof(syscall.Dirent{}.Name)/4)
n, err := syscall.ReadDirent(fd, buf)

On FreeBSD 11.x syscall.Dirent is not the type stored/read. It is converted from syscall.dirent_freebsd11 , also the minimum buffer size to read dirents into is 1024 bytes (DIRBLKSIZ).

type Dirent struct {
Fileno uint64
Off int64
Reclen uint16
Type uint8
Pad0 uint8
Namlen uint16
Pad1 uint16
Name [256]int8
}
type dirent_freebsd11 struct {
Fileno uint32
Reclen uint16
Type uint8
Namlen uint8
Name [256]int8
}

The convertion is done in Getdirentries:

func Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) {
if supportsABI(_ino64First) {
return getdirentries_freebsd12(fd, buf, basep)
}
// The old syscall entries are smaller than the new. Use 1/4 of the original
// buffer size rounded up to DIRBLKSIZ (see /usr/src/lib/libc/sys/getdirentries.c).
oldBufLen := roundup(len(buf)/4, _dirblksiz)
oldBuf := make([]byte, oldBufLen)
n, err = getdirentries(fd, oldBuf, basep)
if err == nil && n > 0 {
n = convertFromDirents11(buf, oldBuf[:n])
}
return
}

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 11, 2019

Change https://golang.org/cl/171757 mentions this issue: syscall: enforce minimum buffer size to call ReadDirent

@gopherbot gopherbot closed this in 770f2a1 Apr 11, 2019
@golang golang locked and limited conversation to collaborators Apr 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.