Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fstat fails on mounted memory filesystem #111

Open
lambdageek opened this issue Aug 2, 2023 · 0 comments
Open

fstat fails on mounted memory filesystem #111

lambdageek opened this issue Aug 2, 2023 · 0 comments

Comments

@lambdageek
Copy link
Member

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:

const DirectoryOnlyBaseRights: rights = DirectoryBaseRights & ~FileBaseRights;
const FileOnlyBaseRights: rights = FileBaseRights & DirectoryBaseRights;

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

lambdageek added a commit to lambdageek/MSBuildStructuredLog that referenced this issue Aug 2, 2023
nothing is read after the first int32.

trying to use a separate pipe doesn't work because .NET wants to FStat, but
vscode-wasm has a bug with
mountpoint directories having bad permissions
microsoft/vscode-wasm#111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant