github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/poll/fd_wasip1.go (about) 1 // Copyright 2023 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 5 package poll 6 7 import ( 8 "github.com/shogo82148/std/syscall" 9 ) 10 11 type SysFile struct { 12 // RefCountPtr is a pointer to the reference count of Sysfd. 13 // 14 // WASI preview 1 lacks a dup(2) system call. When the os and net packages 15 // need to share a file/socket, instead of duplicating the underlying file 16 // descriptor, we instead provide a way to copy FD instances and manage the 17 // underlying file descriptor with reference counting. 18 RefCountPtr *int32 19 20 // RefCount is the reference count of Sysfd. When a copy of an FD is made, 21 // it points to the reference count of the original FD instance. 22 RefCount int32 23 24 // Cache for the file type, lazily initialized when Seek is called. 25 Filetype uint32 26 27 // If the file represents a directory, this field contains the current 28 // readdir position. It is reset to zero if the program calls Seek(0, 0). 29 Dircookie uint64 30 31 // Absolute path of the file, as returned by syscall.PathOpen; 32 // this is used by Fchdir to emulate setting the current directory 33 // to an open file descriptor. 34 Path string 35 } 36 37 // Copy creates a copy of the FD. 38 // 39 // The FD instance points to the same underlying file descriptor. The file 40 // descriptor isn't closed until all FD instances that refer to it have been 41 // closed/destroyed. 42 func (fd *FD) Copy() FD 43 44 // Fchdir wraps syscall.Fchdir. 45 func (fd *FD) Fchdir() error 46 47 // ReadDir wraps syscall.ReadDir. 48 // We treat this like an ordinary system call rather than a call 49 // that tries to fill the buffer. 50 func (fd *FD) ReadDir(buf []byte, cookie syscall.Dircookie) (int, error) 51 52 func (fd *FD) ReadDirent(buf []byte) (int, error) 53 54 // Seek wraps syscall.Seek. 55 func (fd *FD) Seek(offset int64, whence int) (int64, error)