syscall: Stat_t for js/wasip1
This commit is contained in:
24
runtime/internal/clite/syscall/fs_wasip1.go
Normal file
24
runtime/internal/clite/syscall/fs_wasip1.go
Normal file
@@ -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
|
||||
}
|
||||
@@ -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
runtime/internal/clite/syscall/syscall_js.go
Normal file
26
runtime/internal/clite/syscall/syscall_js.go
Normal file
@@ -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
runtime/internal/lib/os/stat_js.go
Normal file
45
runtime/internal/lib/os/stat_js.go
Normal file
@@ -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
runtime/internal/lib/os/stat_wasip1.go
Normal file
43
runtime/internal/lib/os/stat_wasip1.go
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user