syscall_freebsd.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2009,2010 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package syscall
  5. import (
  6. "sync"
  7. "unsafe"
  8. )
  9. const (
  10. _SYS_FSTAT_FREEBSD12 = 551 // { int fstat(int fd, _Out_ struct stat *sb); }
  11. _SYS_FSTATAT_FREEBSD12 = 552 // { int fstatat(int fd, _In_z_ char *path, _Out_ struct stat *buf, int flag); }
  12. _SYS_GETDIRENTRIES_FREEBSD12 = 554 // { ssize_t getdirentries(int fd, _Out_writes_bytes_(count) char *buf, size_t count, _Out_ off_t *basep); }
  13. _SYS_STATFS_FREEBSD12 = 555 // { int statfs(_In_z_ char *path, _Out_ struct statfs *buf); }
  14. _SYS_FSTATFS_FREEBSD12 = 556 // { int fstatfs(int fd, _Out_ struct statfs *buf); }
  15. _SYS_GETFSSTAT_FREEBSD12 = 557 // { int getfsstat(_Out_writes_bytes_opt_(bufsize) struct statfs *buf, long bufsize, int mode); }
  16. _SYS_MKNODAT_FREEBSD12 = 559 // { int mknodat(int fd, _In_z_ char *path, mode_t mode, dev_t dev); }
  17. )
  18. // See https://www.freebsd.org/doc/en_US.ISO8859-1/books/porters-handbook/versions.html.
  19. var (
  20. osreldateOnce sync.Once
  21. osreldate uint32
  22. )
  23. // INO64_FIRST from /usr/src/lib/libc/sys/compat-ino64.h
  24. const _ino64First = 1200031
  25. func supportsABI(ver uint32) bool {
  26. osreldateOnce.Do(func() { osreldate, _ = SysctlUint32("kern.osreldate") })
  27. return osreldate >= ver
  28. }
  29. func direntIno(buf []byte) (uint64, bool) {
  30. return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno))
  31. }
  32. func direntReclen(buf []byte) (uint64, bool) {
  33. return readInt(buf, unsafe.Offsetof(Dirent{}.Reclen), unsafe.Sizeof(Dirent{}.Reclen))
  34. }
  35. func direntNamlen(buf []byte) (uint64, bool) {
  36. return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen))
  37. }