英文:
Where is Stat_t defined for plan9?
问题
在syscall
的plan9
特定的Go代码中,没有像其他GOOS
那样的Stat_t
。Stat_t
或其等效物在哪里定义?
英文:
In the plan9
specific Go code for syscall
, there is no Stat_t
like with other GOOS
. Where is Stat_t
, or its equivalent defined?
答案1
得分: 5
TL;DR: 这是*syscall.Dir
类型。详细信息请继续阅读。
在Plan9上,os.Stat
的源代码在这里。它调用了dirstat
,该函数的定义在这里。它将dirstat
的返回值传递给fileInfoFromStat
,该函数在同一文件中定义,位置在这里。
对于路径(而不是*File
对象),dirstat
只是调用了syscall.Stat
,它基本上只是stat
的一个薄包装。syscall.Stat
需要一个字节缓冲区来写入。这个缓冲区稍微经过处理(详见dirstat
的详细信息),然后传递给syscall.UnmarshalDir
,这就是魔法发生的地方。文档说明它从缓冲区解码一个单独的9P stat消息,并返回一个*syscall.Dir
。
然后,dirstat
将这个*syscall.Dir
传递给fileInfoFromStat
,它将其处理成一个FileInfo
。通过FileInfo
对象的Sys()
方法获取的就是这个*syscall.Dir
值。
英文:
TL;DR: It's the *syscall.Dir
type. Read on for details.
The source for os.Stat
on Plan9 is here. It calls dirstat
, which is defined here. It feeds the return value of dirstat
into fileInfoFromStat
, which is defined in the same file here.
In the case of paths (as opposed to *File
objects), dirstat
just calls syscall.Stat
, which is basically just a thin wrapper around stat
. syscall.Stat
expects a byte buffer to be able to write into. This buffer is processed a bit (see dirstat
for details), and then fed into syscall.UnmarshalDir
, which is where the magic happens. The documentation states that it "decodes a single 9P stat message" from a buffer and returns a *syscall.Dir
.
dirstat
then passes this *syscall.Dir
to fileInfoFromStat
, which is what processes it into a FileInfo
. It's this *syscall.Dir
value that is obtained through the Sys()
method on the FileInfo
object.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论