File: stat_standard.go

package info (click to toggle)
golang-github-hugelgupf-p9 0.3.0-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 608 kB
  • sloc: makefile: 9
file content (31 lines) | stat: -rw-r--r-- 853 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//go:build linux || dragonfly || solaris
// +build linux dragonfly solaris

package internal

import (
	"os"
	"syscall"

	"golang.org/x/sys/unix"
)

// InfoToStat takes a platform native FileInfo and converts it into a 9P2000.L compatible Stat_t
func InfoToStat(fi os.FileInfo) *Stat_t {
	nativeStat := fi.Sys().(*syscall.Stat_t)
	return &Stat_t{
		Dev:     nativeStat.Dev,
		Ino:     nativeStat.Ino,
		Nlink:   nativeStat.Nlink,
		Mode:    nativeStat.Mode,
		Uid:     nativeStat.Uid,
		Gid:     nativeStat.Gid,
		Rdev:    nativeStat.Rdev,
		Size:    nativeStat.Size,
		Blksize: nativeStat.Blksize,
		Blocks:  nativeStat.Blocks,
		Atim:    unix.NsecToTimespec(syscall.TimespecToNsec(nativeStat.Atim)),
		Mtim:    unix.NsecToTimespec(syscall.TimespecToNsec(nativeStat.Mtim)),
		Ctim:    unix.NsecToTimespec(syscall.TimespecToNsec(nativeStat.Ctim)),
	}
}