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

read_file returns null for empty file #659

Open
stasoid opened this issue May 22, 2022 · 1 comment
Open

read_file returns null for empty file #659

stasoid opened this issue May 22, 2022 · 1 comment
Labels

Comments

@stasoid
Copy link
Contributor

stasoid commented May 22, 2022

If an empty file is created by a command, FS.read_file returns null instead of empty Uint8Array. Empty files created by create_file doesn't have this issue.

This happens because of this line in get_data, but I don't know if it can be changed to return new Uint8Array. There is similar code in get_buffer, which also claims to @return {!Promise<Uint8Array>}.

How to reproduce: execute command touch /mnt/f in the following VM, then press read f button. Result: null is printed to js console.

<!doctype html>
<script src="../build/libv86.js"></script>

<script>
onload = function()
{
	emulator = new V86Starter({
		wasm_path:  "../build/v86.wasm",
		bios:       { url: "../bios/seabios.bin" },
		vga_bios:   { url: "../bios/vgabios.bin" },
		bzimage:    { url: "../images/buildroot-bzimage.bin" },
		filesystem: {},
		screen_container: screen_container,
		autostart: true
	});
}
async function read_f()
{
	let data = await emulator.fs9p.read_file("f");
	console.log(data);
}
</script>

<!-- A minimal structure for the ScreenAdapter defined in browser/screen.js -->
<div id=screen_container>
	<div style="white-space: pre; font: 14px monospace"></div>
	<canvas></canvas>
</div>

<button onclick="read_f()">read f</button>
@copy
Copy link
Owner

copy commented May 23, 2022

This happens because of this line in get_data, but I don't know if it can be changed to return new Uint8Array. There is similar code in get_buffer, which also claims to @return {!Promise}.

I don't think it can be changed to return new Uint8Array, since that would be returned for non-existing files. Rather, CreateFile should ensure that inodedata is set (similar Linux's behavious, where close(open(..., O_CREAT)) creates an empty file).

A PR (with a test case showing the current incorrect behaviour, see https://github.com/copy/v86/blob/master/tests/devices/virtio_9p.js) would be welcome.

@copy copy added the bug label Jun 3, 2022
@copy copy mentioned this issue Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants