12
func sameFile(sys1, sys2 interface{}) bool {
12
func sameFile(fs1, fs2 *fileStat) bool {
13
a := fs1.sys.(*syscall.Dir)
14
b := fs2.sys.(*syscall.Dir)
15
15
return a.Qid.Path == b.Qid.Path && a.Type == b.Type && a.Dev == b.Dev
18
func fileInfoFromStat(d *Dir) FileInfo {
18
func fileInfoFromStat(d *syscall.Dir) FileInfo {
21
21
size: int64(d.Length),
41
// arg is an open *File or a path string.
42
func dirstat(arg interface{}) (d *Dir, err error) {
41
// arg is an open *File or a path string.
42
func dirstat(arg interface{}) (*syscall.Dir, error) {
45
45
// This is big enough for most stat messages
50
50
buf := make([]byte, size)
53
54
switch a := arg.(type) {
56
57
n, err = syscall.Fstat(a.fd, buf)
59
n, err = syscall.Stat(name, buf)
60
n, err = syscall.Stat(a, buf)
62
panic("phase error in dirstat")
62
65
return nil, &PathError{"stat", name, err}
64
67
if n < syscall.STATFIXLEN {
65
return nil, &PathError{"stat", name, errShortStat}
68
return nil, &PathError{"stat", name, syscall.ErrShortStat}
68
71
// Pull the real size out of the stat message.
72
size = int(uint16(buf[0]) | uint16(buf[1])<<8)
72
74
// If the stat message is larger than our buffer we will
73
75
// go around the loop and allocate one that is big enough.
75
d, err = UnmarshalDir(buf[:n])
77
return nil, &PathError{"stat", name, err}
80
d, err := syscall.UnmarshalDir(buf[:n])
82
return nil, &PathError{"stat", name, err}
82
return nil, &PathError{"stat", name, errBadStat}
86
return nil, &PathError{"stat", name, syscall.ErrBadStat}
85
// Stat returns a FileInfo structure describing the named file.
89
// Stat returns a FileInfo describing the named file.
86
90
// If there is an error, it will be of type *PathError.
87
func Stat(name string) (FileInfo, error) {
91
func Stat(name string) (fi FileInfo, err error) {
88
92
d, err := dirstat(name)
92
96
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.
99
// Lstat returns a FileInfo describing the named file.
100
// If the file is a symbolic link, the returned FileInfo
101
// describes the symbolic link. Lstat makes no attempt to follow the link.
98
102
// If there is an error, it will be of type *PathError.
99
func Lstat(name string) (FileInfo, error) {
103
func Lstat(name string) (fi FileInfo, err error) {
100
104
return Stat(name)
104
108
func atime(fi FileInfo) time.Time {
105
return time.Unix(int64(fi.Sys().(*Dir).Atime), 0)
109
return time.Unix(int64(fi.Sys().(*syscall.Dir).Atime), 0)