OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [os/] [stat_plan9.go] - Blame information for rev 867

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// 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.
4
 
5
package os
6
 
7
import (
8
        "syscall"
9
        "time"
10
)
11
 
12
func sameFile(sys1, sys2 interface{}) bool {
13
        a := sys1.(*Dir)
14
        b := sys2.(*Dir)
15
        return a.Qid.Path == b.Qid.Path && a.Type == b.Type && a.Dev == b.Dev
16
}
17
 
18
func fileInfoFromStat(d *Dir) FileInfo {
19
        fs := &fileStat{
20
                name:    d.Name,
21
                size:    int64(d.Length),
22
                modTime: time.Unix(int64(d.Mtime), 0),
23
                sys:     d,
24
        }
25
        fs.mode = FileMode(d.Mode & 0777)
26
        if d.Mode&syscall.DMDIR != 0 {
27
                fs.mode |= ModeDir
28
        }
29
        if d.Mode&syscall.DMAPPEND != 0 {
30
                fs.mode |= ModeAppend
31
        }
32
        if d.Mode&syscall.DMEXCL != 0 {
33
                fs.mode |= ModeExclusive
34
        }
35
        if d.Mode&syscall.DMTMP != 0 {
36
                fs.mode |= ModeTemporary
37
        }
38
        return fs
39
}
40
 
41
// arg is an open *File or a path string.
42
func dirstat(arg interface{}) (d *Dir, err error) {
43
        var name string
44
 
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
48
 
49
        for i := 0; i < 2; i++ {
50
                buf := make([]byte, size)
51
 
52
                var n int
53
                switch a := arg.(type) {
54
                case *File:
55
                        name = a.name
56
                        n, err = syscall.Fstat(a.fd, buf)
57
                case string:
58
                        name = a
59
                        n, err = syscall.Stat(name, buf)
60
                }
61
                if err != nil {
62
                        return nil, &PathError{"stat", name, err}
63
                }
64
                if n < syscall.STATFIXLEN {
65
                        return nil, &PathError{"stat", name, Eshortstat}
66
                }
67
 
68
                // Pull the real size out of the stat message.
69
                s, _ := gbit16(buf)
70
                size = int(s)
71
 
72
                // If the stat message is larger than our buffer we will
73
                // 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
                }
81
        }
82
        return nil, &PathError{"stat", name, Ebadstat}
83
}
84
 
85
// Stat returns a FileInfo structure describing the named file and an error, if any.
86
func Stat(name string) (FileInfo, error) {
87
        d, err := dirstat(name)
88
        if err != nil {
89
                return nil, err
90
        }
91
        return fileInfoFromStat(d), nil
92
}
93
 
94
// Lstat returns the FileInfo structure describing the named file and an
95
// error, if any.  If the file is a symbolic link (though Plan 9 does not have symbolic links),
96
// the returned FileInfo describes the symbolic link.  Lstat makes no attempt to follow the link.
97
func Lstat(name string) (FileInfo, error) {
98
        return Stat(name)
99
}
100
 
101
// For testing.
102
func atime(fi FileInfo) time.Time {
103
        return time.Unix(int64(fi.Sys().(*Dir).Atime), 0)
104
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.