From 04d2b722484839cc882d11cbac2b17319f20fcda Mon Sep 17 00:00:00 2001 From: Ernest Wong Date: Sun, 18 Nov 2018 23:20:31 +1300 Subject: [PATCH] 9p: Simplify read - OpenInode is not asynchronous --- lib/9p.js | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/lib/9p.js b/lib/9p.js index 05f6c66b..7a77c962 100644 --- a/lib/9p.js +++ b/lib/9p.js @@ -591,37 +591,33 @@ Virtio9p.prototype.ReceiveRequest = async function (bufchain) { // jshint ignore this.SendReply(bufchain); } else { this.fs.OpenInode(this.fids[fid].inodeid, undefined); - this.fs.AddEvent(this.fids[fid].inodeid, - async function() { // jshint ignore:line - const inodeid = this.fids[fid].inodeid; + const inodeid = this.fids[fid].inodeid; - if (inode.size < offset+count) count = inode.size - offset; - else if(id == 40) - { - // for directories, return whole number of dir-entries. - count = this.fs.RoundToDirentry(inodeid, offset + count) - offset; - } - if(offset > inode.size) - { - // offset can be greater than available - should return count of zero. - // See http://ericvh.github.io/9p-rfc/rfc9p2000.html#anchor30 - count = 0; - } + if (inode.size < offset+count) count = inode.size - offset; + else if(id == 40) + { + // for directories, return whole number of dir-entries. + count = this.fs.RoundToDirentry(inodeid, offset + count) - offset; + } + if(offset > inode.size) + { + // offset can be greater than available - should return count of zero. + // See http://ericvh.github.io/9p-rfc/rfc9p2000.html#anchor30 + count = 0; + } - this.bus.send("9p-read-start", [this.fids[fid].dbg_name]); + this.bus.send("9p-read-start", [this.fids[fid].dbg_name]); - const data = await this.fs.Read(inodeid, offset, count); // jshint ignore:line + const data = await this.fs.Read(inodeid, offset, count); // jshint ignore:line - this.bus.send("9p-read-end", [this.fids[fid].dbg_name, count]); + this.bus.send("9p-read-end", [this.fids[fid].dbg_name, count]); - if(data) { - this.replybuffer.set(data, 7 + 4); - } - marshall.Marshall(["w"], [count], this.replybuffer, 7); - this.BuildReply(id, tag, 4 + count); - this.SendReply(bufchain); - }.bind(this) // jshint ignore:line - ); // jshint ignore:line + if(data) { + this.replybuffer.set(data, 7 + 4); + } + marshall.Marshall(["w"], [count], this.replybuffer, 7); + this.BuildReply(id, tag, 4 + count); + this.SendReply(bufchain); } break;