diff --git a/lib/filesystem.js b/lib/filesystem.js index 256d4a03..f32d95c8 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -333,7 +333,6 @@ function Inode(qidnumber) }; this.caps = undefined; this.nlinks = 1; - this.dirent_offsets = undefined; //this.qid_type = 0; //this.qid_version = 0; @@ -365,7 +364,6 @@ Inode.prototype.get_state = function() state[19] = this.qid.path; state[20] = this.caps; state[21] = this.nlinks; - state[22] = this.dirent_offsets; return state; }; @@ -393,7 +391,6 @@ Inode.prototype.set_state = function(state) this.qid.path = state[19]; this.caps = state[20]; this.nlinks = state[21]; - this.dirent_offsets = state[22]; }; FS.prototype.CreateInode = function() { @@ -825,8 +822,6 @@ FS.prototype.FillDirectory = function(dirid) { inode.size = size; var offset = 0x0; - inode.dirent_offsets = [offset]; - offset += marshall.Marshall( ["Q", "d", "b", "s"], [this.inodes[dirid].qid, @@ -834,7 +829,6 @@ FS.prototype.FillDirectory = function(dirid) { this.inodes[dirid].mode >> 12, "."], data, offset); - inode.dirent_offsets.push(offset); offset += marshall.Marshall( ["Q", "d", "b", "s"], @@ -843,7 +837,6 @@ FS.prototype.FillDirectory = function(dirid) { this.inodes[parentid].mode >> 12, ".."], data, offset); - inode.dirent_offsets.push(offset); id = this.inodes[dirid].firstid; while(id != -1) { @@ -854,7 +847,6 @@ FS.prototype.FillDirectory = function(dirid) { this.inodes[id].mode >> 12, this.inodes[id].name], data, offset); - this.inodes[dirid].dirent_offsets.push(offset); id = this.inodes[id].nextid; } inode.updatedir = false; @@ -862,19 +854,24 @@ FS.prototype.FillDirectory = function(dirid) { FS.prototype.RoundToDirentry = function(dirid, offset_target) { - const offsets = this.GetInode(dirid).dirent_offsets; + const data = this.inodedata[dirid]; + dbg_assert(data, `FS directory data for dirid=${dirid} should be generated`); + dbg_assert(data.length, "FS directory should have at least an entry"); - dbg_assert(offsets, "9P direntry offsets should be cached"); - dbg_assert(offsets[0] === 0, "9P first direntry offset should be zero"); - dbg_assert(offset_target >= 0, "9P RoundToDirentry target offset should be non-negative"); - - let i = 0; - while(offsets[i] <= offset_target) + if(offset_target >= data.length) { - i++; + return data.length; } - return offsets[i - 1]; + let offset = 0; + while(true) + { + const next_offset = marshall.Unmarshall(["Q", "d"], data, { offset })[1]; + if(next_offset > offset_target) break; + offset = next_offset; + } + + return offset; }; diff --git a/lib/marshall.js b/lib/marshall.js index 1b3267d0..89a56681 100644 --- a/lib/marshall.js +++ b/lib/marshall.js @@ -111,6 +111,16 @@ marshall.Unmarshall = function(typelist, struct, state) { } output.push(str); break; + case "Q": + state.offset = offset; + const qid = marshall.Unmarshall(["b", "w", "d"], struct, state); + offset = state.offset; + output.push({ + type: qid[0], + version: qid[1], + path: qid[2], + }); + break; default: message.Debug("Error in Unmarshall: Unknown type=" + typelist[i]); break;