• Stars
    star
    140
  • Rank 252,034 (Top 6 %)
  • Language
  • Created almost 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Filesystem API for WASI

WASI filesystem

A proposed WebAssembly System Interface API.

Current Phase

WASI-filesystem is currently in Phase 2.

Champions

  • Dan Gohman

Phase 4 Advancement Criteria

WASI filesystem must have host implementations which can pass the testsuite on at least Windows, macOS, and Linux.

WASI filesystem must have at least two complete independent implementations.

Table of Contents

Introduction

WASI filesystem is a WASI API primarily for accessing host filesystems. It has function for opening, reading, and writing files, and for working with directories.

Unlike many filesystem APIs, WASI filesystem is capability-oriented. Instead of having functions that implicitly reference a filesystem namespace, WASI filesystems' APIs are passed a directory handle along with a path, and the path is looked up relative to the given handle, and sandboxed to be resolved within that directory.

WASI filesystem hides some of the surface differences between Windows and Unix-style filesystems, however much of its behavior, indluding the semantics of path lookup, and the semantics of files, directories, and symlinks, and the constraints on filesystem paths, is host-dependent.

WASI filesystem is not intended to be used as a virtual API for accessing arbitary resources. Unix's "everything is a file" philosophy is in conflict with the goals of supporting modularity and the principle of least authority.

Many of the ideas related to doing capability-based filesystem sandboxing with openat come from CloudABI and Capsicum.

Goals

The primary goal of WASI filesystem is to allow users to use WASI programs to access their existing filesystems in a straightforward and efficient manner.

Non-goals

WASI filesystem is not aiming for deterministic semantics. That would either require restricting it to fully controlled private filesystems, which would conflict with the goal of giving users access to their existing filesystems, or requiring implementations to do a lot of extra work to emulate specific defined behaviors, which would conflict with the goal of being efficient.

API walk-through

Opening a file

/// Write "Hello, World" into a file called "greeting.txt" in `dir`.
fn write_hello_world_to_a_file(dir: Descriptor) -> Result<(), Errno> {
    let at_flags = AtFlags::FollowSymlinks;
    let o_flags = OFlags::Create | OFlags::Trunc;
    let descriptor_flags = DescriptorFlags::Write;
    let mode = Mode::Readable;
    let file =
        dir.openat(at_flags, "greeting.txt", o_flags, descriptor_flags, mode)?;
    let message = b"Hello, World\n";
    let mut view = &message[..];
    let mut offset = 0;
    while !view.is_empty() {
        let num_written = file.pwrite(view.to_owned(), 0)?;
        offset += num_written;
        view = &view[num_writen..];
    }
    // The file descriptor is closed when it's dropped!
}

Perhaps the biggest change from the preview1 version of openat, called path_open, is the removal of the rights flags. Preview1 associates a set of flags with every file descriptor enumerating which operatings may be performed on it, such as reading, writing, appending, truncating, and many other operations. In practice, this created a lot of ambiguity about how it mapped to POSIX semantics, as it doesn't directly correspond to any feature in POSIX, or in Windows either.

The other major change from preview1 is the introduction of the mode argument, which controls the permissions of the generated file. There was no way to control permissions in preview1, so this is new functionality.

Streaming read from a file

TODO

Reading from a directory

fn read_entries(dir: Descriptor) -> Result<(), Errno> { // TODO: Implement this example. }

[etc.

Detailed design discussion

Should WASI filesystem be case-sensitive, case-insensitive, or platform-dependent?

Even just among popular platforms, there are case-sensitive and case-insensitive filesystems in wide use.

It would be nice to have an API which presented consistent behavior across platforms, so that applications don't have to worry about subtle differences, and subtle bugs due to those differences.

However, implementing case sensitivity on a case-insensitive filesystem, or case-insensitivity on a case-sensitive filesystem, are both tricky to do.

One issue is that case insensitivity depends on a Unicode version, so the details can differ between different case-insensitive platforms. Another issue is tha WASI filesystem in general can't assume it has exclusive access to the filesystem, so approaches that involve checking for files with names that differ only by case can race with other processes creating new files.

Considered alternatives

Fully deterministic filesystem

The main tradeoff with full determinism is that it makes it difficult to access existing filesystems that the Wasm runtime doesn't have full control over. This proposal is aiming to address use cases where users have existing filesystems they want to access.

Stakeholder Interest & Feedback

TODO before entering Phase 3.

Preview1 has a similar filesystem API, and it's widely exposed in toolchains.

References & acknowledgements

Many thanks for valuable feedback and advice from:

  • [Person 1]
  • [Person 2]
  • [etc.]

More Repositories

1

design

WebAssembly Design Documents
11,261
star
2

binaryen

Optimizer and compiler/toolchain library for WebAssembly
WebAssembly
7,048
star
3

wabt

The WebAssembly Binary Toolkit
C++
6,350
star
4

WASI

WebAssembly System Interface
Rust
4,510
star
5

spec

WebAssembly specification, reference interpreter, and test suite.
WebAssembly
3,061
star
6

wasi-sdk

WASI-enabled WebAssembly C/C++ toolchain
Shell
1,097
star
7

gc

Branch of the spec repo scoped to discussion of GC integration in WebAssembly
WebAssembly
911
star
8

proposals

Tracking WebAssembly proposals
849
star
9

component-model

Repository for design and specification of the Component Model
Python
827
star
10

wasi-libc

WASI libc implementation for WebAssembly
C
784
star
11

interface-types

WebAssembly
640
star
12

threads

Threads and Atomics in WebAssembly
WebAssembly
577
star
13

wasm-c-api

Wasm C API prototype
C++
521
star
14

simd

Branch of the spec repo scoped to discussion of SIMD in WebAssembly
WebAssembly
519
star
15

meetings

WebAssembly meetings (VC or in-person), agendas, and notes
HTML
438
star
16

wasi-nn

Neural Network proposal for WASI
380
star
17

esm-integration

ECMAScript module integration
WebAssembly
341
star
18

wasm-jit-prototype

Standalone VM using LLVM JIT
C++
307
star
19

tool-conventions

Conventions supporting interoperatibility between tools working with WebAssembly.
276
star
20

website

WebAssembly website
CSS
269
star
21

testsuite

Mirror of the spec testsuite
WebAssembly
172
star
22

memory64

Memory with 64-bit indexes
WebAssembly
168
star
23

reference-types

Proposal for adding basic reference types (anyref)
WebAssembly
161
star
24

wasi-crypto

WASI Cryptography API Proposal
Makefile
160
star
25

wasi-sockets

WASI API proposal for managing sockets
Rust
155
star
26

exception-handling

Proposal to add exception handling to WebAssembly
WebAssembly
141
star
27

module-linking

Proposal for allowing modules to define, import and export modules and instances
WebAssembly
119
star
28

multi-memory

Multiple per-module memories for Wasm
WebAssembly
115
star
29

wasi-threads

WebAssembly
111
star
30

wasi-http

108
star
31

tail-call

Proposal to add tail calls to WebAssembly
WebAssembly
106
star
32

wasp

WebAssembly module decoder in C++
C++
105
star
33

stack-switching

A repository for the stack switching proposal.
WebAssembly
105
star
34

debugging

Design documents and discussions about debug support in WebAssembly
98
star
35

wasi-io

I/O Types proposal for WASI
96
star
36

wasmint

Library for interpreting / debugging wasm code
C++
93
star
37

function-references

Proposal for Typed Function References
WebAssembly
91
star
38

bulk-memory-operations

Bulk memory operations
WebAssembly
74
star
39

multi-value

Proposal to add multi-values to WebAssembly
WebAssembly
66
star
40

wasi-testsuite

WASI Testsuite
Rust
45
star
41

waterfall

Build and test bots
44
star
42

flexible-vectors

Vector operations for WebAssembly
WebAssembly
42
star
43

js-types

Proposal for adding type reflection to the JS API
WebAssembly
42
star
44

content-security-policy

WebAssembly
39
star
45

wasi-cloud-core

Rust
39
star
46

js-promise-integration

JavaScript Promise Integration
WebAssembly
37
star
47

relaxed-simd

Relax the strict determinism requirements of SIMD operations.
WebAssembly
36
star
48

wasi-webgpu

36
star
49

JS-BigInt-integration

JavaScript BigInt to WebAssembly i64 integration
WebAssembly
36
star
50

wasi-libc-old

Precursor to WASI libc.
C
35
star
51

stringref

WebAssembly
34
star
52

benchmarks

Resources for collaborative benchmarking
JavaScript
27
star
53

wasi-random

Entropy source API for WASI
25
star
54

wasi-keyvalue

24
star
55

wasi-clocks

Clocks API for WASI
22
star
56

wasi-sql

20
star
57

annotations

Proposal for Custom Annotation Syntax in the Text Format
WebAssembly
19
star
58

proposal-type-imports

Proposal for Type Imports & Exports
WebAssembly
19
star
59

memory-control

A proposal to introduce finer grained control of WebAssembly memory.
WebAssembly
19
star
60

shared-everything-threads

A draft proposal for spawning threads in WebAssembly
WebAssembly
18
star
61

constant-time

Constant-time WebAssembly
WebAssembly
18
star
62

wasi-sql-embed

18
star
63

wasi-proposal-template

Starter template for proposing a new WASI API
17
star
64

wasi-parallel

wasi-parallel is a proposal to add a parallel for construct to WASI.
Shell
17
star
65

sign-extension-ops

Sign-extension opcodes
WebAssembly
17
star
66

funclets

Proposal for adding funclets - flexible intraprocedural control flow
WebAssembly
17
star
67

mutable-global

Import & export of mutable globals
WebAssembly
16
star
68

wasi-tools

WASI tools
Rust
16
star
69

wasi-poll

16
star
70

wasi-messaging

messaging proposal for WASI
15
star
71

wasi-cli

Command-Line Interface (CLI) World for WASI
15
star
72

instrument-tracing

Proposal to add instrumentation and tracing instructions to WebAssembly
WebAssembly
14
star
73

nontrapping-float-to-int-conversions

Proposal to add non-trapping float-to-int conversions to WebAssembly
WebAssembly
14
star
74

extended-const

Proposal for extended constant expressions
WebAssembly
14
star
75

conditional-sections

WebAssembly
13
star
76

wasi-grpc

13
star
77

profiles

Profiles proposal
WebAssembly
12
star
78

wasi-logging

WASI logging API
11
star
79

extended-name-section

WebAssembly
11
star
80

feature-detection

WebAssembly
10
star
81

webassembly.github.io

Redirect to webassembly.org
HTML
10
star
82

wasi-blobstore

10
star
83

wasi-runtime-config

9
star
84

testsuite-js

WebAssembly testsuite tests converted to single-file JavaScript tests
JavaScript
9
star
85

lld

Staging repository for upstreaming WebAssembly support into lld
C++
9
star
86

branch-hinting

Proposal to add branch hinting functionality to WebAssembly
WebAssembly
9
star
87

decompressor-prototype

C++
8
star
88

wasi-observe

Observability World for WASI
Just
8
star
89

wat-numeric-values

Proposal to add numeric values to data segment definitions in the text format
WebAssembly
7
star
90

gc-js-customization

WebAssembly
7
star
91

wasi-classic-command

6
star
92

wasi-url

6
star
93

wasi-i2c

I2C API for WASi
Rust
5
star
94

wg-charter

Proposed WebAssembly Working Group charter
HTML
5
star
95

wit-abi-up-to-date

4
star
96

call-tags

WebAssembly
4
star
97

cg-charter

Proposed WebAssembly Community Group charter
HTML
4
star
98

root-scanning

Spec proposal for scanning/marking of linear memory GC roots
WebAssembly
4
star
99

js-string-builtins

JS String Builtins
WebAssembly
3
star
100

conditional-segment-initialization

Conditional segment initialization
WebAssembly
3
star