blob: 31ff6aff30c917c91e652b5e0e4ad67a7bd3a506 [file] [log] [blame]
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package os
import (
"errors"
"internal/poll"
"syscall"
"syscall/zx/fdio"
"time"
)
func (f *File) Truncate(size int64) error {
if err := f.checkValid("truncate"); err != nil {
return err
}
return syscall.Ftruncate(f.pfd.Sysfd, size)
}
func (f *File) Sync() error {
if f == nil {
return ErrInvalid
}
return syscall.Fsync(f.pfd.Sysfd)
}
func syscallMode(i FileMode) (o uint32) {
o |= uint32(i.Perm())
// TODO i&ModeSetuid != 0
// TODO i&ModeSetgid != 0
// TODO i&ModeSticky != 0
return o
}
func (f *File) chmod(mode FileMode) error {
return errors.New("os: Chmod unimplemented on fuchsia")
}
func (f *File) Chown(uid, gid int) error {
return errors.New("os: Chown unimplemented on fuchsia")
}
func chmod(name string, mode FileMode) error {
return errors.New("os: chmod unimplemented on fuchsia")
}
func Chown(name string, uid, gid int) error {
return errors.New("os: Chown unimplemented on fuchsia")
}
func Chtimes(name string, atime time.Time, mtime time.Time) error {
var utimes [2]syscall.Timespec
utimes[0] = syscall.NsecToTimespec(atime.UnixNano())
utimes[1] = syscall.NsecToTimespec(mtime.UnixNano())
if e := syscall.UtimesNano(fixLongPath(name), utimes[0:]); e != nil {
return &PathError{"chtimes", name, e}
}
return nil
}
func Readlink(name string) (string, error) {
return "", errors.New("Readlink unimplemented")
}
func Pipe() (r *File, w *File, err error) {
p0, p1, err := fdio.NewPipes()
if err != nil {
return nil, nil, err
}
r = NewFile(uintptr(syscall.OpenFDIO(p0)), "|0")
w = NewFile(uintptr(syscall.OpenFDIO(p1)), "|1")
// TODO CloseOnExec equivalent
return r, w, nil
}
// Chdir changes the current working directory to the file,
// which must be a directory.
// If there is an error, it will be of type *PathError.
func (f *File) Chdir() error {
if err := f.checkValid("chdir"); err != nil {
return err
}
if e := syscall.Fchdir(f.pfd.Sysfd); e != nil {
return &PathError{"chdir", f.name, e}
}
return nil
}
func sigpipe() // implemented in package runtime
var supportsCloseOnExec = true
func fillFileStatFromSys(fs *fileStat, name string) {
fs.name = basename(name)
fs.size = int64(fs.sys.Size)
// For now, pretend files have all bits. This should really be:
// fs.mode = FileMode(fs.sys.Dev & 0777)
// but we don't really set file modes properly and testing for executables
// in $PATH fails without the x bit set.
fs.mode = FileMode(0766)
switch fs.sys.Dev & 0xf000 {
case 0x4000:
fs.mode = fs.mode | ModeDir
case 0x2000:
fs.mode = fs.mode | ModeCharDevice
case 0xa000:
fs.mode = fs.mode | ModeSymlink
case 0xc000:
fs.mode = fs.mode | ModeSocket
}
fs.modTime = time.Unix(int64(fs.sys.ModifyTime), 0)
}
func atime(fi FileInfo) time.Time {
// TODO: fdio doesn't have atime yet
return time.Time{}
}
// setDeadline sets the read and write deadline.
func (f *File) setDeadline(time.Time) error {
if err := f.checkValid("SetDeadline"); err != nil {
return err
}
return poll.ErrNoDeadline
}
// setReadDeadline sets the read deadline.
func (f *File) setReadDeadline(time.Time) error {
if err := f.checkValid("SetReadDeadline"); err != nil {
return err
}
return poll.ErrNoDeadline
}
// setWriteDeadline sets the write deadline.
func (f *File) setWriteDeadline(time.Time) error {
if err := f.checkValid("SetWriteDeadline"); err != nil {
return err
}
return poll.ErrNoDeadline
}
// checkValid checks whether f is valid for use.
func (f *File) checkValid(op string) error {
if f == nil {
return ErrInvalid
}
return nil
}