1// Copyright 2009 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// +build linux openbsd solaristag
6
7package os
8
9import (
10	"syscall"
11	"time"
12)
13
14func fillFileStatFromSys(fs *fileStat, name string) {
15	fs.name = basename(name)
16	fs.size = int64(fs.sys.Size)
17	fs.modTime = timespecToTime(fs.sys.Mtim)
18	fs.mode = FileMode(fs.sys.Mode & 0777)
19	switch fs.sys.Mode & syscall.S_IFMT {
20	case syscall.S_IFBLK:
21		fs.mode |= ModeDevice
22	case syscall.S_IFCHR:
23		fs.mode |= ModeDevice | ModeCharDevice
24	case syscall.S_IFDIR:
25		fs.mode |= ModeDir
26	case syscall.S_IFIFO:
27		fs.mode |= ModeNamedPipe
28	case syscall.S_IFLNK:
29		fs.mode |= ModeSymlink
30	case syscall.S_IFREG:
31		// nothing to do
32	case syscall.S_IFSOCK:
33		fs.mode |= ModeSocket
34	}
35	if fs.sys.Mode&syscall.S_ISGID != 0 {
36		fs.mode |= ModeSetgid
37	}
38	if fs.sys.Mode&syscall.S_ISUID != 0 {
39		fs.mode |= ModeSetuid
40	}
41	if fs.sys.Mode&syscall.S_ISVTX != 0 {
42		fs.mode |= ModeSticky
43	}
44}
45
46func timespecToTime(ts syscall.Timespec) time.Time {
47	return time.Unix(int64(ts.Sec), int64(ts.Nsec))
48}
49
50// For testing.
51func atime(fi FileInfo) time.Time {
52	return timespecToTime(fi.Sys().(*syscall.Stat_t).Atim)
53}
54