Skip to content

Commit

Permalink
unix: implement Fstat{,at} using Statx on linux/loong64
Browse files Browse the repository at this point in the history
linux/loong64 doesn't provide the fstat and fstatat syscalls in the
upstream Linux kernel. Instead, solely the statx syscall is available.
Use it to implement Fstat and Fstatat.

This follows the implementation in package syscall.

Change-Id: I69eefc863a37bd76ef2ab1e7670d1724dc147aae
Reviewed-on: https://go-review.googlesource.com/c/sys/+/411378
Auto-Submit: Ian Lance Taylor <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
Run-TryBot: Ian Lance Taylor <[email protected]>
Run-TryBot: Tobias Klauser <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
Auto-Submit: Tobias Klauser <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
  • Loading branch information
tklauser authored and gopherbot committed Jun 15, 2022
1 parent 6c1b26c commit 003f7fa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 27 deletions.
39 changes: 37 additions & 2 deletions unix/syscall_linux_loong64.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import "unsafe"
//sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) = SYS_EPOLL_PWAIT
//sys Fadvise(fd int, offset int64, length int64, advice int) (err error) = SYS_FADVISE64
//sys Fchown(fd int, uid int, gid int) (err error)
//sys Fstat(fd int, stat *Stat_t) (err error)
//sys Fstatat(fd int, path string, stat *Stat_t, flags int) (err error)
//sys Fstatfs(fd int, buf *Statfs_t) (err error)
//sys Ftruncate(fd int, length int64) (err error)
//sysnb Getegid() (egid int)
Expand Down Expand Up @@ -43,6 +41,43 @@ func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err
//sys Shutdown(fd int, how int) (err error)
//sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error)

func timespecFromStatxTimestamp(x StatxTimestamp) Timespec {
return Timespec{
Sec: x.Sec,
Nsec: int64(x.Nsec),
}
}

func Fstatat(fd int, path string, stat *Stat_t, flags int) error {
var r Statx_t
// Do it the glibc way, add AT_NO_AUTOMOUNT.
if err := Statx(fd, path, AT_NO_AUTOMOUNT|flags, STATX_BASIC_STATS, &r); err != nil {
return err
}

stat.Dev = Mkdev(r.Dev_major, r.Dev_minor)
stat.Ino = r.Ino
stat.Mode = uint32(r.Mode)
stat.Nlink = r.Nlink
stat.Uid = r.Uid
stat.Gid = r.Gid
stat.Rdev = Mkdev(r.Rdev_major, r.Rdev_minor)
// hope we don't get to process files so large to overflow these size
// fields...
stat.Size = int64(r.Size)
stat.Blksize = int32(r.Blksize)
stat.Blocks = int64(r.Blocks)
stat.Atim = timespecFromStatxTimestamp(r.Atime)
stat.Mtim = timespecFromStatxTimestamp(r.Mtime)
stat.Ctim = timespecFromStatxTimestamp(r.Ctime)

return nil
}

func Fstat(fd int, stat *Stat_t) (err error) {
return Fstatat(fd, "", stat, AT_EMPTY_PATH)
}

func Stat(path string, stat *Stat_t) (err error) {
return Fstatat(AT_FDCWD, path, stat, 0)
}
Expand Down
25 changes: 0 additions & 25 deletions unix/zsyscall_linux_loong64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 003f7fa

Please sign in to comment.