Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions runtime/internal/clite/syscall/fs_wasip1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2023 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.

//go:build wasip1

package syscall

type Stat_t struct {
Dev uint64
Ino uint64
Filetype uint8
Nlink uint64
Size uint64
Atime uint64
Mtime uint64
Ctime uint64

Mode int

// Uid and Gid are always zero on wasip1 platforms
Uid uint32
Gid uint32
}
11 changes: 0 additions & 11 deletions runtime/internal/clite/syscall/fs_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,14 +310,3 @@ func hasPrefix(s, prefix string) bool {
func hasSuffix(s, suffix string) bool {
return len(s) >= len(suffix) && s[len(s)-len(suffix):] == suffix
}

type Stat_t struct {
Dev uint64
Ino uint64
Filetype uint8
Nlink uint64
Size uint64
Atime uint64
Mtime uint64
Ctime uint64
}
26 changes: 26 additions & 0 deletions runtime/internal/clite/syscall/syscall_js.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2018 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.

//go:build js && wasm

package syscall

type Stat_t struct {
Dev int64
Ino uint64
Mode uint32
Nlink uint32
Uid uint32
Gid uint32
Rdev int64
Size int64
Blksize int32
Blocks int32
Atime int64
AtimeNsec int64
Mtime int64
MtimeNsec int64
Ctime int64
CtimeNsec int64
}
45 changes: 45 additions & 0 deletions runtime/internal/lib/os/stat_js.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2009 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.

//go:build js && wasm

package os

import (
"time"

"github.com/goplus/llgo/runtime/internal/clite/syscall"
)

func fillFileStatFromSys(fs *fileStat, name string) {
fs.name = basename(name)
fs.size = fs.sys.Size
fs.modTime = time.Unix(fs.sys.Mtime, fs.sys.MtimeNsec)
fs.mode = FileMode(fs.sys.Mode & 0777)
switch fs.sys.Mode & syscall.S_IFMT {
case syscall.S_IFBLK:
fs.mode |= ModeDevice
case syscall.S_IFCHR:
fs.mode |= ModeDevice | ModeCharDevice
case syscall.S_IFDIR:
fs.mode |= ModeDir
case syscall.S_IFIFO:
fs.mode |= ModeNamedPipe
case syscall.S_IFLNK:
fs.mode |= ModeSymlink
case syscall.S_IFREG:
// nothing to do
case syscall.S_IFSOCK:
fs.mode |= ModeSocket
}
if fs.sys.Mode&syscall.S_ISGID != 0 {
fs.mode |= ModeSetgid
}
if fs.sys.Mode&syscall.S_ISUID != 0 {
fs.mode |= ModeSetuid
}
if fs.sys.Mode&syscall.S_ISVTX != 0 {
fs.mode |= ModeSticky
}
}
43 changes: 43 additions & 0 deletions runtime/internal/lib/os/stat_wasip1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2023 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.

//go:build wasip1

package os

import (
"time"

"github.com/goplus/llgo/runtime/internal/clite/syscall"
)

func fillFileStatFromSys(fs *fileStat, name string) {
fs.name = basename(name)
fs.size = int64(fs.sys.Size)
fs.modTime = time.Unix(0, int64(fs.sys.Mtime))

switch fs.sys.Filetype {
case syscall.FILETYPE_BLOCK_DEVICE:
fs.mode |= ModeDevice
case syscall.FILETYPE_CHARACTER_DEVICE:
fs.mode |= ModeDevice | ModeCharDevice
case syscall.FILETYPE_DIRECTORY:
fs.mode |= ModeDir
case syscall.FILETYPE_SOCKET_DGRAM:
fs.mode |= ModeSocket
case syscall.FILETYPE_SOCKET_STREAM:
fs.mode |= ModeSocket
case syscall.FILETYPE_SYMBOLIC_LINK:
fs.mode |= ModeSymlink
}

// WASI does not support unix-like permissions, but Go programs are likely
// to expect the permission bits to not be zero so we set defaults to help
// avoid breaking applications that are migrating to WASM.
if fs.sys.Filetype == syscall.FILETYPE_DIRECTORY {
fs.mode |= 0700
} else {
fs.mode |= 0600
}
}
Loading