mirror of
https://github.com/copy/v86.git
synced 2025-12-31 04:23:15 +00:00
fs: remove AddEvent/HandleEvent, make await OpenInode instead
This commit is contained in:
parent
5aeac32af3
commit
007b0d9e71
2 changed files with 11 additions and 52 deletions
24
lib/9p.js
24
lib/9p.js
|
|
@ -322,21 +322,15 @@ Virtio9p.prototype.ReceiveRequest = async function (bufchain) {
|
|||
dbg_log("[open] fid=" + fid + ", mode=" + mode, LOG_9P);
|
||||
var idx = this.fids[fid].inodeid;
|
||||
var inode = this.fs.GetInode(idx);
|
||||
dbg_log("file open " + this.fids[fid].dbg_name, LOG_9P);
|
||||
//if (inode.status === STATUS_LOADING) return;
|
||||
var ret = this.fs.OpenInode(idx, mode);
|
||||
dbg_log("file open " + this.fids[fid].dbg_name + " tag:"+tag, LOG_9P);
|
||||
await this.fs.OpenInode(idx, mode);
|
||||
|
||||
this.fs.AddEvent(this.fids[fid].inodeid,
|
||||
function() {
|
||||
dbg_log("file opened " + this.fids[fid].dbg_name + " tag:"+tag, LOG_9P);
|
||||
var req = [];
|
||||
req[0] = inode.qid;
|
||||
req[1] = this.msize - 24;
|
||||
marshall.Marshall(["Q", "w"], req, this.replybuffer, 7);
|
||||
this.BuildReply(id, tag, 13+4);
|
||||
this.SendReply(bufchain);
|
||||
}.bind(this)
|
||||
);
|
||||
req = [];
|
||||
req[0] = inode.qid;
|
||||
req[1] = this.msize - 24;
|
||||
marshall.Marshall(["Q", "w"], req, this.replybuffer, 7);
|
||||
this.BuildReply(id, tag, 13+4);
|
||||
this.SendReply(bufchain);
|
||||
break;
|
||||
|
||||
case 70: // link
|
||||
|
|
@ -621,7 +615,7 @@ Virtio9p.prototype.ReceiveRequest = async function (bufchain) {
|
|||
this.BuildReply(id, tag, 4 + count);
|
||||
this.SendReply(bufchain);
|
||||
} else {
|
||||
this.fs.OpenInode(this.fids[fid].inodeid, undefined);
|
||||
await this.fs.OpenInode(this.fids[fid].inodeid, undefined);
|
||||
const inodeid = this.fids[fid].inodeid;
|
||||
|
||||
count = Math.min(count, this.replybuffer.length - (7 + 4));
|
||||
|
|
|
|||
|
|
@ -62,7 +62,6 @@ const texten = new TextEncoder();
|
|||
export function FS(storage, qidcounter) {
|
||||
/** @type {Array.<!Inode>} */
|
||||
this.inodes = [];
|
||||
this.events = [];
|
||||
|
||||
this.storage = storage;
|
||||
|
||||
|
|
@ -139,39 +138,6 @@ FS.prototype.set_state = function(state)
|
|||
|
||||
// -----------------------------------------------------
|
||||
|
||||
FS.prototype.AddEvent = function(id, OnEvent) {
|
||||
var inode = this.inodes[id];
|
||||
if(inode.status === STATUS_OK || inode.status === STATUS_ON_STORAGE) {
|
||||
OnEvent();
|
||||
}
|
||||
else if(this.is_forwarder(inode))
|
||||
{
|
||||
this.follow_fs(inode).AddEvent(inode.foreign_id, OnEvent);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.events.push({id: id, OnEvent: OnEvent});
|
||||
}
|
||||
};
|
||||
|
||||
FS.prototype.HandleEvent = function(id) {
|
||||
const inode = this.inodes[id];
|
||||
if(this.is_forwarder(inode))
|
||||
{
|
||||
this.follow_fs(inode).HandleEvent(inode.foreign_id);
|
||||
}
|
||||
//dbg_log("number of events: " + this.events.length, LOG_9P);
|
||||
var newevents = [];
|
||||
for(var i=0; i<this.events.length; i++) {
|
||||
if(this.events[i].id === id) {
|
||||
this.events[i].OnEvent();
|
||||
} else {
|
||||
newevents.push(this.events[i]);
|
||||
}
|
||||
}
|
||||
this.events = newevents;
|
||||
};
|
||||
|
||||
FS.prototype.load_from_json = function(fs)
|
||||
{
|
||||
dbg_assert(fs, "Invalid fs passed to load_from_json");
|
||||
|
|
@ -695,11 +661,11 @@ FS.prototype.CreateBinaryFile = async function(filename, parentid, buffer) {
|
|||
};
|
||||
|
||||
|
||||
FS.prototype.OpenInode = function(id, mode) {
|
||||
FS.prototype.OpenInode = async function(id, mode) {
|
||||
var inode = this.inodes[id];
|
||||
if(this.is_forwarder(inode))
|
||||
{
|
||||
return this.follow_fs(inode).OpenInode(inode.foreign_id, mode);
|
||||
return await this.follow_fs(inode).OpenInode(inode.foreign_id, mode);
|
||||
}
|
||||
if((inode.mode&S_IFMT) === S_IFDIR) {
|
||||
this.FillDirectory(id);
|
||||
|
|
@ -714,7 +680,6 @@ FS.prototype.OpenInode = function(id, mode) {
|
|||
}
|
||||
*/
|
||||
//dbg_log("open:" + this.GetFullPath(id) + " type: " + inode.mode + " status:" + inode.status, LOG_9P);
|
||||
return true;
|
||||
};
|
||||
|
||||
FS.prototype.CloseInode = async function(id) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue