microsoft / microsoft/vscode-wasm

fstat fails on mounted memory filesystem

Open
#111 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
456
Forks
40
Avg merge
3d 2h
Merged PRs (30d)
4

Description

If I create /pipe/input on the memory file system, calling int fd = open("/pipe/input", O_RDONLY); will succeed, but calling fstat(fd, &stat) will fail with EPERM

			const memFS = await wasm.createMemoryFileSystem();
			const rootFileSystem = await wasm.createRootFileSystem([
				{ kind: 'workspaceFolder' },
				{
					kind: 'memoryFileSystem',
					mountPoint: '/pipe',
					fileSystem: memFS
				},
			]);
			const pipeIn = memFS.createWritable('./input', 'utf-8');
			const seedBuf = new Uint8Array(1);
			seedBuf[0] = 42;
			pipeIn.write(seedBuf);

Repro: clone the "memfs" branch of https://github.com/lambdageek/big-buffer-write/tree/memfs build and run the extension and run it with "wasi: write big buffer". pick a small value from the Quick Pick, like 20.

Note the output in the output window:

2023-08-02 14:17:10.506 [error] stderr: the mode for /pipe is 040000

2023-08-02 14:17:10.506 [error] stderr: fstat input
2023-08-02 14:17:10.506 [error] stderr: :
2023-08-02 14:17:10.507 [error] stderr:  
2023-08-02 14:17:10.507 [error] stderr: Operation not permitted
2023-08-02 14:17:10.507 [error] stderr: 

2023-08-02 14:17:10.507 [error] stderr: that's EPERM

2023-08-02 14:17:10.509 [info] process terminated with exit code 1

Also, FileOnlyBaseRights looks like a typo:

https://github.com/microsoft/vscode-wasm/blob/62adc93b3d67ce09a045e84395171346c13e8a02/wasm-wasi-core/src/common/memoryFileSystemDriver.ts#L241-L242

This should probably be const FileOnlyBaseRights: rights = FileBaseRights & ~DirectoryBaseRights;


Why I care: .NET does an FStatCheckIO after opening a file that ends up failing
https://github.com/dotnet/runtime/blob/e2a2bfff005ea0620cf1d2b04a01dc90bbfe8ead/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs#L334

So FileStream f = File.OpenRead("/pipe/input") always fails

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in wasm-wasi-core/src/common/memoryFileSystemDriver.ts around lines 241-242 and inspect the memory filesystem rights used for files and directories. Reproduce with the linked memfs branch, then verify that opening /pipe/input followed by fstat no longer returns EPERM and that the reported FileOnlyBaseRights definition is addressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, wasm
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.