Decouple 9p and starter from fs's internal structure
Part of changes to support fs mounting on the host side. Inode attributes are generally left untouched as field accesses.
This commit is contained in:
parent
5b5a36d258
commit
9e592dbd84
47
lib/9p.js
47
lib/9p.js
|
@ -249,8 +249,8 @@ Virtio9p.prototype.ReceiveRequest = function (bufchain) {
|
|||
req[2] = Math.floor(space/req[1]); // free blocks, let's say 1GB
|
||||
req[3] = req[2] - Math.floor(size/req[1]); // free blocks in fs
|
||||
req[4] = req[2] - Math.floor(size/req[1]); // free blocks avail to non-superuser
|
||||
req[5] = this.fs.inodes.length; // total number of inodes
|
||||
req[6] = 1024*1024;
|
||||
req[5] = this.fs.CountUsedInodes(); // total number of inodes
|
||||
req[6] = this.fs.CountFreeInodes();
|
||||
req[7] = 0; // file system id?
|
||||
req[8] = 256; // maximum length of filenames
|
||||
|
||||
|
@ -290,26 +290,9 @@ Virtio9p.prototype.ReceiveRequest = function (bufchain) {
|
|||
var fid = req[1];
|
||||
var name = req[2];
|
||||
message.Debug("[link] dfid=" + dfid + ", name=" + name);
|
||||
var inode = this.fs.CreateInode();
|
||||
var inodetarget = this.fs.GetInode(this.fids[fid].inodeid);
|
||||
var targetdata = this.fs.inodedata[this.fids[fid].inodeid];
|
||||
//inode = inodetarget;
|
||||
inode.dirty = true;
|
||||
inode.mode = inodetarget.mode;
|
||||
inode.size = inodetarget.size;
|
||||
inode.symlink = inodetarget.symlink;
|
||||
var data = this.fs.inodedata[this.fs.inodes.length] = new Uint8Array(inode.size);
|
||||
if(targetdata)
|
||||
{
|
||||
data.set(targetdata.subarray(0, inode.size), 0);
|
||||
}
|
||||
inode.name = name;
|
||||
inode.parentid = this.fids[dfid].inodeid;
|
||||
this.fs.PushInode(inode);
|
||||
|
||||
//inode.uid = inodetarget.uid;
|
||||
//inode.gid = inodetarget.gid;
|
||||
//inode.mode = inodetarget.mode | S_IFLNK;
|
||||
|
||||
this.fs.Link(this.fids[fid].inodeid, name, this.fids[dfid].inodeid);
|
||||
|
||||
this.BuildReply(id, tag, 0);
|
||||
this.SendReply(bufchain);
|
||||
break;
|
||||
|
@ -535,13 +518,12 @@ Virtio9p.prototype.ReceiveRequest = function (bufchain) {
|
|||
this.BuildReply(id, tag, 4 + count);
|
||||
this.SendReply(bufchain);
|
||||
} else {
|
||||
var file = this.fs.inodes[this.fids[fid].inodeid];
|
||||
this.bus.send("9p-read-start");
|
||||
|
||||
this.fs.OpenInode(this.fids[fid].inodeid, undefined);
|
||||
this.fs.AddEvent(this.fids[fid].inodeid,
|
||||
function() {
|
||||
this.bus.send("9p-read-end", [file.name, count]);
|
||||
this.bus.send("9p-read-end", [inode.name, count]);
|
||||
|
||||
const inodeid = this.fids[fid].inodeid;
|
||||
|
||||
|
@ -557,9 +539,9 @@ Virtio9p.prototype.ReceiveRequest = function (bufchain) {
|
|||
// See http://ericvh.github.io/9p-rfc/rfc9p2000.html#anchor30
|
||||
count = 0;
|
||||
}
|
||||
var data = this.fs.inodedata[inodeid];
|
||||
const data = this.fs.Read(inodeid, offset, count);
|
||||
if(data) {
|
||||
this.replybuffer.set(data.subarray(offset, offset + count), 7 + 4);
|
||||
this.replybuffer.set(data, 7 + 4);
|
||||
}
|
||||
marshall.Marshall(["w"], [count], this.replybuffer, 7);
|
||||
this.BuildReply(id, tag, 4 + count);
|
||||
|
@ -574,7 +556,9 @@ Virtio9p.prototype.ReceiveRequest = function (bufchain) {
|
|||
var fid = req[0];
|
||||
var offset = req[1];
|
||||
var count = req[2];
|
||||
message.Debug("[write]: fid=" + fid + " (" + this.fs.inodes[this.fids[fid].inodeid].name + ") offset=" + offset + " count=" + count + " fidtype=" + this.fids[fid].type);
|
||||
|
||||
const filename = this.fs.GetInode(this.fids[fid].inodeid).name;
|
||||
message.Debug("[write]: fid=" + fid + " (" + filename + ") offset=" + offset + " count=" + count + " fidtype=" + this.fids[fid].type);
|
||||
if(this.fids[fid].type === FID_XATTR)
|
||||
{
|
||||
// XXX: xattr not supported yet. Ignore write.
|
||||
|
@ -588,8 +572,7 @@ Virtio9p.prototype.ReceiveRequest = function (bufchain) {
|
|||
this.fs.Write(this.fids[fid].inodeid, offset, count, buffer.subarray(state.offset));
|
||||
}
|
||||
|
||||
var file = this.fs.inodes[this.fids[fid].inodeid];
|
||||
this.bus.send("9p-write-end", [file.name, count]);
|
||||
this.bus.send("9p-write-end", [filename, count]);
|
||||
|
||||
marshall.Marshall(["w"], [count], this.replybuffer, 7);
|
||||
this.BuildReply(id, tag, 4);
|
||||
|
@ -689,8 +672,8 @@ Virtio9p.prototype.ReceiveRequest = function (bufchain) {
|
|||
var idx = this.fids[fid].inodeid;
|
||||
var offset = 7+2;
|
||||
var nwidx = 0;
|
||||
//console.log(idx, this.fs.inodes[idx]);
|
||||
message.Debug("walk in dir " + this.fs.inodes[idx].name + " to: " + walk.toString());
|
||||
//console.log(idx, this.fs.GetInode(idx));
|
||||
message.Debug("walk in dir " + this.fs.GetInode(idx).name + " to: " + walk.toString());
|
||||
for(var i=0; i<nwname; i++) {
|
||||
idx = this.fs.Search(idx, walk[i]);
|
||||
|
||||
|
@ -698,7 +681,7 @@ Virtio9p.prototype.ReceiveRequest = function (bufchain) {
|
|||
message.Debug("Could not find: " + walk[i]);
|
||||
break;
|
||||
}
|
||||
offset += marshall.Marshall(["Q"], [this.fs.inodes[idx].qid], this.replybuffer, offset);
|
||||
offset += marshall.Marshall(["Q"], [this.fs.GetInode(idx).qid], this.replybuffer, offset);
|
||||
nwidx++;
|
||||
//message.Debug(this.fids[nwfid].inodeid);
|
||||
//this.fids[nwfid].inodeid = idx;
|
||||
|
|
|
@ -598,6 +598,18 @@ FS.prototype.Write = function(id, offset, count, buffer) {
|
|||
data.set(buffer.subarray(0, count), offset);
|
||||
};
|
||||
|
||||
FS.prototype.Read = function(inodeid, offset, count)
|
||||
{
|
||||
if(!this.inodedata[inodeid])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.inodedata[inodeid].subarray(offset, offset + count);
|
||||
}
|
||||
};
|
||||
|
||||
FS.prototype.Search = function(parentid, name) {
|
||||
var id = this.inodes[parentid].firstid;
|
||||
while(id != -1) {
|
||||
|
@ -610,6 +622,16 @@ FS.prototype.Search = function(parentid, name) {
|
|||
return -1;
|
||||
};
|
||||
|
||||
FS.prototype.CountUsedInodes = function()
|
||||
{
|
||||
return this.inodes.length;
|
||||
};
|
||||
|
||||
FS.prototype.CountFreeInodes = function()
|
||||
{
|
||||
return 1024 * 1024;
|
||||
};
|
||||
|
||||
FS.prototype.GetTotalSize = function() {
|
||||
return this.used_size;
|
||||
//var size = 0;
|
||||
|
@ -645,6 +667,30 @@ FS.prototype.FindPreviousID = function(idx) {
|
|||
return id;
|
||||
};
|
||||
|
||||
// XXX: just copying
|
||||
FS.prototype.Link = function(targetid, name, parentid)
|
||||
{
|
||||
var inode = this.CreateInode();
|
||||
var inodetarget = this.GetInode(targetid);
|
||||
const targetdata = this.Read(targetid, 0, inodetarget.size);
|
||||
//inode = inodetarget;
|
||||
inode.dirty = true;
|
||||
inode.mode = inodetarget.mode;
|
||||
inode.size = inodetarget.size;
|
||||
inode.symlink = inodetarget.symlink;
|
||||
var data = this.inodedata[this.inodes.length] = new Uint8Array(inode.size);
|
||||
if(targetdata)
|
||||
{
|
||||
data.set(targetdata, 0);
|
||||
}
|
||||
inode.name = name;
|
||||
inode.parentid = parentid;
|
||||
this.PushInode(inode);
|
||||
//inode.uid = inodetarget.uid;
|
||||
//inode.gid = inodetarget.gid;
|
||||
//inode.mode = inodetarget.mode | S_IFLNK;
|
||||
};
|
||||
|
||||
FS.prototype.Unlink = function(idx) {
|
||||
this.NotifyListeners(idx, 'delete');
|
||||
if (idx == 0) return false; // root node cannot be deleted
|
||||
|
|
|
@ -1149,11 +1149,12 @@ V86Starter.prototype.read_file = function(file, callback)
|
|||
id,
|
||||
function()
|
||||
{
|
||||
var data = fs.inodedata[id];
|
||||
const size = fs.GetInode(id).size;
|
||||
const data = fs.Read(id, 0, size);
|
||||
|
||||
if(data)
|
||||
{
|
||||
callback(null, data.subarray(0, fs.inodes[id].size));
|
||||
callback(null, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue