Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(345)

Side by Side Diff: src/pkg/os/stat_plan9.go

Issue 4149046: code review 4149046: os: Plan 9 support. (Closed)
Patch Set: diff -r fad73d342108 https://go.googlecode.com/hg/ Created 13 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 package os
6
7 import "syscall"
8
9 func fileInfoFromStat(fi *FileInfo, d *Dir) *FileInfo {
10 fi.Dev = uint64(d.Qid.Vers) | uint64(d.Qid.Type<<32)
11 fi.Ino = d.Qid.Path
12
13 fi.Mode = uint32(d.Mode) & 0777
14 if (d.Mode & syscall.DMDIR) == syscall.DMDIR {
15 fi.Mode |= syscall.S_IFDIR
16 } else {
17 fi.Mode |= syscall.S_IFREG
18 }
19
20 fi.Size = int64(d.Length)
21 fi.Atime_ns = 1e9 * int64(d.Atime)
22 fi.Mtime_ns = 1e9 * int64(d.Mtime)
23 fi.Name = d.Name
24 fi.FollowedSymlink = false
25 return fi
26 }
27
28 // arg is an open *File or a path string.·
29 func dirstat(arg interface{}) (fi *FileInfo, err Error) {
30 var name string
31 nd := syscall.STATFIXLEN + 16*4
32
33 for i := 0; i < 2; i++ { /* should work by the second try */
34 buf := make([]byte, nd)
35
36 var n int
37 var e syscall.Error
38
39 switch syscall_arg := arg.(type) {
40 case *File:
41 name = syscall_arg.name
42 n, e = syscall.Fstat(syscall_arg.fd, buf)
43 case string:
44 name = syscall_arg
45 n, e = syscall.Stat(name, buf)
46 }
47
48 if e != nil {
49 return nil, &PathError{"stat", name, e}
50 }
51
52 if n < syscall.STATFIXLEN {
53 return nil, &PathError{"stat", name, Eshortstat}
54 }
55
56 ntmp, _ := gbit16(buf)
57 nd = int(ntmp)
58
59 if nd <= n {
60 d, e := UnmarshalDir(buf[:n])
61
62 if e != nil {
63 return nil, &PathError{"stat", name, e}
64 }
65
66 return fileInfoFromStat(new(FileInfo), d), nil
67 }
68 }
69
70 return nil, &PathError{"stat", name, Ebadstat}
71 }
72
73
74 // Stat returns a FileInfo structure describing the named file and an error, if any.
75 func Stat(name string) (fi *FileInfo, err Error) {
76 return dirstat(name)
77 }
78
79 func Lstat(name string) (fi *FileInfo, err Error) {
r 2011/03/31 22:57:46 copy the comment for Lstat from file.go
paulzhol 2011/04/01 20:16:44 Done.
80 return dirstat(name)
81 }
OLDNEW
« src/pkg/os/dir_plan9.go ('K') | « src/pkg/os/proc.go ('k') | src/pkg/os/sys_plan9.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b