Skip to content

Mount root fs via NODEFS - #3152

Closed
coolwanglu wants to merge 2 commits into
emscripten-core:incomingfrom
coolwanglu:node-webkit
Closed

coolwanglu wants to merge 2 commits into
emscripten-core:incomingfrom
coolwanglu:node-webkit

Conversation

@coolwanglu

Copy link
Copy Markdown
Contributor

See also #2040.

This WIP patch introduces a new option Module['MOUNT_ROOT_NODEFS'], which allows the js file to mount the real filesystem into the emscripten user-space via node.js

An immediate use case is adapting the output of emscripten into frameworks like node-webkit, which allows a complete environment for web native apps.

Currently standard streams /dev/std{in,out,err} do not work. I'm not quite familiar with the implementation of fs in nodes.js, and here are my observations.

fs.writeFileSync('/dev/stdout', 'hello') does not work in node.js, where I got an ENXIO error, maybe because /dev/stdout is a special device.
fs.writeSync(1, 'hello') does work.
ofstream fout('/dev/stdout'); fout << "hello"; does work in C++ -- not sure if this is undefined behavior, as some says that opening standard streams is undefined behavior.

Some ideas of making standard streams work:

  • To manually create streams (via FS.createStream and TTY) and store the fd's to FS
    • The program may use STDOUT, but not /dev/stdout
  • To mount all the subdirs under '/' except for '/dev'
    • Needs extra efforts to make them sync
  • To mount the root into a dir (e.g. '/nodefs_root'), and add that prefix to all the open() calls
  • To take special care of /dev/std* in FS, i.e., to create our own /dev/std* devices even when / is mounted from NODEFS

None of them seems elegant thought...

So I would like to know whether if this would be interesting to emscripten. And if there are better ideas than hacking FS/NODEFS to support standard streams.

@coolwanglu coolwanglu changed the title Node webkit Mount root fs via NODEFS Jan 26, 2015
@coolwanglu

Copy link
Copy Markdown
Contributor Author

Can we do something like this?

FS.mount(NODEFS, {root: '/'}, '/');
FS.mount(MEMFS, {}, '/dev');
FS.createStandardStreams();

@coolwanglu

Copy link
Copy Markdown
Contributor Author

@kripken what do you think about this?

@kripken

kripken commented Jan 29, 2015

Copy link
Copy Markdown
Member

Hmm, does this just allow the root to be mounted using node, as opposed to a subdirectory? Is there a significant benefit to allowing that?

@inolen

inolen commented Jan 30, 2015

Copy link
Copy Markdown
Collaborator

Devices are actually why that support was never added.

@coolwanglu

Copy link
Copy Markdown
Contributor Author

@kripken It could be just easier to mount everything, in order to access everything. Or do you suggest 'to mount all the subdirs in the root except for /dev' ?

@kripken

kripken commented Feb 3, 2015

Copy link
Copy Markdown
Member

It seems potentially confusing if we only mount some things (not devices). And it doesn't seem so bad to mount the real filesystem under a subdir. Overall I am inclined to think that this is unnecessary complexity.

@coolwanglu

Copy link
Copy Markdown
Contributor Author

OK I see. :)

@coolwanglu coolwanglu closed this Feb 3, 2015
@TooTallNate

Copy link
Copy Markdown

@kripken Do you have a recommendation for transpiling C cli apps that allow a user-supplied filename to be accessed? Mapping to the same filesystem would be a lot more convenient than changing the C code in all the places where the file is accessed to add the /root prefix.

@kripken

kripken commented Jun 21, 2016 •

Copy link
Copy Markdown
Member

How about setting the user-supplied filename to subdir/file and then mounting the filesystem on subdir?

@TooTallNate

Copy link
Copy Markdown

I was hoping to not have to modify the source code so much. I'm compiling a 3rd party CLI program to JS and not knowing the internals of the code, and having Emscripten "just work" in this case seems like it would be a worthwhile feature.

But from what I gather this project is more focused on the browser side of things then the terminal / Node.js, so I understand that it's not much of a priority at this time.

@saschanaz

Copy link
Copy Markdown
Collaborator

Just opened #5266 to discuss about this.

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

Successfully merging this pull request may close these issues.

5 participants