diff options
Diffstat (limited to 'src/pkg/os/file_plan9.go')
-rw-r--r-- | src/pkg/os/file_plan9.go | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/src/pkg/os/file_plan9.go b/src/pkg/os/file_plan9.go index 7d136eb36..cb0e9ef92 100644 --- a/src/pkg/os/file_plan9.go +++ b/src/pkg/os/file_plan9.go @@ -5,11 +5,14 @@ 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 @@ -26,19 +29,20 @@ type file struct { } // Fd returns the integer Unix file descriptor referencing the open file. -func (file *File) Fd() int { - if file == nil { - return -1 +func (f *File) Fd() uintptr { + if f == nil { + return ^(uintptr(0)) } - return file.fd + return uintptr(f.fd) } // NewFile returns a new File with the given file descriptor and name. -func NewFile(fd int, name string) *File { - if fd < 0 { +func NewFile(fd uintptr, name string) *File { + fdi := int(fd) + if fdi < 0 { return nil } - f := &File{&file{fd: fd, name: name}} + f := &File{&file{fd: fdi, name: name}} runtime.SetFinalizer(f.file, (*file).close) return f } @@ -76,7 +80,7 @@ func syscallMode(i FileMode) (o uint32) { // or Create instead. It opens the named file with specified flag // (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful, // methods on the returned File can be used for I/O. -// It returns the File and an error, if any. +// If there is an error, it will be of type *PathError. func OpenFile(name string, flag int, perm FileMode) (file *File, err error) { var ( fd int @@ -128,7 +132,7 @@ func OpenFile(name string, flag int, perm FileMode) (file *File, err error) { } } - return NewFile(fd, name), nil + return NewFile(uintptr(fd), name), nil } // Close closes the File, rendering it unusable for I/O. @@ -139,7 +143,7 @@ func (file *File) Close() error { func (file *file) close() error { if file == nil || file.fd < 0 { - return Ebadfd + return ErrInvalid } var err error syscall.ForkLock.RLock() @@ -181,6 +185,7 @@ func (f *File) Truncate(size int64) error { const chmodMask = uint32(syscall.DMAPPEND | syscall.DMEXCL | syscall.DMTMP | ModePerm) // 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 Dir @@ -201,7 +206,7 @@ func (f *File) Chmod(mode FileMode) error { // of recently written data to disk. func (f *File) Sync() (err error) { if f == nil { - return EINVAL + return ErrInvalid } var d Dir @@ -248,6 +253,7 @@ func (f *File) seek(offset int64, whence int) (ret int64, err error) { // Truncate changes the size of the named file. // 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 Dir d.Null() @@ -261,6 +267,7 @@ func Truncate(name string, size int64) error { } // Remove removes the named file or directory. +// If there is an error, it will be of type *PathError. func Remove(name string) error { if e := syscall.Remove(name); e != nil { return &PathError{"remove", name, e} @@ -282,6 +289,7 @@ func Rename(oldname, newname string) error { } // Chmod changes the mode of the named file to mode. +// If there is an error, it will be of type *PathError. func Chmod(name string, mode FileMode) error { var d Dir @@ -325,34 +333,37 @@ func Pipe() (r *File, w *File, err error) { } syscall.ForkLock.RUnlock() - return NewFile(p[0], "|0"), NewFile(p[1], "|1"), nil + return NewFile(uintptr(p[0]), "|0"), NewFile(uintptr(p[1]), "|1"), nil } // not supported on Plan 9 // Link creates a hard link. +// If there is an error, it will be of type *LinkError. func Link(oldname, newname string) error { - return EPLAN9 + return &LinkError{"link", oldname, newname, ErrPlan9} } +// 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 EPLAN9 + return &LinkError{"symlink", oldname, newname, ErrPlan9} } func Readlink(name string) (string, error) { - return "", EPLAN9 + return "", ErrPlan9 } func Chown(name string, uid, gid int) error { - return EPLAN9 + return ErrPlan9 } func Lchown(name string, uid, gid int) error { - return EPLAN9 + return ErrPlan9 } func (f *File) Chown(uid, gid int) error { - return EPLAN9 + return ErrPlan9 } // TempDir returns the default directory to use for temporary files. |