本文整理匯總了Golang中github.com/lunixbochs/usercorn/go/kernel/common.Obuf.Struc方法的典型用法代碼示例。如果您正苦於以下問題:Golang Obuf.Struc方法的具體用法?Golang Obuf.Struc怎麽用?Golang Obuf.Struc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/lunixbochs/usercorn/go/kernel/common.Obuf
的用法示例。
在下文中一共展示了Obuf.Struc方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getdents
func (k *LinuxKernel) getdents(dirfd co.Fd, buf co.Obuf, count uint64, bits uint) uint64 {
dir, ok := k.Files[dirfd]
if !ok {
return UINT64_MAX // FIXME
}
dents := dir.Dirents
if dents == nil {
dent, err := os.Lstat(path.Join(dir.Path, ".."))
if err == nil {
dents = append(dents, fileInfoProxy{dent, ".."})
}
dent, err = os.Lstat(dir.Path)
if err == nil {
dents = append(dents, fileInfoProxy{dent, "."})
}
contents, err := ioutil.ReadDir(dir.Path)
if err != nil {
return UINT64_MAX // FIXME
}
dents = append(dents, contents...)
dir.Dirents = dents
}
if dir.Offset >= uint64(len(dents)) {
return 0
}
dents = dents[dir.Offset:]
written := 0
offset := dir.Offset
out := buf.Struc()
for i, f := range dents {
// TODO: syscall.Stat_t portability?
inode := f.Sys().(*syscall.Stat_t).Ino
// figure out file mode
mode := f.Mode()
fileType := DT_REG
if f.IsDir() {
fileType = DT_DIR
} else if mode&os.ModeNamedPipe > 0 {
fileType = DT_FIFO
} else if mode&os.ModeSymlink > 0 {
fileType = DT_LNK
} else if mode&os.ModeDevice > 0 {
if mode&os.ModeCharDevice > 0 {
fileType = DT_CHR
} else {
fileType = DT_BLK
}
} else if mode&os.ModeSocket > 0 {
fileType = DT_SOCK
}
// TODO: does inode get truncated? guess it depends on guest LFS support
var ent interface{}
if bits == 64 {
ent = &Dirent64{inode, dir.Offset + uint64(i), 0, fileType, f.Name() + "\x00"}
} else {
ent = &Dirent{inode, dir.Offset + uint64(i), 0, f.Name() + "\x00", fileType}
}
size, _ := struc.Sizeof(ent)
if uint64(written+size) > count {
break
}
offset++
if bits == 64 {
ent.(*Dirent64).Len = size
} else {
ent.(*Dirent).Len = size
}
written += size
if err := out.Pack(ent); err != nil {
return UINT64_MAX // FIXME
}
}
dir.Offset = offset
return uint64(written)
}