diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-08-02 11:22:20 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-08-02 11:22:20 -0700 |
commit | afc5f4c379d036394345728a03b264fa0dca64d3 (patch) | |
tree | 97a89efe7cb92f02edc4cca1e9dd5b9119a8d422 /src/library.js | |
parent | dce5bea0af112159cc62617ca9efe213522a6e51 (diff) | |
parent | bbde98b8ca02d21412b33f9f348f4cec622dd3f8 (diff) |
Merge pull request #1457 from inolen/fs_init_split
split up FS.init
Diffstat (limited to 'src/library.js')
-rw-r--r-- | src/library.js | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/src/library.js b/src/library.js index 143d7c28..7978e9cb 100644 --- a/src/library.js +++ b/src/library.js @@ -29,7 +29,8 @@ LibraryManager.library = { _impure_ptr: 'allocate(1, "i32*", ALLOC_STATIC)', $FS__deps: ['$ERRNO_CODES', '__setErrNo', 'stdin', 'stdout', 'stderr', '_impure_ptr'], - $FS__postset: '__ATINIT__.unshift({ func: function() { if (!Module["noFSInit"] && !FS.init.initialized) FS.init() } });' + + $FS__postset: 'FS.staticInit();' + + '__ATINIT__.unshift({ func: function() { if (!Module["noFSInit"] && !FS.init.initialized) FS.init() } });' + '__ATMAIN__.push({ func: function() { FS.ignorePermissions = false } });' + '__ATEXIT__.push({ func: function() { FS.quit() } });' + // export some names through closure @@ -223,7 +224,6 @@ LibraryManager.library = { // set to true and the object is a symbolic link, it will be returned as is // instead of being resolved. Links embedded in the path are still resolved. findObject: function(path, dontResolveLastLink) { - FS.ensureRoot(); var ret = FS.analyzePath(path, dontResolveLastLink); if (ret.exists) { return ret.object; @@ -509,8 +509,7 @@ LibraryManager.library = { if (!success) ___setErrNo(ERRNO_CODES.EIO); return success; }, - ensureRoot: function() { - if (FS.root) return; + staticInit: function () { // The main file system tree. All the contents are inside this. FS.root = { read: true, @@ -521,6 +520,11 @@ LibraryManager.library = { inodeNumber: 1, contents: {} }; + // Create the temporary folder, if not already created + try { + FS.createFolder('/', 'tmp', true, true); + } catch(e) {} + FS.createFolder('/', 'dev', true, true); }, // Initializes the filesystems with stdin/stdout/stderr devices, given // optional handlers. @@ -529,8 +533,6 @@ LibraryManager.library = { assert(!FS.init.initialized, 'FS.init was previously called. If you want to initialize later with custom parameters, remove any earlier calls (note that one is automatically added to the generated code)'); FS.init.initialized = true; - FS.ensureRoot(); - // Allow Module.stdin etc. to provide defaults, if none explicitly passed to us here input = input || Module['stdin']; output = output || Module['stdout']; @@ -583,21 +585,15 @@ LibraryManager.library = { if (!error.printer) error.printer = Module['printErr']; if (!error.buffer) error.buffer = []; - // Create the temporary folder, if not already created - try { - FS.createFolder('/', 'tmp', true, true); - } catch(e) {} - // Create the I/O devices. - var devFolder = FS.createFolder('/', 'dev', true, true); - var stdin = FS.createDevice(devFolder, 'stdin', input); + var stdin = FS.createDevice('/dev', 'stdin', input); stdin.isTerminal = !stdinOverridden; - var stdout = FS.createDevice(devFolder, 'stdout', null, output); + var stdout = FS.createDevice('/dev', 'stdout', null, output); stdout.isTerminal = !stdoutOverridden; - var stderr = FS.createDevice(devFolder, 'stderr', null, error); + var stderr = FS.createDevice('/dev', 'stderr', null, error); stderr.isTerminal = !stderrOverridden; - FS.createDevice(devFolder, 'tty', input, output); - FS.createDevice(devFolder, 'null', function(){}, function(){}); + FS.createDevice('/dev', 'tty', input, output); + FS.createDevice('/dev', 'null', function(){}, function(){}); // Create default streams. FS.streams[1] = { |