mirror of
https://codeberg.org/TicklishHoneyBee/CLIte.git
synced 2026-03-11 09:04:37 +00:00
start of persistant filesystem
This commit is contained in:
parent
79db978349
commit
e852f31781
2 changed files with 103 additions and 5 deletions
|
|
@ -73,6 +73,9 @@ var bios = {
|
|||
case 1:
|
||||
return bios.video.io;
|
||||
break;
|
||||
case 2:
|
||||
return bios.storage.io;
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
return null;
|
||||
|
|
@ -146,6 +149,46 @@ var bios = {
|
|||
return true;
|
||||
}
|
||||
},
|
||||
storage:{
|
||||
data:{
|
||||
files:[]
|
||||
},
|
||||
internal:{
|
||||
flush:function() {
|
||||
var list = bios.storage.data.files.join(':');
|
||||
window.localStorage.setItem('files',list);
|
||||
}
|
||||
},
|
||||
io:{
|
||||
addFile:function(fn,data) {
|
||||
if (bios.storage.data.files.indexOf(fn) < 0)
|
||||
bios.storage.data.files.push(fn);
|
||||
window.localStorage.setItem(fn,data);
|
||||
bios.storage.internal.flush();
|
||||
},
|
||||
delFile:function(fn) {
|
||||
var ind = bios.storage.data.files.indexOf(fn)
|
||||
if (ind > -1)
|
||||
bios.storage.data.files.splice(ind,1);
|
||||
window.localStorage.removeItem(fn);
|
||||
bios.storage.internal.flush();
|
||||
},
|
||||
getList:function() {
|
||||
return bios.storage.data.files;
|
||||
},
|
||||
getFile:function(fn) {
|
||||
var ind = bios.storage.data.files.indexOf(fn)
|
||||
if (ind < 0)
|
||||
return null;
|
||||
return window.localStorage.getItem(fn).toString();
|
||||
}
|
||||
},
|
||||
init:function() {
|
||||
let f = window.localStorage.getItem('files');
|
||||
if (f)
|
||||
bios.storage.data.files = f.split(':');
|
||||
}
|
||||
},
|
||||
input:{
|
||||
el:null,
|
||||
state:0,
|
||||
|
|
@ -227,7 +270,11 @@ var bios = {
|
|||
bios.input.init();
|
||||
bios.core.writeStringVGA(25,4,'Done',2);
|
||||
|
||||
bios.core.writeStringVGA(0,6,'Booting...');
|
||||
bios.core.writeStringVGA(3,5,'Storage Devices:');
|
||||
bios.storage.init();
|
||||
bios.core.writeStringVGA(25,5,'Done',2);
|
||||
|
||||
bios.core.writeStringVGA(0,7,'Booting...');
|
||||
|
||||
bios.boot.preBoot();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -307,8 +307,8 @@ guest:x:1:1:guest:/usr/home/guest:/bin/sh
|
|||
return false;
|
||||
}
|
||||
n.data.content = `
|
||||
root:x:0:
|
||||
guest:x:1:
|
||||
root:x:0:root
|
||||
guest:x:1:guest
|
||||
`;
|
||||
// TODO: check cookies for a local user
|
||||
n.mode = clite.lib.modestr('-rw-r--r--');
|
||||
|
|
@ -507,6 +507,18 @@ license.txt:/etc/license:0:0:-rw-r--r--`;
|
|||
// populate /etc (mostly for environment)
|
||||
clite.log.write('Populating /etc');
|
||||
defaultConfig();
|
||||
var b = clite.state.bios.io.read(2);
|
||||
if (b) {
|
||||
let list = b.getList();
|
||||
list.forEach(function(fn) {
|
||||
let d = clite.lib.dirname(fn);
|
||||
vfsapi.mkPath(0,d);
|
||||
vfsapi.mkFile(0,fn);
|
||||
let n = vfsapi.getNode(0,fn);
|
||||
if (n)
|
||||
n.data.content = b.getFile(fn);
|
||||
});
|
||||
}
|
||||
// populate /dev (data/filesys.txt is /dev/wfs already)
|
||||
clite.log.write('Populating /dev');
|
||||
defaultDevices();
|
||||
|
|
@ -896,6 +908,13 @@ clite.user = {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
function getUserByName(n) {
|
||||
for (var i=0; i<data.users.length; i++) {
|
||||
if (data.users[i].name == n)
|
||||
return data.users[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function getGroup(gid) {
|
||||
for (var i=0; i<data.groups.length; i++) {
|
||||
if (data.groups[i].gid == gid)
|
||||
|
|
@ -904,8 +923,28 @@ clite.user = {
|
|||
return null;
|
||||
}
|
||||
function saveUsers() {
|
||||
// TODO: write /etc/passwd and /etc/group
|
||||
// TODO: write all non-root and non-guest lines to cookies
|
||||
var b = clite.state.bios.io.read(2)
|
||||
var n = vfsapi.getNode(0,'/etc/passwd');
|
||||
if (!n)
|
||||
return false;
|
||||
n.data.content = '';
|
||||
//root:$-7a1c0437:0:0:root:/root:/bin/sh
|
||||
data.users.forEach(function(u) {
|
||||
var pw = 'x';
|
||||
if (u.pass != 'x')
|
||||
pw = '$'+u.pass;
|
||||
n.data.content += u.name+':'+pw+':'+u.uid+':'+u.gid+'::'+u.env.HOME+':'+u.env.SHELL+'\n';
|
||||
});
|
||||
b.addFile('/etc/passwd',n.data.content);
|
||||
n = vfsapi.getNode(0,'/etc/group');
|
||||
if (!n)
|
||||
return false;
|
||||
n.data.content = '';
|
||||
//root:x:0:
|
||||
data.groups.forEach(function(g) {
|
||||
n.data.content += g.name+':x:'+g.gid+':'+g.users.join(',')+'\n'
|
||||
});
|
||||
b.addFile('/etc/group',n.data.content);
|
||||
}
|
||||
function loadUsers() {
|
||||
// load in user data from /etc/passwd
|
||||
|
|
@ -971,6 +1010,11 @@ clite.user = {
|
|||
gdata.name = sects[0];
|
||||
gdata.gid = parseInt(sects[2]);
|
||||
gdata.users = sects[3].split(',');
|
||||
gdata.users.forEach(function(u) {
|
||||
var ud = getUserByName(u);
|
||||
if (ud)
|
||||
ud.groups.push(gdata.name);
|
||||
});
|
||||
});
|
||||
|
||||
// load the environment
|
||||
|
|
@ -1262,6 +1306,13 @@ cat -l /usr/share/introduction
|
|||
return true;
|
||||
return false;
|
||||
}
|
||||
clite.user.dump = function() {
|
||||
var d = '';
|
||||
data.users.forEach(function(u) {
|
||||
d += u.name+':'+u.pass+':'+u.uid+':'+u.gid+':'+u.env.HOME+':'+u.env.SHELL+'\n';
|
||||
});
|
||||
return d;
|
||||
}
|
||||
|
||||
loadUsers();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue