summaryrefslogtreecommitdiff
path: root/libgo/go/os/file_plan9.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/os/file_plan9.go')
-rw-r--r--libgo/go/os/file_plan9.go92
1 files changed, 64 insertions, 28 deletions
diff --git a/libgo/go/os/file_plan9.go b/libgo/go/os/file_plan9.go
index db366a07cc9..fb2f2347d7d 100644
--- a/libgo/go/os/file_plan9.go
+++ b/libgo/go/os/file_plan9.go
@@ -169,13 +169,18 @@ func (f *File) Stat() (fi FileInfo, err error) {
// 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 dir
- d.Null()
+ var d syscall.Dir
- d.Length = uint64(size)
+ d.Null()
+ d.Length = size
- if e := syscall.Fwstat(f.fd, pdir(nil, &d)); e != nil {
- return &PathError{"truncate", f.name, e}
+ var buf [syscall.STATFIXLEN]byte
+ n, err := d.Marshal(buf[:])
+ if err != nil {
+ return &PathError{"truncate", f.name, err}
+ }
+ if err = syscall.Fwstat(f.fd, buf[:n]); err != nil {
+ return &PathError{"truncate", f.name, err}
}
return nil
}
@@ -185,7 +190,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 dir
+ var d syscall.Dir
odir, e := dirstat(f)
if e != nil {
@@ -193,8 +198,14 @@ func (f *File) Chmod(mode FileMode) error {
}
d.Null()
d.Mode = odir.Mode&^chmodMask | syscallMode(mode)&chmodMask
- if e := syscall.Fwstat(f.fd, pdir(nil, &d)); e != nil {
- return &PathError{"chmod", f.name, e}
+
+ var buf [syscall.STATFIXLEN]byte
+ n, err := d.Marshal(buf[:])
+ if err != nil {
+ return &PathError{"chmod", f.name, err}
+ }
+ if err = syscall.Fwstat(f.fd, buf[:n]); err != nil {
+ return &PathError{"chmod", f.name, err}
}
return nil
}
@@ -206,12 +217,16 @@ func (f *File) Sync() (err error) {
if f == nil {
return ErrInvalid
}
-
- var d dir
+ var d syscall.Dir
d.Null()
- if e := syscall.Fwstat(f.fd, pdir(nil, &d)); e != nil {
- return NewSyscallError("fsync", e)
+ var buf [syscall.STATFIXLEN]byte
+ n, err := d.Marshal(buf[:])
+ if err != nil {
+ return NewSyscallError("fsync", err)
+ }
+ if err = syscall.Fwstat(f.fd, buf[:n]); err != nil {
+ return NewSyscallError("fsync", err)
}
return nil
}
@@ -253,13 +268,18 @@ 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 dir
- d.Null()
+ var d syscall.Dir
- d.Length = uint64(size)
+ d.Null()
+ d.Length = size
- if e := syscall.Wstat(name, pdir(nil, &d)); e != nil {
- return &PathError{"truncate", name, e}
+ var buf [syscall.STATFIXLEN]byte
+ n, err := d.Marshal(buf[:])
+ if err != nil {
+ return &PathError{"truncate", name, err}
+ }
+ if err = syscall.Wstat(name, buf[:n]); err != nil {
+ return &PathError{"truncate", name, err}
}
return nil
}
@@ -275,13 +295,18 @@ func Remove(name string) error {
// Rename renames a file.
func Rename(oldname, newname string) error {
- var d dir
- d.Null()
+ var d syscall.Dir
+ d.Null()
d.Name = newname
- if e := syscall.Wstat(oldname, pdir(nil, &d)); e != nil {
- return &PathError{"rename", oldname, e}
+ var buf [syscall.STATFIXLEN]byte
+ n, err := d.Marshal(buf[:])
+ if err != nil {
+ return &PathError{"rename", oldname, err}
+ }
+ if err = syscall.Wstat(oldname, buf[:n]); err != nil {
+ return &PathError{"rename", oldname, err}
}
return nil
}
@@ -290,7 +315,7 @@ func Rename(oldname, newname string) error {
// 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 dir
+ var d syscall.Dir
odir, e := dirstat(name)
if e != nil {
@@ -298,8 +323,14 @@ func Chmod(name string, mode FileMode) error {
}
d.Null()
d.Mode = odir.Mode&^chmodMask | syscallMode(mode)&chmodMask
- if e := syscall.Wstat(name, pdir(nil, &d)); e != nil {
- return &PathError{"chmod", name, e}
+
+ var buf [syscall.STATFIXLEN]byte
+ n, err := d.Marshal(buf[:])
+ if err != nil {
+ return &PathError{"chmod", name, err}
+ }
+ if err = syscall.Wstat(name, buf[:n]); err != nil {
+ return &PathError{"chmod", name, err}
}
return nil
}
@@ -311,14 +342,19 @@ func Chmod(name string, mode FileMode) error {
// 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 dir
- d.Null()
+ var d syscall.Dir
+ d.Null()
d.Atime = uint32(atime.Unix())
d.Mtime = uint32(mtime.Unix())
- if e := syscall.Wstat(name, pdir(nil, &d)); e != nil {
- return &PathError{"chtimes", name, e}
+ var buf [syscall.STATFIXLEN]byte
+ n, err := d.Marshal(buf[:])
+ if err != nil {
+ return &PathError{"chtimes", name, err}
+ }
+ if err = syscall.Wstat(name, buf[:n]); err != nil {
+ return &PathError{"chtimes", name, err}
}
return nil
}