Subject: Re: Build error on NetBSD

From: John Goerzen <[email-masked]>
Date: Wed, 04 Aug 2021 11:02:27 -0500

On Wed, Aug 04 2021, Sergey Matveev wrote:

>     package main
>     import "syscall"
>     func main() {
>         var s syscall.Statfs_t
>         if err := syscall.Statfs("/", &s); err != nil { 
>         panic(err) }
>         println(int64(s.Bavail) * int64(s.Bsize))
>     }

That fails to compile, in a very similar manner to the NNCP code:

jgoerzen@sverige:~/t$ go build foo.go
# command-line-arguments
./foo.go:5:26: undefined: syscall.Statfs
./foo.go:6:32: s.Bavail undefined (type syscall.Statfs_t has no 
field or method Bavail)
./foo.go:6:50: s.Bsize undefined (type syscall.Statfs_t has no 
field or method Bsize)

NetBSD does have a C statvfs() call, and does not have statfs(). 
According to the Linux statfs(2) manpage, POSIX calls for 
statvfs() and doesn't mention statfs().  I don't know if Go is 
really using statvfs() on some platforms, but from what I could 
see at 
https://cs.opensource.google/go/x/sys/+/master:unix/zsyscall_netbsd_amd64.go 
, there is simply no implementation for statfs on NetBSD in Go. 
Compare to, say, 
https://cs.opensource.google/go/x/sys/+/master:unix/zsyscall_linux_amd64.go 
.  Weird that it seems to not even be using libc here and going 
with a direct syscall interface (!)

I got it to compile and work by just replacing that entire 
function with "return true".  I mean, that's not ideal, but I 
don't see what else you'll be able to do on NetBSD.  It will still 
work, I think, though abort less early if a disk is getting full.

John