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.
12 func sameFile(sys1, sys2 interface{}) bool {
15 return a.Qid.Path == b.Qid.Path && a.Type == b.Type && a.Dev == b.Dev
18 func fileInfoFromStat(d *Dir) FileInfo {
21 size: int64(d.Length),
22 modTime: time.Unix(int64(d.Mtime), 0),
25 fs.mode = FileMode(d.Mode & 0777)
26 if d.Mode&syscall.DMDIR != 0 {
29 if d.Mode&syscall.DMAPPEND != 0 {
32 if d.Mode&syscall.DMEXCL != 0 {
33 fs.mode |= ModeExclusive
35 if d.Mode&syscall.DMTMP != 0 {
36 fs.mode |= ModeTemporary
41 // arg is an open *File or a path string.
42 func dirstat(arg interface{}) (d *Dir, err error) {
45 // This is big enough for most stat messages
46 // and rounded to a multiple of 128 bytes.
47 size := (syscall.STATFIXLEN + 16*4 + 128) &^ 128
49 for i := 0; i < 2; i++ {
50 buf := make([]byte, size)
53 switch a := arg.(type) {
56 n, err = syscall.Fstat(a.fd, buf)
59 n, err = syscall.Stat(name, buf)
62 return nil, &PathError{"stat", name, err}
64 if n < syscall.STATFIXLEN {
65 return nil, &PathError{"stat", name, errShortStat}
68 // Pull the real size out of the stat message.
72 // If the stat message is larger than our buffer we will
73 // go around the loop and allocate one that is big enough.
75 d, err = UnmarshalDir(buf[:n])
77 return nil, &PathError{"stat", name, err}
82 return nil, &PathError{"stat", name, errBadStat}
85 // Stat returns a FileInfo structure describing the named file.
86 // If there is an error, it will be of type *PathError.
87 func Stat(name string) (FileInfo, error) {
88 d, err := dirstat(name)
92 return fileInfoFromStat(d), nil
95 // Lstat returns the FileInfo structure describing the named file.
96 // If the file is a symbolic link (though Plan 9 does not have symbolic links),
97 // the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link.
98 // If there is an error, it will be of type *PathError.
99 func Lstat(name string) (FileInfo, error) {
104 func atime(fi FileInfo) time.Time {
105 return time.Unix(int64(fi.Sys().(*Dir).Atime), 0)