~ubuntu-branches/ubuntu/saucy/golang/saucy

« back to all changes in this revision

Viewing changes to src/pkg/os/stat_plan9.go

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2013-07-08 05:52:37 UTC
  • mfrom: (29.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130708055237-at01839e0hp8z3ni
Tags: 2:1.1-1ubuntu1
016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
        "time"
10
10
)
11
11
 
12
 
func sameFile(sys1, sys2 interface{}) bool {
13
 
        a := sys1.(*Dir)
14
 
        b := sys2.(*Dir)
 
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
16
16
}
17
17
 
18
 
func fileInfoFromStat(d *Dir) FileInfo {
 
18
func fileInfoFromStat(d *syscall.Dir) FileInfo {
19
19
        fs := &fileStat{
20
20
                name:    d.Name,
21
21
                size:    int64(d.Length),
38
38
        return fs
39
39
}
40
40
 
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) {
43
43
        var name string
44
44
 
45
45
        // This is big enough for most stat messages
50
50
                buf := make([]byte, size)
51
51
 
52
52
                var n int
 
53
                var err error
53
54
                switch a := arg.(type) {
54
55
                case *File:
55
56
                        name = a.name
56
57
                        n, err = syscall.Fstat(a.fd, buf)
57
58
                case string:
58
59
                        name = a
59
 
                        n, err = syscall.Stat(name, buf)
 
60
                        n, err = syscall.Stat(a, buf)
 
61
                default:
 
62
                        panic("phase error in dirstat")
60
63
                }
61
64
                if err != nil {
62
65
                        return nil, &PathError{"stat", name, err}
63
66
                }
64
67
                if n < syscall.STATFIXLEN {
65
 
                        return nil, &PathError{"stat", name, errShortStat}
 
68
                        return nil, &PathError{"stat", name, syscall.ErrShortStat}
66
69
                }
67
70
 
68
71
                // Pull the real size out of the stat message.
69
 
                s, _ := gbit16(buf)
70
 
                size = int(s)
 
72
                size = int(uint16(buf[0]) | uint16(buf[1])<<8)
71
73
 
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.
74
 
                if size <= n {
75
 
                        d, err = UnmarshalDir(buf[:n])
76
 
                        if err != nil {
77
 
                                return nil, &PathError{"stat", name, err}
78
 
                        }
79
 
                        return
80
 
                }
 
76
                if size > n {
 
77
                        continue
 
78
                }
 
79
 
 
80
                d, err := syscall.UnmarshalDir(buf[:n])
 
81
                if err != nil {
 
82
                        return nil, &PathError{"stat", name, err}
 
83
                }
 
84
                return d, nil
81
85
        }
82
 
        return nil, &PathError{"stat", name, errBadStat}
 
86
        return nil, &PathError{"stat", name, syscall.ErrBadStat}
83
87
}
84
88
 
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)
89
93
        if err != nil {
90
94
                return nil, err
92
96
        return fileInfoFromStat(d), nil
93
97
}
94
98
 
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)
101
105
}
102
106
 
103
107
// For testing.
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)
106
110
}