Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
90626864
Commit
90626864
authored
May 02, 2012
by
Anthony Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
os: conform to Go 1 API on Plan 9
R=golang-dev, r, bradfitz, r CC=golang-dev
https://golang.org/cl/6117062
parent
38590329
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
52 deletions
+64
-52
dir_plan9.go
src/pkg/os/dir_plan9.go
+17
-17
file_plan9.go
src/pkg/os/file_plan9.go
+33
-21
path_plan9.go
src/pkg/os/path_plan9.go
+2
-2
stat_plan9.go
src/pkg/os/stat_plan9.go
+12
-12
No files found.
src/pkg/os/dir_plan9.go
View file @
90626864
...
...
@@ -48,7 +48,7 @@ func (file *File) readdir(n int) (fi []FileInfo, err error) {
if
m
<
syscall
.
STATFIXLEN
{
return
result
,
&
PathError
{
"readdir"
,
file
.
name
,
errShortStat
}
}
dir
,
e
:=
U
nmarshalDir
(
d
.
buf
[
d
.
bufp
:
d
.
bufp
+
int
(
m
)])
dir
,
e
:=
u
nmarshalDir
(
d
.
buf
[
d
.
bufp
:
d
.
bufp
+
int
(
m
)])
if
e
!=
nil
{
return
result
,
&
PathError
{
"readdir"
,
file
.
name
,
e
}
}
...
...
@@ -73,12 +73,12 @@ func (file *File) readdirnames(n int) (names []string, err error) {
return
}
type
D
ir
struct
{
type
d
ir
struct
{
// system-modified data
Type
uint16
// server type
Dev
uint32
// server subtype
// file data
Qid
Q
id
// unique id from server
Qid
q
id
// unique id from server
Mode
uint32
// permissions
Atime
uint32
// last read time
Mtime
uint32
// last write time
...
...
@@ -89,16 +89,16 @@ type Dir struct {
Muid
string
// last modifier name
}
type
Q
id
struct
{
type
q
id
struct
{
Path
uint64
// the file server's unique identification for the file
Vers
uint32
// version number for given Path
Type
uint8
// the type of the file (syscall.QTDIR for example)
}
var
nullDir
=
D
ir
{
var
nullDir
=
d
ir
{
^
uint16
(
0
),
^
uint32
(
0
),
Q
id
{
^
uint64
(
0
),
^
uint32
(
0
),
^
uint8
(
0
)},
q
id
{
^
uint64
(
0
),
^
uint32
(
0
),
^
uint8
(
0
)},
^
uint32
(
0
),
^
uint32
(
0
),
^
uint32
(
0
),
...
...
@@ -111,12 +111,12 @@ var nullDir = Dir{
// Null assigns members of d with special "don't care" values indicating
// they should not be written by syscall.Wstat.
func
(
d
*
D
ir
)
Null
()
{
func
(
d
*
d
ir
)
Null
()
{
*
d
=
nullDir
}
// pdir appends a 9P Stat message based on the contents of Dir d to a byte slice b.
func
pdir
(
b
[]
byte
,
d
*
D
ir
)
[]
byte
{
func
pdir
(
b
[]
byte
,
d
*
d
ir
)
[]
byte
{
n
:=
len
(
b
)
b
=
pbit16
(
b
,
0
)
// length, filled in later
b
=
pbit16
(
b
,
d
.
Type
)
...
...
@@ -134,9 +134,9 @@ func pdir(b []byte, d *Dir) []byte {
return
b
}
//
U
nmarshalDir reads a 9P Stat message from a 9P protocol message stored in b,
// returning the corresponding
D
ir struct.
func
UnmarshalDir
(
b
[]
byte
)
(
d
*
D
ir
,
err
error
)
{
//
u
nmarshalDir reads a 9P Stat message from a 9P protocol message stored in b,
// returning the corresponding
d
ir struct.
func
unmarshalDir
(
b
[]
byte
)
(
d
*
d
ir
,
err
error
)
{
n
:=
uint16
(
0
)
n
,
b
=
gbit16
(
b
)
...
...
@@ -144,7 +144,7 @@ func UnmarshalDir(b []byte) (d *Dir, err error) {
return
nil
,
errBadStat
}
d
=
new
(
D
ir
)
d
=
new
(
d
ir
)
d
.
Type
,
b
=
gbit16
(
b
)
d
.
Dev
,
b
=
gbit32
(
b
)
d
.
Qid
,
b
=
gqid
(
b
)
...
...
@@ -165,17 +165,17 @@ func UnmarshalDir(b []byte) (d *Dir, err error) {
}
// gqid reads the qid part of a 9P Stat message from a 9P protocol message stored in b,
// returning the corresponding
Q
id struct and the remaining slice of b.
func
gqid
(
b
[]
byte
)
(
Q
id
,
[]
byte
)
{
var
q
Q
id
// returning the corresponding
q
id struct and the remaining slice of b.
func
gqid
(
b
[]
byte
)
(
q
id
,
[]
byte
)
{
var
q
q
id
q
.
Path
,
b
=
gbit64
(
b
)
q
.
Vers
,
b
=
gbit32
(
b
)
q
.
Type
,
b
=
gbit8
(
b
)
return
q
,
b
}
// pqid appends a
Q
id struct q to a 9P message b.
func
pqid
(
b
[]
byte
,
q
Q
id
)
[]
byte
{
// pqid appends a
q
id struct q to a 9P message b.
func
pqid
(
b
[]
byte
,
q
q
id
)
[]
byte
{
b
=
pbit64
(
b
,
q
.
Path
)
b
=
pbit32
(
b
,
q
.
Vers
)
b
=
pbit8
(
b
,
q
.
Type
)
...
...
src/pkg/os/file_plan9.go
View file @
90626864
...
...
@@ -5,14 +5,11 @@
package
os
import
(
"errors"
"runtime"
"syscall"
"time"
)
var
ErrPlan9
=
errors
.
New
(
"unimplemented on Plan 9"
)
// File represents an open file descriptor.
type
File
struct
{
*
file
...
...
@@ -137,8 +134,8 @@ func OpenFile(name string, flag int, perm FileMode) (file *File, err error) {
// Close closes the File, rendering it unusable for I/O.
// It returns an error, if any.
func
(
f
ile
*
File
)
Close
()
error
{
return
f
ile
.
file
.
close
()
func
(
f
*
File
)
Close
()
error
{
return
f
.
file
.
close
()
}
func
(
file
*
file
)
close
()
error
{
...
...
@@ -159,8 +156,8 @@ func (file *file) close() error {
}
// Stat returns the FileInfo structure describing file.
// I
t returns the FileInfo and an error, if any
.
func
(
f
*
File
)
Stat
()
(
FileInfo
,
error
)
{
// I
f there is an error, it will be of type *PathError
.
func
(
f
*
File
)
Stat
()
(
fi
FileInfo
,
err
error
)
{
d
,
err
:=
dirstat
(
f
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -170,8 +167,9 @@ func (f *File) Stat() (FileInfo, error) {
// Truncate changes the size of the file.
// It does not change the I/O offset.
// If there is an error, it will be of type *PathError.
func
(
f
*
File
)
Truncate
(
size
int64
)
error
{
var
d
D
ir
var
d
d
ir
d
.
Null
()
d
.
Length
=
uint64
(
size
)
...
...
@@ -187,7 +185,7 @@ const chmodMask = uint32(syscall.DMAPPEND | syscall.DMEXCL | syscall.DMTMP | Mod
// Chmod changes the mode of the file to mode.
// If there is an error, it will be of type *PathError.
func
(
f
*
File
)
Chmod
(
mode
FileMode
)
error
{
var
d
D
ir
var
d
d
ir
odir
,
e
:=
dirstat
(
f
)
if
e
!=
nil
{
...
...
@@ -209,7 +207,7 @@ func (f *File) Sync() (err error) {
return
ErrInvalid
}
var
d
D
ir
var
d
d
ir
d
.
Null
()
if
e
:=
syscall
.
Fwstat
(
f
.
fd
,
pdir
(
nil
,
&
d
));
e
!=
nil
{
...
...
@@ -255,7 +253,7 @@ func (f *File) seek(offset int64, whence int) (ret int64, err error) {
// If the file is a symbolic link, it changes the size of the link's target.
// If there is an error, it will be of type *PathError.
func
Truncate
(
name
string
,
size
int64
)
error
{
var
d
D
ir
var
d
d
ir
d
.
Null
()
d
.
Length
=
uint64
(
size
)
...
...
@@ -277,7 +275,7 @@ func Remove(name string) error {
// Rename renames a file.
func
Rename
(
oldname
,
newname
string
)
error
{
var
d
D
ir
var
d
d
ir
d
.
Null
()
d
.
Name
=
newname
...
...
@@ -289,9 +287,10 @@ func Rename(oldname, newname string) error {
}
// Chmod changes the mode of the named file to mode.
// If the file is a symbolic link, it changes the mode of the link's target.
// If there is an error, it will be of type *PathError.
func
Chmod
(
name
string
,
mode
FileMode
)
error
{
var
d
D
ir
var
d
d
ir
odir
,
e
:=
dirstat
(
name
)
if
e
!=
nil
{
...
...
@@ -310,8 +309,9 @@ func Chmod(name string, mode FileMode) error {
//
// The underlying filesystem may truncate or round the values to a
// less precise time unit.
// If there is an error, it will be of type *PathError.
func
Chtimes
(
name
string
,
atime
time
.
Time
,
mtime
time
.
Time
)
error
{
var
d
D
ir
var
d
d
ir
d
.
Null
()
d
.
Atime
=
uint32
(
atime
.
Unix
())
...
...
@@ -323,6 +323,8 @@ func Chtimes(name string, atime time.Time, mtime time.Time) error {
return
nil
}
// Pipe returns a connected pair of Files; reads from r return bytes
// written to w. It returns the files and an error, if any.
func
Pipe
()
(
r
*
File
,
w
*
File
,
err
error
)
{
var
p
[
2
]
int
...
...
@@ -338,32 +340,42 @@ func Pipe() (r *File, w *File, err error) {
// not supported on Plan 9
// Link creates
a hard link
.
// Link creates
newname as a hard link to the oldname file
.
// If there is an error, it will be of type *LinkError.
func
Link
(
oldname
,
newname
string
)
error
{
return
&
LinkError
{
"link"
,
oldname
,
newname
,
ErrPlan
9
}
return
&
LinkError
{
"link"
,
oldname
,
newname
,
syscall
.
EPLAN
9
}
}
// Symlink creates newname as a symbolic link to oldname.
// If there is an error, it will be of type *LinkError.
func
Symlink
(
oldname
,
newname
string
)
error
{
return
&
LinkError
{
"symlink"
,
oldname
,
newname
,
ErrPlan
9
}
return
&
LinkError
{
"symlink"
,
oldname
,
newname
,
syscall
.
EPLAN
9
}
}
// Readlink returns the destination of the named symbolic link.
// If there is an error, it will be of type *PathError.
func
Readlink
(
name
string
)
(
string
,
error
)
{
return
""
,
ErrPlan9
return
""
,
&
PathError
{
"readlink"
,
name
,
syscall
.
EPLAN9
}
}
// Chown changes the numeric uid and gid of the named file.
// If the file is a symbolic link, it changes the uid and gid of the link's target.
// If there is an error, it will be of type *PathError.
func
Chown
(
name
string
,
uid
,
gid
int
)
error
{
return
ErrPlan9
return
&
PathError
{
"chown"
,
name
,
syscall
.
EPLAN9
}
}
// Lchown changes the numeric uid and gid of the named file.
// If the file is a symbolic link, it changes the uid and gid of the link itself.
// If there is an error, it will be of type *PathError.
func
Lchown
(
name
string
,
uid
,
gid
int
)
error
{
return
ErrPlan9
return
&
PathError
{
"lchown"
,
name
,
syscall
.
EPLAN9
}
}
// Chown changes the numeric uid and gid of the named file.
// If there is an error, it will be of type *PathError.
func
(
f
*
File
)
Chown
(
uid
,
gid
int
)
error
{
return
ErrPlan9
return
&
PathError
{
"chown"
,
f
.
name
,
syscall
.
EPLAN9
}
}
// TempDir returns the default directory to use for temporary files.
...
...
src/pkg/os/path_plan9.go
View file @
90626864
...
...
@@ -5,8 +5,8 @@
package
os
const
(
PathSeparator
=
'/'
// OS-specific path separator
PathListSeparator
=
0
// OS-specific path list separator
PathSeparator
=
'/'
// OS-specific path separator
PathListSeparator
=
'\000'
// OS-specific path list separator
)
// IsPathSeparator returns true if c is a directory separator character.
...
...
src/pkg/os/stat_plan9.go
View file @
90626864
...
...
@@ -10,12 +10,12 @@ import (
)
func
sameFile
(
sys1
,
sys2
interface
{})
bool
{
a
:=
sys1
.
(
*
D
ir
)
b
:=
sys2
.
(
*
D
ir
)
a
:=
sys1
.
(
*
d
ir
)
b
:=
sys2
.
(
*
d
ir
)
return
a
.
Qid
.
Path
==
b
.
Qid
.
Path
&&
a
.
Type
==
b
.
Type
&&
a
.
Dev
==
b
.
Dev
}
func
fileInfoFromStat
(
d
*
D
ir
)
FileInfo
{
func
fileInfoFromStat
(
d
*
d
ir
)
FileInfo
{
fs
:=
&
fileStat
{
name
:
d
.
Name
,
size
:
int64
(
d
.
Length
),
...
...
@@ -39,7 +39,7 @@ func fileInfoFromStat(d *Dir) FileInfo {
}
// arg is an open *File or a path string.
func
dirstat
(
arg
interface
{})
(
d
*
D
ir
,
err
error
)
{
func
dirstat
(
arg
interface
{})
(
d
*
d
ir
,
err
error
)
{
var
name
string
// This is big enough for most stat messages
...
...
@@ -72,7 +72,7 @@ func dirstat(arg interface{}) (d *Dir, err error) {
// If the stat message is larger than our buffer we will
// go around the loop and allocate one that is big enough.
if
size
<=
n
{
d
,
err
=
U
nmarshalDir
(
buf
[
:
n
])
d
,
err
=
u
nmarshalDir
(
buf
[
:
n
])
if
err
!=
nil
{
return
nil
,
&
PathError
{
"stat"
,
name
,
err
}
}
...
...
@@ -82,9 +82,9 @@ func dirstat(arg interface{}) (d *Dir, err error) {
return
nil
,
&
PathError
{
"stat"
,
name
,
errBadStat
}
}
// Stat returns a FileInfo
structure
describing the named file.
// Stat returns a FileInfo describing the named file.
// If there is an error, it will be of type *PathError.
func
Stat
(
name
string
)
(
FileInfo
,
error
)
{
func
Stat
(
name
string
)
(
fi
FileInfo
,
err
error
)
{
d
,
err
:=
dirstat
(
name
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -92,15 +92,15 @@ func Stat(name string) (FileInfo, error) {
return
fileInfoFromStat
(
d
),
nil
}
// Lstat returns
the FileInfo structure
describing the named file.
// If the file is a symbolic link
(though Plan 9 does not have symbolic links),
//
the returned FileInfo
describes the symbolic link. Lstat makes no attempt to follow the link.
// Lstat returns
a FileInfo
describing the named file.
// If the file is a symbolic link
, the returned FileInfo
// describes the symbolic link. Lstat makes no attempt to follow the link.
// If there is an error, it will be of type *PathError.
func
Lstat
(
name
string
)
(
FileInfo
,
error
)
{
func
Lstat
(
name
string
)
(
fi
FileInfo
,
err
error
)
{
return
Stat
(
name
)
}
// For testing.
func
atime
(
fi
FileInfo
)
time
.
Time
{
return
time
.
Unix
(
int64
(
fi
.
Sys
()
.
(
*
D
ir
)
.
Atime
),
0
)
return
time
.
Unix
(
int64
(
fi
.
Sys
()
.
(
*
d
ir
)
.
Atime
),
0
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment