|
@@ -14,6 +14,7 @@ package unix
|
|
|
|
|
|
import "unsafe"
|
|
|
|
|
|
+// SockaddrDatalink implements the Sockaddr interface for AF_LINK type sockets.
|
|
|
type SockaddrDatalink struct {
|
|
|
Len uint8
|
|
|
Family uint8
|
|
@@ -54,18 +55,6 @@ func nametomib(name string) (mib []_C_int, err error) {
|
|
|
return buf[0 : n/siz], nil
|
|
|
}
|
|
|
|
|
|
-func direntIno(buf []byte) (uint64, bool) {
|
|
|
- return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno))
|
|
|
-}
|
|
|
-
|
|
|
-func direntReclen(buf []byte) (uint64, bool) {
|
|
|
- return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
|
|
|
-}
|
|
|
-
|
|
|
-func direntNamlen(buf []byte) (uint64, bool) {
|
|
|
- return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))
|
|
|
-}
|
|
|
-
|
|
|
//sysnb pipe() (r int, w int, err error)
|
|
|
|
|
|
func Pipe(p []int) (err error) {
|
|
@@ -105,6 +94,23 @@ func Accept4(fd, flags int) (nfd int, sa Sockaddr, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+const ImplementsGetwd = true
|
|
|
+
|
|
|
+//sys Getcwd(buf []byte) (n int, err error) = SYS___GETCWD
|
|
|
+
|
|
|
+func Getwd() (string, error) {
|
|
|
+ var buf [PathMax]byte
|
|
|
+ _, err := Getcwd(buf[0:])
|
|
|
+ if err != nil {
|
|
|
+ return "", err
|
|
|
+ }
|
|
|
+ n := clen(buf[:])
|
|
|
+ if n < 1 {
|
|
|
+ return "", EINVAL
|
|
|
+ }
|
|
|
+ return string(buf[:n]), nil
|
|
|
+}
|
|
|
+
|
|
|
func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
|
|
|
var _p0 unsafe.Pointer
|
|
|
var bufsize uintptr
|
|
@@ -120,6 +126,11 @@ func Getfsstat(buf []Statfs_t, flags int) (n int, err error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+func setattrlistTimes(path string, times []Timespec, flags int) error {
|
|
|
+ // used on Darwin for UtimesNano
|
|
|
+ return ENOSYS
|
|
|
+}
|
|
|
+
|
|
|
// Derive extattr namespace and attribute name
|
|
|
|
|
|
func xattrnamespace(fullattr string) (ns int, attr string, err error) {
|
|
@@ -271,7 +282,6 @@ func Listxattr(file string, dest []byte) (sz int, err error) {
|
|
|
|
|
|
// FreeBSD won't allow you to list xattrs from multiple namespaces
|
|
|
s := 0
|
|
|
- var e error
|
|
|
for _, nsid := range [...]int{EXTATTR_NAMESPACE_USER, EXTATTR_NAMESPACE_SYSTEM} {
|
|
|
stmp, e := ExtattrListFile(file, nsid, uintptr(d), destsiz)
|
|
|
|
|
@@ -283,7 +293,6 @@ func Listxattr(file string, dest []byte) (sz int, err error) {
|
|
|
* we don't have read permissions on, so don't ignore those errors
|
|
|
*/
|
|
|
if e != nil && e == EPERM && nsid != EXTATTR_NAMESPACE_USER {
|
|
|
- e = nil
|
|
|
continue
|
|
|
} else if e != nil {
|
|
|
return s, e
|
|
@@ -297,7 +306,7 @@ func Listxattr(file string, dest []byte) (sz int, err error) {
|
|
|
d = initxattrdest(dest, s)
|
|
|
}
|
|
|
|
|
|
- return s, e
|
|
|
+ return s, nil
|
|
|
}
|
|
|
|
|
|
func Flistxattr(fd int, dest []byte) (sz int, err error) {
|
|
@@ -305,11 +314,9 @@ func Flistxattr(fd int, dest []byte) (sz int, err error) {
|
|
|
destsiz := len(dest)
|
|
|
|
|
|
s := 0
|
|
|
- var e error
|
|
|
for _, nsid := range [...]int{EXTATTR_NAMESPACE_USER, EXTATTR_NAMESPACE_SYSTEM} {
|
|
|
stmp, e := ExtattrListFd(fd, nsid, uintptr(d), destsiz)
|
|
|
if e != nil && e == EPERM && nsid != EXTATTR_NAMESPACE_USER {
|
|
|
- e = nil
|
|
|
continue
|
|
|
} else if e != nil {
|
|
|
return s, e
|
|
@@ -323,7 +330,7 @@ func Flistxattr(fd int, dest []byte) (sz int, err error) {
|
|
|
d = initxattrdest(dest, s)
|
|
|
}
|
|
|
|
|
|
- return s, e
|
|
|
+ return s, nil
|
|
|
}
|
|
|
|
|
|
func Llistxattr(link string, dest []byte) (sz int, err error) {
|
|
@@ -331,11 +338,9 @@ func Llistxattr(link string, dest []byte) (sz int, err error) {
|
|
|
destsiz := len(dest)
|
|
|
|
|
|
s := 0
|
|
|
- var e error
|
|
|
for _, nsid := range [...]int{EXTATTR_NAMESPACE_USER, EXTATTR_NAMESPACE_SYSTEM} {
|
|
|
stmp, e := ExtattrListLink(link, nsid, uintptr(d), destsiz)
|
|
|
if e != nil && e == EPERM && nsid != EXTATTR_NAMESPACE_USER {
|
|
|
- e = nil
|
|
|
continue
|
|
|
} else if e != nil {
|
|
|
return s, e
|
|
@@ -349,7 +354,7 @@ func Llistxattr(link string, dest []byte) (sz int, err error) {
|
|
|
d = initxattrdest(dest, s)
|
|
|
}
|
|
|
|
|
|
- return s, e
|
|
|
+ return s, nil
|
|
|
}
|
|
|
|
|
|
//sys ioctl(fd int, req uint, arg uintptr) (err error)
|
|
@@ -391,6 +396,52 @@ func IoctlGetTermios(fd int, req uint) (*Termios, error) {
|
|
|
return &value, err
|
|
|
}
|
|
|
|
|
|
+func Uname(uname *Utsname) error {
|
|
|
+ mib := []_C_int{CTL_KERN, KERN_OSTYPE}
|
|
|
+ n := unsafe.Sizeof(uname.Sysname)
|
|
|
+ if err := sysctl(mib, &uname.Sysname[0], &n, nil, 0); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ mib = []_C_int{CTL_KERN, KERN_HOSTNAME}
|
|
|
+ n = unsafe.Sizeof(uname.Nodename)
|
|
|
+ if err := sysctl(mib, &uname.Nodename[0], &n, nil, 0); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ mib = []_C_int{CTL_KERN, KERN_OSRELEASE}
|
|
|
+ n = unsafe.Sizeof(uname.Release)
|
|
|
+ if err := sysctl(mib, &uname.Release[0], &n, nil, 0); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ mib = []_C_int{CTL_KERN, KERN_VERSION}
|
|
|
+ n = unsafe.Sizeof(uname.Version)
|
|
|
+ if err := sysctl(mib, &uname.Version[0], &n, nil, 0); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ // The version might have newlines or tabs in it, convert them to
|
|
|
+ // spaces.
|
|
|
+ for i, b := range uname.Version {
|
|
|
+ if b == '\n' || b == '\t' {
|
|
|
+ if i == len(uname.Version)-1 {
|
|
|
+ uname.Version[i] = 0
|
|
|
+ } else {
|
|
|
+ uname.Version[i] = ' '
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ mib = []_C_int{CTL_HW, HW_MACHINE}
|
|
|
+ n = unsafe.Sizeof(uname.Machine)
|
|
|
+ if err := sysctl(mib, &uname.Machine[0], &n, nil, 0); err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
/*
|
|
|
* Exposed directly
|
|
|
*/
|
|
@@ -434,6 +485,7 @@ func IoctlGetTermios(fd int, req uint) (*Termios, error) {
|
|
|
//sys Fstatfs(fd int, stat *Statfs_t) (err error)
|
|
|
//sys Fsync(fd int) (err error)
|
|
|
//sys Ftruncate(fd int, length int64) (err error)
|
|
|
+//sys Getdents(fd int, buf []byte) (n int, err error)
|
|
|
//sys Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error)
|
|
|
//sys Getdtablesize() (size int)
|
|
|
//sysnb Getegid() (egid int)
|