1 // Copyright 2011 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.
14 func fileInfoFromStat(d *syscall.Dir) FileInfo {
18 modTime: time.Unix(int64(d.Mtime), 0),
21 fs.mode = FileMode(d.Mode & 0777)
22 if d.Mode&syscall.DMDIR != 0 {
25 if d.Mode&syscall.DMAPPEND != 0 {
28 if d.Mode&syscall.DMEXCL != 0 {
29 fs.mode |= ModeExclusive
31 if d.Mode&syscall.DMTMP != 0 {
32 fs.mode |= ModeTemporary
34 // Consider all files not served by #M as device files.
38 // Consider all files served by #c as character device files.
40 fs.mode |= ModeCharDevice
45 // arg is an open *File or a path string.
46 func dirstat(arg interface{}) (*syscall.Dir, error) {
50 size := syscall.STATFIXLEN + 16*4
52 for i := 0; i < 2; i++ {
53 buf := make([]byte, bitSize16+size)
56 switch a := arg.(type) {
59 n, err = syscall.Fstat(a.fd, buf)
62 n, err = syscall.Stat(a, buf)
64 panic("phase error in dirstat")
68 return nil, &PathError{"stat", name, err}
71 // Pull the real size out of the stat message.
72 size = int(uint16(buf[0]) | uint16(buf[1])<<8)
74 // If the stat message is larger than our buffer we will
75 // go around the loop and allocate one that is big enough.
77 d, err := syscall.UnmarshalDir(buf[:n])
79 return nil, &PathError{"stat", name, err}
87 err = syscall.ErrBadStat
90 return nil, &PathError{"stat", name, err}
93 // statNolog implements Stat for Plan 9.
94 func statNolog(name string) (FileInfo, error) {
95 d, err := dirstat(name)
99 return fileInfoFromStat(d), nil
102 // lstatNolog implements Lstat for Plan 9.
103 func lstatNolog(name string) (FileInfo, error) {
104 return statNolog(name)
108 func atime(fi FileInfo) time.Time {
109 return time.Unix(int64(fi.Sys().(*syscall.Dir).Atime), 0)