Stat_t在Plan9中是如何定义的?

huangapple go评论86阅读模式
英文:

Where is Stat_t defined for plan9?

问题

syscallplan9特定的Go代码中,没有像其他GOOS那样的Stat_tStat_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.

huangapple
  • 本文由 发表于 2016年2月22日 11:07:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/35545178.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定