mirror of
https://github.com/rwinkhart/sys.git
synced 2026-08-30 13:56:45 -04:00
unix: split Pipe/Pipe2/Dup2, use *at replacement calls
This brings over three CLs from the main syscall package: http://golang.org/cl/5833 http://golang.org/cl/5835 http://golang.org/cl/5837 Pipe, Pipe2, and Dup2 are moved from syscall_linux.go to the GOARCH specific variants. On 386 and amd64, Linux kernel version 2.6.23 (the documented minimum Linux kernel version the Go distribution supports) does not support the pipe2 system call, so Pipe continues to call pipe. On ARM, Pipe now calls pipe2. Several system calls are reimplemented in terms of the *at syscalls, passing AT_FDCWD to indicate that pathnames are to be interpreted relative to the current directory. The *at syscalls were added in Linux kernel version 2.6.16. This is in preparation for arm64 support, as the arm64 Linux kernel does not provide the traditional syscall variants. Change-Id: Id6bc6097dc5f4324cd9e429c5e1f3a411a08ce42 Reviewed-on: https://go-review.googlesource.com/10032 Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
+54
-35
@@ -20,10 +20,38 @@ import (
|
||||
* Wrapped
|
||||
*/
|
||||
|
||||
//sys open(path string, mode int, perm uint32) (fd int, err error)
|
||||
func Access(path string, mode uint32) (err error) {
|
||||
return Faccessat(AT_FDCWD, path, mode, 0)
|
||||
}
|
||||
|
||||
func Chmod(path string, mode uint32) (err error) {
|
||||
return Fchmodat(AT_FDCWD, path, mode, 0)
|
||||
}
|
||||
|
||||
func Chown(path string, uid int, gid int) (err error) {
|
||||
return Fchownat(AT_FDCWD, path, uid, gid, 0)
|
||||
}
|
||||
|
||||
func Creat(path string, mode uint32) (fd int, err error) {
|
||||
return Open(path, O_CREAT|O_WRONLY|O_TRUNC, mode)
|
||||
}
|
||||
|
||||
//sys linkat(olddirfd int, oldpath string, newdirfd int, newpath string, flags int) (err error)
|
||||
|
||||
func Link(oldpath string, newpath string) (err error) {
|
||||
return linkat(AT_FDCWD, oldpath, AT_FDCWD, newpath, 0)
|
||||
}
|
||||
|
||||
func Mkdir(path string, mode uint32) (err error) {
|
||||
return Mkdirat(AT_FDCWD, path, mode)
|
||||
}
|
||||
|
||||
func Mknod(path string, mode uint32, dev int) (err error) {
|
||||
return Mknodat(AT_FDCWD, path, mode, dev)
|
||||
}
|
||||
|
||||
func Open(path string, mode int, perm uint32) (fd int, err error) {
|
||||
return open(path, mode|O_LARGEFILE, perm)
|
||||
return openat(AT_FDCWD, path, mode|O_LARGEFILE, perm)
|
||||
}
|
||||
|
||||
//sys openat(dirfd int, path string, flags int, mode uint32) (fd int, err error)
|
||||
@@ -32,30 +60,34 @@ func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error)
|
||||
return openat(dirfd, path, flags|O_LARGEFILE, mode)
|
||||
}
|
||||
|
||||
//sysnb pipe(p *[2]_C_int) (err error)
|
||||
//sys readlinkat(dirfd int, path string, buf []byte) (n int, err error)
|
||||
|
||||
func Pipe(p []int) (err error) {
|
||||
if len(p) != 2 {
|
||||
return EINVAL
|
||||
}
|
||||
var pp [2]_C_int
|
||||
err = pipe(&pp)
|
||||
p[0] = int(pp[0])
|
||||
p[1] = int(pp[1])
|
||||
return
|
||||
func Readlink(path string, buf []byte) (n int, err error) {
|
||||
return readlinkat(AT_FDCWD, path, buf)
|
||||
}
|
||||
|
||||
//sysnb pipe2(p *[2]_C_int, flags int) (err error)
|
||||
func Rename(oldpath string, newpath string) (err error) {
|
||||
return Renameat(AT_FDCWD, oldpath, AT_FDCWD, newpath)
|
||||
}
|
||||
|
||||
func Pipe2(p []int, flags int) (err error) {
|
||||
if len(p) != 2 {
|
||||
return EINVAL
|
||||
}
|
||||
var pp [2]_C_int
|
||||
err = pipe2(&pp, flags)
|
||||
p[0] = int(pp[0])
|
||||
p[1] = int(pp[1])
|
||||
return
|
||||
func Rmdir(path string) error {
|
||||
return unlinkat(AT_FDCWD, path, AT_REMOVEDIR)
|
||||
}
|
||||
|
||||
//sys symlinkat(oldpath string, newdirfd int, newpath string) (err error)
|
||||
|
||||
func Symlink(oldpath string, newpath string) (err error) {
|
||||
return symlinkat(oldpath, AT_FDCWD, newpath)
|
||||
}
|
||||
|
||||
func Unlink(path string) error {
|
||||
return unlinkat(AT_FDCWD, path, 0)
|
||||
}
|
||||
|
||||
//sys unlinkat(dirfd int, path string, flags int) (err error)
|
||||
|
||||
func Unlinkat(dirfd int, path string) error {
|
||||
return unlinkat(dirfd, path, 0)
|
||||
}
|
||||
|
||||
//sys utimes(path string, times *[2]Timeval) (err error)
|
||||
@@ -789,17 +821,13 @@ func Mount(source string, target string, fstype string, flags uintptr, data stri
|
||||
/*
|
||||
* Direct access
|
||||
*/
|
||||
//sys Access(path string, mode uint32) (err error)
|
||||
//sys Acct(path string) (err error)
|
||||
//sys Adjtimex(buf *Timex) (state int, err error)
|
||||
//sys Chdir(path string) (err error)
|
||||
//sys Chmod(path string, mode uint32) (err error)
|
||||
//sys Chroot(path string) (err error)
|
||||
//sys ClockGettime(clockid int32, time *Timespec) (err error)
|
||||
//sys Close(fd int) (err error)
|
||||
//sys Creat(path string, mode uint32) (fd int, err error)
|
||||
//sys Dup(oldfd int) (fd int, err error)
|
||||
//sys Dup2(oldfd int, newfd int) (err error)
|
||||
//sys Dup3(oldfd int, newfd int, flags int) (err error)
|
||||
//sysnb EpollCreate(size int) (fd int, err error)
|
||||
//sysnb EpollCreate1(flag int) (fd int, err error)
|
||||
@@ -836,22 +864,16 @@ func Getpgrp() (pid int) {
|
||||
//sysnb InotifyRmWatch(fd int, watchdesc uint32) (success int, err error)
|
||||
//sysnb Kill(pid int, sig syscall.Signal) (err error)
|
||||
//sys Klogctl(typ int, buf []byte) (n int, err error) = SYS_SYSLOG
|
||||
//sys Link(oldpath string, newpath string) (err error)
|
||||
//sys Listxattr(path string, dest []byte) (sz int, err error)
|
||||
//sys Mkdir(path string, mode uint32) (err error)
|
||||
//sys Mkdirat(dirfd int, path string, mode uint32) (err error)
|
||||
//sys Mknod(path string, mode uint32, dev int) (err error)
|
||||
//sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error)
|
||||
//sys Nanosleep(time *Timespec, leftover *Timespec) (err error)
|
||||
//sys Pause() (err error)
|
||||
//sys PivotRoot(newroot string, putold string) (err error) = SYS_PIVOT_ROOT
|
||||
//sysnb prlimit(pid int, resource int, old *Rlimit, newlimit *Rlimit) (err error) = SYS_PRLIMIT64
|
||||
//sys read(fd int, p []byte) (n int, err error)
|
||||
//sys Readlink(path string, buf []byte) (n int, err error)
|
||||
//sys Removexattr(path string, attr string) (err error)
|
||||
//sys Rename(oldpath string, newpath string) (err error)
|
||||
//sys Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) (err error)
|
||||
//sys Rmdir(path string) (err error)
|
||||
//sys Setdomainname(p []byte) (err error)
|
||||
//sys Sethostname(p []byte) (err error)
|
||||
//sysnb Setpgid(pid int, pgid int) (err error)
|
||||
@@ -873,7 +895,6 @@ func Setgid(uid int) (err error) {
|
||||
|
||||
//sys Setpriority(which int, who int, prio int) (err error)
|
||||
//sys Setxattr(path string, attr string, data []byte, flags int) (err error)
|
||||
//sys Symlink(oldpath string, newpath string) (err error)
|
||||
//sys Sync()
|
||||
//sysnb Sysinfo(info *Sysinfo_t) (err error)
|
||||
//sys Tee(rfd int, wfd int, len int, flags int) (n int64, err error)
|
||||
@@ -881,8 +902,6 @@ func Setgid(uid int) (err error) {
|
||||
//sysnb Times(tms *Tms) (ticks uintptr, err error)
|
||||
//sysnb Umask(mask int) (oldmask int)
|
||||
//sysnb Uname(buf *Utsname) (err error)
|
||||
//sys Unlink(path string) (err error)
|
||||
//sys Unlinkat(dirfd int, path string, flags int) (err error)
|
||||
//sys Unmount(target string, flags int) (err error) = SYS_UMOUNT2
|
||||
//sys Unshare(flags int) (err error)
|
||||
//sys Ustat(dev int, ubuf *Ustat_t) (err error)
|
||||
|
||||
Reference in New Issue
Block a user