aboutsummaryrefslogtreecommitdiff
path: root/src/library_fs.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/library_fs.js')
-rw-r--r--src/library_fs.js49
1 files changed, 31 insertions, 18 deletions
diff --git a/src/library_fs.js b/src/library_fs.js
index 9c83fcad..9d1f0cfd 100644
--- a/src/library_fs.js
+++ b/src/library_fs.js
@@ -18,7 +18,7 @@ mergeInto(LibraryManager.library, {
devices: [null],
streams: [null],
nextInode: 1,
- name_table: new Array(4096),
+ name_table: null,
currentPath: '/',
initialized: false,
// Whether we are currently ignoring permissions. Useful when preparing the
@@ -27,16 +27,21 @@ mergeInto(LibraryManager.library, {
// to modify the filesystem freely before run() is called.
ignorePermissions: true,
- ErrnoError: function(errno) {
- this.errno = errno;
- for (var key in ERRNO_CODES) {
- if (ERRNO_CODES[key] === errno) {
- this.code = key;
- break;
+ ErrnoError: (function() {
+ function ErrnoError(errno) {
+ this.errno = errno;
+ for (var key in ERRNO_CODES) {
+ if (ERRNO_CODES[key] === errno) {
+ this.code = key;
+ break;
+ }
}
- }
- this.message = ERRNO_MESSAGES[errno] + ' : ' + new Error().stack;
- },
+ this.message = ERRNO_MESSAGES[errno];
+ };
+ ErrnoError.prototype = new Error();
+ ErrnoError.prototype.constructor = ErrnoError;
+ return ErrnoError;
+ }()),
handleFSError: function(e) {
if (!(e instanceof FS.ErrnoError)) throw e + ' : ' + new Error().stack;
@@ -51,7 +56,7 @@ mergeInto(LibraryManager.library, {
for (var i = 0; i < name.length; i++) {
hash = ((hash << 5) - hash + name.charCodeAt(i)) | 0;
}
- return (parentid + hash) % FS.name_table.length;
+ return ((parentid + hash) >>> 0) % FS.name_table.length;
},
hashAddNode: function(node) {
var hash = FS.hashName(node.parent.id, node.name);
@@ -730,6 +735,9 @@ mergeInto(LibraryManager.library, {
});
// use a custom read function
stream_ops.read = function(stream, buffer, offset, length, position) {
+ if (!FS.forceLoadFile(node)) {
+ throw new FS.ErrnoError(ERRNO_CODES.EIO);
+ }
var contents = stream.node.contents;
var size = Math.min(contents.length - position, length);
if (contents.slice) { // normal array
@@ -860,6 +868,8 @@ mergeInto(LibraryManager.library, {
assert(stderr.fd === 3, 'invalid handle for stderr (' + stderr.fd + ')');
},
staticInit: function() {
+ FS.name_table = new Array(4096);
+
FS.root = FS.createNode(null, '/', {{{ cDefine('S_IFDIR') }}} | 0777, 0);
FS.mount(MEMFS, {}, '/');
@@ -1035,7 +1045,7 @@ mergeInto(LibraryManager.library, {
FS.hashRemoveNode(old_node);
// do the underlying fs rename
try {
- old_node.node_ops.rename(old_node, new_dir, new_name);
+ old_dir.node_ops.rename(old_node, new_dir, new_name);
} catch (e) {
throw e;
} finally {
@@ -1062,6 +1072,14 @@ mergeInto(LibraryManager.library, {
parent.node_ops.rmdir(parent, name);
FS.destroyNode(node);
},
+ readdir: function(path) {
+ var lookup = FS.lookupPath(path, { follow: true });
+ var node = lookup.node;
+ if (!node.node_ops.readdir) {
+ throw new FS.ErrnoError(ERRNO_CODES.ENOTDIR);
+ }
+ return node.node_ops.readdir(node);
+ },
unlink: function(path) {
var lookup = FS.lookupPath(path, { parent: true });
var parent = lookup.node;
@@ -1202,6 +1220,7 @@ mergeInto(LibraryManager.library, {
open: function(path, flags, mode, fd_start, fd_end) {
path = PATH.normalize(path);
flags = typeof flags === 'string' ? FS.modeStringToFlags(flags) : flags;
+ mode = typeof mode === 'undefined' ? 0666 : mode;
if ((flags & {{{ cDefine('O_CREAT') }}})) {
mode = (mode & {{{ cDefine('S_IALLUGO') }}}) | {{{ cDefine('S_IFREG') }}};
} else {
@@ -1280,12 +1299,6 @@ mergeInto(LibraryManager.library, {
}
return stream.stream_ops.llseek(stream, offset, whence);
},
- readdir: function(stream) {
- if (!stream.stream_ops.readdir) {
- throw new FS.ErrnoError(ERRNO_CODES.ENOTDIR);
- }
- return stream.stream_ops.readdir(stream);
- },
read: function(stream, buffer, offset, length, position) {
if (length < 0 || position < 0) {
throw new FS.ErrnoError(ERRNO_CODES.EINVAL);