来自os.Stat / Lstat的目录大小

Let's say I do an os.Stat() on a directory:

func main() {
    fi, _ := os.Stat("/tmp")
    println(fi.Size())
}

// 548
// Program exited.

https://play.golang.org/p/NIzGMHRYfi

What exactly is the [FileInfo].Size() value meant to represent? It's not the file size, so I'm guessing something like number of files? Inodes? I couldn't find a clear answer anywhere, so maybe someone can enlighten me?

FileInfo mentions

// length in bytes for regular files; system-dependent for others

So it really depends on the execution environment.
See for instance "Where does ext4 store directory sizes?"

In that example, a directory stat size returns 4096 bytes.
That's the actual size of the directory itself, not what it contains.

The stat command provides no facility for querying anything other then the size of a filesystem object (directory or file).

stat simply doesn't have a way to return multiple sizes—so it can only return the size of the directory itself, not of its contents.
And also "directory size including contents" becomes less clear when you have hardlinked files.