File FileDescriptor.h

Defines

WASI_RIGHTS_WRITE
WASI_RIGHTS_READ
DEFAULT_ROOT_FD
namespace storage

Enums

enum OpenMode

Values:

enumerator CREATE
enumerator DIRECTORY
enumerator EXCL
enumerator TRUNC
enumerator NONE
enum ReadWriteType

Values:

enumerator READ_ONLY
enumerator READ_WRITE
enumerator WRITE_ONLY
enumerator NO_READ_WRITE
enumerator CUSTOM
class DirEnt

Public Members

uint64_t next
uint8_t type
uint64_t ino
std::string path
class FileDescriptor

Public Functions

FileDescriptor() = default
DirEnt iterNext()
bool iterStarted() const
bool iterFinished()
void iterBack()
void iterReset()
size_t copyDirentsToWasiBuffer(uint8_t *buffer, size_t bufferLen)

Note that this function conforms to the standard readdir interface:

  • Copy each dirent struct followed by its path string

  • If the last path string doesn’t fit, return the buffer length

  • If the last dirent doesn’t fit, don’t copy it and return the buffer length

The external libc wrapper should prevent this third point.

If the final dirent or path doesn’t fit, the caller will expect the next result to contain that same dirent/ path, so we have to step back one in the iterator if that’s the case.

The caller knows they’ve reached the end when the buffer is not filled by this call.

Stat stat(const std::string &relativePath = "")
bool unlink(const std::string &relativePath = "")
bool rmdir(const std::string &relativePath = "")
bool rename(const std::string &newPath, const std::string &relativePath = "")
ssize_t readLink(const std::string &relativePath, char *buffer, size_t bufferLen)
bool pathOpen(uint32_t lookupFlags, uint32_t openFlags, int32_t fdFlags)
bool updateFlags(int32_t fdFlags)
ssize_t write(std::vector<::iovec> &nativeIovecs, int iovecCount)
void close() const
bool mkdir(const std::string &dirPath)
uint16_t seek(int64_t offset, int wasiWhence, uint64_t *newOffset) const
uint64_t tell() const
int getLinuxFd() const
int getLinuxFlags() const
int getLinuxErrno() const
uint16_t getWasiErrno() const
uint64_t getActualRightsBase() const
uint64_t getActualRightsInheriting() const
void setActualRights(uint64_t rights, uint64_t inheriting)
std::string absPath(const std::string &relativePath)
void setPath(const std::string &newPath)
std::string getPath()
int duplicate(const FileDescriptor &other)

Public Members

uint8_t wasiPreopenType

Public Static Functions

static FileDescriptor stdinFactory()
static FileDescriptor stdoutFactory()
static FileDescriptor stderrFactory()

Private Functions

void loadDirContents()

Private Members

std::string path
bool rightsSet = false
uint64_t actualRightsBase
uint64_t actualRightsInheriting
int linuxFd = -1
int linuxMode = -1
int linuxFlags = -1
int linuxErrno = 0
uint16_t wasiErrno = 0
bool dirContentsLoaded = false
std::vector<DirEnt> dirContents
int dirContentsIdx = 0

Private Static Functions

static FileDescriptor stdFdFactory(int stdFd, const std::string &devPath)
class Stat

Public Members

bool failed
uint16_t wasiErrno
uint8_t wasiFiletype
uint64_t st_dev
uint64_t st_ino
uint64_t st_nlink
uint64_t st_size
uint32_t st_mode
uint64_t st_atim
uint64_t st_mtim
uint64_t st_ctim