new filesystem (permission bits, owner, groups, buffer, mountpoints, eval programs), user-management, new io-system

This commit is contained in:
overflowerror 2013-10-05 17:35:44 +02:00
parent aa27d2bebc
commit a8925f7811
18 changed files with 1385 additions and 665 deletions

View file

@ -63,7 +63,7 @@ Emulator.addEventHandlers = function() {
console.log("Emulator: adding key-down-event");
//this.input.onkeydown = this.handleKeyDown;
window.onkeydown = this.handleKeyDown;
var timerid = window.setInterval(function() {/*for (var i = 0; i < 10; i++)*/ Emulator.tick(0);}, 1);
var timerid = window.setInterval(function() {/*for (var i = 0; i < 1000; i++)*/ Emulator.tick(0);}, 1);
Emulator.mainTickId = timerid;
console.log("Emulator: adding default 1ms (or cheated 0.1 ms) tick with tid=" + timerid);
this.refocus();

23
main.js
View file

@ -11,16 +11,37 @@ Math.sign = function(x) {
}
function nothing() {
}
function ret(v) {
return v;
}
function isNumber(n) {
return (parseInt(n) + "" == n);
}
function wait (ms) {
var now = (new Date()).getTime();
var to = now + ms;
while (now != to)
now = (new Date()).getTime();
}
function clone(object){
if(!object)
return object;
if (typeof object != "object")
return obj;
var tmp = object.constructor();
for(var key in object)
tmp[key] = clone(object[key]);
return tmp;
}
var main = function () {
Emulator.init(document.getElementById("output"), document.forms['form'].elements['input'], 80, 24);
}

View file

@ -6,7 +6,7 @@
"hdd": 0,
"partition": 0,
"label": "wish os",
"kernel": "kernel0.1.js",
"kernel": "kernel0.9.js",
"parameters": ""
}
]

13
wish-sys/mbr/config.json~ Normal file
View file

@ -0,0 +1,13 @@
{
"sleep": 10,
"default": 0,
"systems": [
{
"hdd": 0,
"partition": 0,
"label": "wish os",
"kernel": "kernel0.1.js",
"parameters": ""
}
]
}

107
wish-sys/mbr/init.js~ Normal file
View file

@ -0,0 +1,107 @@
var MBR = function() {
}
MBR.main = function(device) {
console.log("MBR: main");
console.log("MBR: start Boot Loader");
Loader.main(device);
}
var Loader = function() {
}
Loader.logo = "\033[32m" +
" .__ .__ \n" +
"__ _ _|__| _____| |__ \n" +
"\\ \\/ \\/ / |/ ___/ | \\ \n" +
" \\ /| |\\___ \\| Y \\\n" +
" \\/\\_/ |__/____ >___| /\n" +
" \\/ \\/ \033[31mLoader\033[0m\n";
Loader.tickid;
Loader.state;
Loader.device;
Loader.config;
Loader.main = function(device) {
console.log("Loader: main");
console.log("Loader: register 100ms-timer");
Loader.tickid = Emulator.registerTimer(100, Loader.tick);
console.log("Loader: register key interrupt");
Emulator.interrupts['key'] = Loader.key;
Loader.device = device;
var text = "\033[2J\033[0;0H\033[?25l" + Loader.logo + "\033[s";
Emulator.output(text);
Loader.state = 0;
}
Loader.key = function(keycode) {
if (KeyCodes.isEnter(keycode)) {
Loader.boot();
return;
}
var char = KeyCodes.normalKey(keycode);
if (char == 'w') Loader.selected--;
if (char == 's') Loader.selected++;
Loader.selected %= Loader.config.systems.length;
if (Loader.selected < 0)
Loader.selected += Loader.config.systems.length;
Loader.outputSystems();
}
Loader.tick = function() {
switch(Loader.state) {
case 0:
console.log("Loader: load config");
Loader.config = JSON.parse(Emulator.Request.get(Loader.device.name + "/" + Loader.device.mbr + "/config.json", "", false, ret))
Loader.selected = Loader.config.default;
Loader.state++;
break;
case 1:
Loader.outputSystems();
Loader.state++;
break;
case 2:
break;
case 3:
Emulator.output(".");
break;
default:
break;
}
}
Loader.outputSystems = function() {
console.log("Loader: display menu");
var systems = Loader.config.systems;
var text = "\033[u\n\n\n\n";
for(var i = 0; i < systems.length; i++) {
var string = "-> " + systems[i].label + " " + systems[i].kernel;
var length = Emulator.Output.xsize - string.length - 10
text += "\033[5C\033[46m\033[31m" + ((i == Loader.selected) ? "->" : " ") + " \033[30m" + systems[i].label + " \033[34m" + systems[i].kernel;
for (var j = 0; j < length; j++)
text += " ";
text += "\033[0m\n";
}
text += "\n\nSelect OS to boot... [w, s]";
Emulator.output(text);
}
Loader.boot = function() {
var device = Emulator.Devices.getHarddisks();
var system = Loader.config.systems[Loader.selected];
device = device[system.hdd];
var partition = device.partitions[system.partition];
var loadstring = device.name + "/" + partition.name + "/" + system.kernel
Emulator.output("\n\nTrying to boot " + loadstring + "..");
Loader.state = 3;
Emulator.Request.include(loadstring, Loader.finished);
}
Loader.finished = function() {
console.log("Loader: stop BIOS");
console.log("loader: remove all event handlers");
Emulator.interrupts = new Array();
Emulator.unregisterTimer(Loader.tickid);
console.log("Loader: start OS");
var system = Loader.config.systems[Loader.selected];
try {
OS.main(system);
Emulator.output("\nKernel loaded successfully.");
} catch (exception) {
console.dir(exception);
Emulator.output("\nFailed to load kernel...\n\n");
Emulator.output("\033[31msystem halt\033[0m");
}
}

View file

@ -4,6 +4,10 @@ CatClass.prototype = new Process();
CatClass.prototype.buffer = new Array();
CatClass.prototype.stream;
CatClass.prototype.main = function(args) {
this.files['stdout'].write("not ready yet");
this.exit(0);
if (args.length == 1) {
this.stream = this.files['stdin'];
} else {

View file

@ -11,18 +11,42 @@ CdClass.prototype.main = function(args) {
folder = args[1];
}
if (folder.substring(0, 1) != "/")
folder = env.array['PWD'] + folder;
if (folder[folder.length - 1] != "/")
folder += "/";
folder = Kernel.Filesystem.shortenPath(folder);
if (!folder) {
folder = env.array['PWD'] + "/" + folder;
try {
folder = Kernel.Filesystem.shortenPath(folder);
} catch (e) {
this.exit(0);
}
var files = Kernel.Filesystem.getDirectory(folder);
if (files.error) {
stdout.write("cd: cannot access " + folder + ": " + files.error + "\n");
var file = new File(folder);
console.dir(file);
if (!file.exists()) {
stdout.write("cd: no such file or directory: " + folder + "\n");
this.exit(2);
}
if (!(file.getPermissions() & PERM_D)) {
stdout.write("cd: not a directory: " + folder + "\n");
this.exit(1);
}
var uid = Kernel.ProcessManager.getUserByPID(Kernel.ProcessManager.getCurrentPID());
if (uid != 0) {
if (uid == file.getOwner()) {
if (!(file.getPermissions() & PERM_UX)) {
stdout.write("cd: permission denied: " + folder + "\n");
this.exit(3);
}
} else if (Kernel.UserManager.isUserIdInGroupId(uid, file.getGroup())) {
if (!(file.getPermissions() & PERM_GX)) {
stdout.write("cd: permission denied: " + folder + "\n");
this.exit(3);
}
} else {
if (!(file.getPermissions() & PERM_OX)) {
stdout.write("cd: permission denied: " + folder + "\n");
this.exit(3);
}
}
}
env.array['PWD'] = folder;
this.exit(0);
}

View file

@ -27,7 +27,7 @@ KillClass.prototype.main = function(args){
ret = 1;
continue;
}
var proc = Kernel.ProcessManager.processList[parseInt(pids[i])];
var proc = Kernel.ProcessManager.getProcess(parseInt(pids[i]);
if (!proc) {
stdout.write("kill: kill " + pids[i] + ": no such process\n");
ret = 1;

View file

@ -10,11 +10,17 @@ LsClass.prototype.main = function(args) {
} else {
folder = args[1];
}
var files = Kernel.Filesystem.getDirectory(folder);
if (files.error) {
stdout.write("ls: cannot access " + folder + ": " + files.error + "\n");
folder = Kernel.Filesystem.shortenPath(folder);
var file = new File(folder);
if (!file.exists()) {
stdout.write("ls: no such file or directory: " + folder + "\n");
this.exit(2);
}
var files = Kernel.Filesystem.readDir(folder);
for (var i = 0; i < files.length; i++) {
if (files[i].substring(0, 1) != ".")
stdout.write(files[i] + "\n");

View file

@ -11,7 +11,8 @@ WshClass.prototype.childList = new Array();
WshClass.prototype.main = function(args) {
console.log("wsh: adding to scheduler job list");
Kernel.Scheduler.add(this);
this.username = args['1'];
this.uid = Kernel.ProcessManager.getUserByPID(this.pid);
this.username = Kernel.UserManager.getUserById(this.uid).username;
this.Environment.array['HOME'] = args[2];
this.Environment.array['PWD'] = args[2];
}
@ -22,19 +23,21 @@ WshClass.prototype.tick = function() {
case 0:
stdout.write("Welcome to WishOS 0.1 (WOSKernel 0.1)\n\n");
console.log("wsh: loading profile");
this.files['profile.d'] = new File("/etc/profile.d/env.json");
var array = JSON.parse(this.files['profile.d'].read());
var prof = new File("/etc/profile.d/env.json");
var array = JSON.parse(prof.read());
prof.close();
for (var i = 0; i < array.length; i++) {
while(array[i][1].indexOf("\\033") != -1)
array[i][1] = array[i][1].replace("\\033", "\033");
this.Environment.array[array[i][0]] = array[i][1];
}
var files = Kernel.Filesystem.getDirectory(this.Environment.array['HOME']);
if (files.error) {
var file = new File(this.Environment.array['HOME']);
if (!file.exists() || !(file.getPermissions() & PERM_D)) {
stdout.write("\033[31mHome directory not found. Using / instead.\n\n");
this.Environment.array['HOME'] = "/";
this.Environment.array['PWD'] = "/";
}
file.close();
this.state++;
break;
case 1:
@ -46,16 +49,17 @@ WshClass.prototype.tick = function() {
while (prompt.indexOf("\\u") != -1)
prompt = prompt.replace("\\u", OS.hostname);
while (prompt.indexOf("\\$") != -1)
prompt = prompt.replace("\\$", (this.username == "root") ? "#" : "$");
prompt = prompt.replace("\\$", (this.uid == 0) ? "#" : "$");
while (prompt.indexOf("\\#") != -1)
prompt = prompt.replace("\\#", (this.lastExitCode == 0) ? "" : this.lastExitCode);
stdout.write(prompt);
this.state++;
break;
case 2:
var code = stdin.read();
if (!code)
var char = stdin.read(1);
if (!char.length)
break;
var code = char.charCodeAt(0);
if (KeyCodes.isBackspace(code)) {
if (!this.input.length)
break;
@ -68,7 +72,6 @@ WshClass.prototype.tick = function() {
this.parseLine();
break;
}
var char = KeyCodes.normalKey(code);
this.input.push(char);
stdout.write(char);
break;
@ -199,32 +202,15 @@ WshClass.prototype.parseLine = function() {
this.state = 3;
var pathArray = new Array();
pathArray[0] = ["stdout", this.files['stdout'].path];
pathArray[1] = ["stdin", this.files['stdin'].path];
var s = "";
s += "var func = function () { ";
s += " try {";
s += " var prog = new " + Kernel.ProcessManager.getClassNameFromFileName(file) + "();";
s += " } catch (exception) {";
s += " console.dir(exception);";
s += " }";
s += " prog.init(" + this.pid + ");";
s += " var paths = JSON.parse('" + JSON.stringify(pathArray) + "');";
s += " for(var i = 0; i < paths.length; i++) {";
s += " prog.files[paths[i][0]] = Kernel.Filesystem.getFile(paths[i][1]);";
s += " }";
s += " prog.Environment = Kernel.ProcessManager.processList[" + this.pid + "].Environment;";
s += " Kernel.ProcessManager.add(prog);";
s += " console.log(\"wsh: start command '" + file + "'...\");";
s += " try {";
s += " prog.main(JSON.parse('" + JSON.stringify(params) + "'));";
s += " } catch (exception) {";
s += " console.log(\"Prozess \" + prog.pid + \": \");";
s += " console.dir(exception);";
s += " }";
s += "}";
eval(s);
Kernel.ProcessManager.load(file, func);
var pid = Kernel.ProcessManager.exec(file, [], false);
var prog = Kernel.ProcessManager.getProcess(pid);
prog.files['stdin'] = this.files['stdin'];
prog.files['stdout'] = this.files['stdout'];
prog.Environment = this.Environment;
console.log("wsh: program startet: " + file);
prog.main(params);
}
WshClass.prototype.tryFile = function(name) {
var file = new File(name);

View file

@ -0,0 +1,10 @@
[
{
"//": "root FS",
"mountPoint": "/",
"hdd": "wish-sys",
"par": "sys-part",
"fs": "basefs",
"options": ""
}
]

View file

@ -0,0 +1,16 @@
[
{
"id": 0,
"name": "root",
"members": [
0
]
},
{
"id": 1,
"name": "users",
"members": [
0, 1
]
}
]

View file

@ -3,15 +3,17 @@
"id": 0,
"username": "root",
"password": "ce5ca673d13b36118d54a7cf13aeb0ca012383bf771e713421b4d1fd841f539a",
"home": "/root/",
"shell": "/bin/wsh.js"
"home": "/root",
"shell": "/bin/wsh.js",
"group": 0
},
{
"id": 1,
"username": "nobody",
"//": "password = nobody",
"password": "6382b3cc881412b77bfcaeed026001c00d9e3025e66c20f6e7e92f079851462a",
"home": "/home/nobody/",
"shell": "/bin/wsh.js"
"home": "/home/nobody",
"shell": "/bin/wsh.js",
"group": 1
}
]

View file

@ -1,516 +0,0 @@
const SIGHUP = 1;
const SIGKILL = 9;
const SIGALRM = 14;
const SIGTERM = 15;
const SIGCHLD = 20;
const SIGXCPU = 24;
const SIGUSR1 = 30;
const SIGUSR2 = 31;
const APPND = 1;
const OVWRT = 2;
const FILE = 1;
const DIR = 2;
const SYSHALT = 31415926
var OS = function() {
}
OS.system;
OS.runlevel;
OS.staticShift = 7;
OS.hostname = "wish";
OS.logo = "\033[32m" +
" .__ .__ \n" +
"__ _ _|__| _____| |__ \n" +
"\\ \\/ \\/ / |/ ___/ | \\ \n" +
" \\ /| |\\___ \\| Y \\\n" +
" \\/\\_/ |__/____ >___| /\n" +
" \\/ \\/ \033[31mOS\033[0m\n";
OS.main = function(system) {
console.log("OS: main");
OS.system = system;
console.log("OS: init Kernel");
Kernel.init();
}
var Kernel = function() {
}
Kernel.time;
Kernel.state;
Kernel.machineTimerId;
Kernel.globalLog;
Kernel.init = function() {
console.log("Kernel: init");
Kernel.state = 0;
console.log("Kernel: main timer (100ms)");
Kernel.machineTimerId = Emulator.registerTimer(100, Kernel.machine);
Kernel.globalLog = "";
}
Kernel.machine = function() {
switch(Kernel.state) {
case 0:
Emulator.Output.shiftKey = OS.staticShift;
Emulator.output("\033[2J\033[0;0H" + OS.logo);
Kernel.msgOut("reseting kernel timer", true);
Kernel.time = 0;
Kernel.msgOut("register main timer (100ms)", true); // pre
Kernel.msgOut("init filesystem", true);
Kernel.Filesystem.init();
Kernel.msgOut("init process manager", true);
Kernel.ProcessManager.init();
Kernel.msgOut("init scheduler", true);
Kernel.Scheduler.init();
Kernel.msgOut("init kernel io", true);
Kernel.IO.init();
Kernel.msgOut(" register keyboard interrupt", true);
Emulator.interrupts['key'] = Kernel.IO.key;
Kernel.msgOut(" register power switch interrupt", true);
Emulator.interrupts['powersw'] = Kernel.IO.powersw;
Kernel.msgOut("loading /sbin/init.js");
Kernel.ProcessManager.load("/sbin/init.js", Kernel.next);
Kernel.state++;
break;
case 1:
break;
case 2:
Kernel.msgSuccess(true);
Kernel.msgOut(" creating class instance", true);
var init = new InitClass();
init.init(0);
Kernel.msgOut(" adding handler for stdio on /dev/tty1", true);
init.files['stdin'] = Kernel.Filesystem.getFile("/dev/tty1/i");
init.files['stdout'] = Kernel.Filesystem.getFile("/dev/tty1/o");
Kernel.msgOut(" adding to process list", true);
Kernel.ProcessManager.add(init);
Kernel.msgOut(" starting init", true);
init.main();
Kernel.msgOut("register scheduler timer (1ms)", true);
Kernel.msgOut("starting scheduler", true);
Emulator.interrupts[0] = Kernel.Scheduler.tick;
Kernel.state++;
break;
case 3:
break;
default:
break;
}
}
Kernel.next = function() {
Kernel.state++;
}
Kernel.msgOut = function(text, success, color) {
while (text.length < Emulator.Output.xsize - 12)
text += " ";
text = "\n" + text;
if (color) {
text = color + text;
text += "\033[0m"
}
Kernel.globalLog += text;
Emulator.output(text);
Kernel.msgSuccess(success);
}
Kernel.msgSuccess = function(success) {
var text = "";
if (success == true)
text = "[ \033[32msuccess\033[0m ]";
else if (success == false)
text = "[ \033[31mfailed\033[0m ]";
else
text = "";
Kernel.globalLog += text;
Emulator.output(text);
}
Kernel.shutdown = function() {
Emulator.output("\n\n\nShuting down...\nKilling all processes...\n");
var procs = new Array();
for (var i in Kernel.ProcessManager.processList) {
var proc = Kernel.ProcessManager.processList[i];
if (proc)
procs.push(proc);
}
//procs.reverse();
for (var i = 0; i < procs.length; i++) {
if (!procs[i].pid)
continue;
Emulator.output("sending sigkill to pid " + procs[i].pid + "...\n");
try {
procs[i].signalHandler(9);
} catch (exception) {
}
}
Emulator.output("all processes killed.\n\nRemoving event handlers\n\n");
Emulator.interrupts = new Array();
Emulator.output("System halt\n\n");
}
Kernel.Scheduler = function() {
}
Kernel.Scheduler.jobs;
Kernel.Scheduler.activ;
Kernel.Scheduler.working;
Kernel.Scheduler.init = function() {
Kernel.msgOut(" init job list", true);
Kernel.Scheduler.jobs = new Array();
Kernel.Scheduler.activ = 0;
Kernel.Scheduler.working = false;
}
Kernel.Scheduler.tick = function() {
if (Kernel.Scheduler.working) {
Kernel.Scheduler.jobs[Kernel.Scheduler.activ].signalHandler(SIGXCPU);
Kernel.Scheduler.activ %= Kernel.Scheduler.jobs.length;
return;
}
Kernel.Scheduler.working = true;
Kernel.Scheduler.activ++;
Kernel.Scheduler.activ %= Kernel.Scheduler.jobs.length;
var pid = Kernel.Scheduler.jobs[Kernel.Scheduler.activ].pid;
try {
Kernel.Scheduler.jobs[Kernel.Scheduler.activ].tick();
} catch (error) {
if ((typeof error) != "number") {
console.log("Kernel: a wild error appeared in pid" + pid + ".tick:");
console.dir(error);
}
}
Kernel.time++;
Kernel.Scheduler.working = false;
}
Kernel.Scheduler.add = function(process) {
if (!process.tick)
return 2; // no tick method
for (var i = 0; i < this.jobs.length; i++) {
if (this.jobs[i].pid == process.pid)
return 3; // no double processes
}
this.jobs.push(process);
return 0;
}
Kernel.Scheduler.remove = function(process) {
for (var i = 0; i < this.jobs.length; i++) {
if (this.jobs[i].pid == process.pid) {
if (this.activ == i)
this.working = false;
this.jobs.splice(i, i);
return 0; // success
}
}
return 1; // not in list
}
Kernel.ProcessManager = function() {
}
Kernel.ProcessManager.nextPid;
Kernel.ProcessManager.processList;
Kernel.ProcessManager.loadedList;
Kernel.ProcessManager.init = function() {
Kernel.msgOut(" init process list", true);
Kernel.ProcessManager.processList = new Array();
Kernel.ProcessManager.loadedList = new Array();
Kernel.ProcessManager.nextPid = 1;
}
Kernel.ProcessManager.add = function(process) {
this.processList[process.pid] = process;
if (process.parentId != 0)
this.processList[process.parentId].signalHandler(SIGCHLD);
}
Kernel.ProcessManager.quit = function(process) {
var parentId = process.parentId;
var pid = process.pid;
console.log("Kernel: quiting pid: " + pid);
Kernel.Scheduler.remove(process);
if (pid != parentId)
this.processList[parentId].signalHandler(SIGCHLD);
}
Kernel.ProcessManager.remove = function(process) {
this.processList.splice(process.pid, 1);
var childs = this.getAllChilds(process.pid);
for (var i = 0; i < childs.length; i++)
childs[i].parentId = 1;
if (childs.length > 0)
this.processList[1].signalHandler(SIGCHLD);
}
Kernel.ProcessManager.load = function(path, loaded) {
if (Kernel.ProcessManager.loadedList[path]) {
loaded();
return;
}
Kernel.ProcessManager.loadedList[path] = true;
Emulator.Request.include(Kernel.Filesystem.getRealPath(path), loaded);
}
Kernel.ProcessManager.getAllChilds = function(pid) {
var kids = new Array();
for(var index in Kernel.ProcessManager.processList) {
var proc = Kernel.ProcessManager.processList[index];
if (proc.parentId == pid) {
if (proc.exitCode === undefined)
kids.push(proc);
}
}
return kids;
}
Kernel.ProcessManager.getPid = function() {
return Kernel.ProcessManager.nextPid++;
}
Kernel.ProcessManager.getClassNameFromFileName = function(name) {
name = name.split("/");
name = name[name.length - 1];
name = name[0].toUpperCase() + name.substring(1);
name = name.split(".")[0];
name += "Class";
return name;
}
var Process = function(parentId) {
}
Process.prototype.pid;
Process.prototype.userId;
Process.prototype.parentId;
Process.prototype.files;
Process.prototype.exitCode;
Process.prototype.init = function(parentId) {
// DO NOT OVERWRITE
this.pid = Kernel.ProcessManager.getPid();
this.parentId = parentId;
this.files = new Array();
}
Process.prototype.main = function(args) {
}
Process.prototype.tick = function() {
}
Process.prototype.exit = function(code) {
this.exitCode = code;
Kernel.ProcessManager.quit(this);
throw code;
}
Process.prototype.signalHandler = function(signal) {
switch(signal) {
case SIGCHLD:
break;
case SIGHUP:
//break;
case SIGALRM:
//break;
case SIGTERM:
//break;
case SIGXCPU:
//break;
case SIGUSR1:
//break;
case SIGUSR2:
//break;
default: //SIGKILL
console.log("PID " + this.pid + " got Signal " + signal);
this.exit(1);
break;
}
}
var File = function(path) {
this.path = path;
}
File.prototype.path;
File.prototype.position = 0;
File.prototype.writeMode = APPND;
File.prototype.forceUpdate = function() {
Kernel.Filesystem.update(this.path);
}
File.prototype.exists = function() {
return Kernel.Filesystem.getFile(this.path).exists()
}
File.prototype.create = function() {
Kernel.Filesystem.create(this.path, FILE);
}
File.prototype.read = function(length) {
var val = Kernel.Filesystem.getFile(this.path).read(this.position, length);
if (length)
this.position += length;
return val;
}
File.prototype.write = function(string) {
this.writeFIFO(string);
}
File.prototype.writeFIFO = function(string) {
Kernel.Filesystem.getFile(this.path).writeFIFO(string, this.writeMode);
}
File.prototype.writeLIFO = function(string) {
Kernel.Filesystem.getFile(this.path).writeLIFO(string, this.writeMode);
}
var InnerFile = function(path) {
this.path = path;
}
InnerFile.prototype = new File;
InnerFile.prototype.content;
InnerFile.prototype.exists = function() {
return ((typeof this.content) != "number");
}
InnerFile.prototype.read = function(position, length) {
if (!length)
return this.content;
return this.content.substring(position, position + length)
}
InnerFile.prototype.writeFIFO = function(string, mode) {
if (mode == APPND)
this.content += string;
if (mode == OVWRT)
this.content = string;
}
InnerFile.prototype.writeLIFO = function(string, mode) {
if (mode == APPND)
this.content = text + this.content;
if (mode == OVWRT)
this.content = string;
}
var AppStream = function() {
}
AppStream.prototype = new File;
AppStream.prototype.content = new Array();
AppStream.prototype.eof = false;
AppStream.prototype.isFile = false;
AppStream.prototype.fromFile = function(file) {
var array = file.read().split("");
array.reverse();
for (var i = 0; i < array.length; i++)
this.content.push(array[i]);
this.isFile = true;
}
AppStream.prototype.read = function() {
var char = this.content.pop();
this.eof = this.isFile && (!this.content.length);
if (char)
return char.charCodeAt(0);
}
AppStream.prototype.writeFIFO = function(string) {
this.content.input.reverse();
for (var i = 0; i < string.length; i++)
this.content.push(char);
this.content.reverse();
}
AppStream.prototype.writeLIFI = function(string) {
for(var i = 0; i < string.length; i++)
this.content.push(string[i]);
}
Kernel.Filesystem = function() {
}
Kernel.Filesystem.devices;
Kernel.Filesystem.root;
Kernel.Filesystem.files;
Kernel.Filesystem.init = function() {
Kernel.msgOut(" geting device list", true);
Kernel.Filesystem.devices = Emulator.Devices.getAll();
var hdd = Kernel.Filesystem.devices.harddisks[OS.system.hdd];
var partition = hdd.partitions[OS.system.partition];
Kernel.msgOut(" generating root path", true);
Kernel.Filesystem.root = hdd.name + "/" + partition.name;
Kernel.Filesystem.files = new Array();
}
Kernel.Filesystem.create = function(name, type) {
var file = new InnerFile(name);
file.content = "";
Kernel.Filesystem.files[name] = file;
}
Kernel.Filesystem.getFile = function(path) {
if (Kernel.Filesystem.files[path])
return Kernel.Filesystem.files[path];
return Kernel.Filesystem.update(path);
console.log("Kernel: get file " + path);
}
Kernel.Filesystem.update = function(path) {
var file = new InnerFile(path);
file.content = Emulator.Request.get(Kernel.Filesystem.getRealPath(path), "", false, ret);
Kernel.Filesystem.files[path] = file;
return file;
}
Kernel.Filesystem.shortenPath = function(name) {
var index;
while ((index = name.indexOf("/../")) != -1) {
name = name.replace("/../", "/");
var index2 = 0;
var index3 = -1;
while(index2 < index) {
index3 = index2;
index2 = name.indexOf("/", index3 + 1);
}
if (index3 == -1)
return undefined;
name = name.substring(0, index3) + name.substring(index);
}
while ((index = name.indexOf("/./")) != -1)
name = name.replace("/./", "/");
return name;
}
Kernel.Filesystem.getRealPath = function(name) {
name = Kernel.Filesystem.shortenPath(name);
return Kernel.Filesystem.root + name;
}
Kernel.Filesystem.addTTY = function(path, output, input) {
var out = new InnerFile(path + "/o");
out.output = output;
out.writeFIFO = function(string) {
this.output(string);
}
out.writeLIFI = function(string) {
this.output(string.reverse());
}
out.read = function() {
return "";
}
var inp = new InnerFile(path + "/i");
inp.input = input;
inp.writeFIFO = function(string) {
var input = this.input();
input.reverse();
for (var i = 0; i < string.length; i++)
input.push(char);
input.reverse();
}
inp.writeLIFI = function(string) {
for(var i = 0; i < string.length; i++)
this.input().push(string[i]);
}
inp.read = function() {
return this.input().pop();
}
Kernel.Filesystem.files[path + "/o"] = out;
Kernel.Filesystem.files[path + "/i"] = inp
}
Kernel.Filesystem.getDirectory = function(path) {
console.log("Kernel: trying to read directory " + path);
var response = Emulator.Request.get(Kernel.Filesystem.getRealPath("/lib/kernel/files.php"), "scandir=" + encodeURIComponent(path), false, ret);
response = JSON.parse(response);
if (response.error) {
console.log("Kernel: error on reading: " + response.error);
return response;
}
return response;
}
Kernel.IO = function() {
}
Kernel.IO.inputBuffer;
Kernel.IO.init = function() {
Kernel.msgOut(" generating /dev/tty1", true);
Kernel.Filesystem.addTTY("/dev/tty1", Kernel.IO.output, Kernel.IO.input);
Kernel.IO.inputBuffer = new Array();
}
Kernel.IO.key = function(code) {
Kernel.IO.inputBuffer.push(code);
}
Kernel.IO.powersw = function() {
console.log("Kernel: power switch pressed, but no action defined");
}
Kernel.IO.input = function() {
return Kernel.IO.inputBuffer;
}
Kernel.IO.output = function(string) {
Emulator.output(string);
}

File diff suppressed because it is too large Load diff

View file

@ -3,36 +3,16 @@ var GettyClass = function() {
}
GettyClass.prototype = new Process();
GettyClass.prototype.file = "";
GettyClass.prototype.login = "/sbin/login";
GettyClass.prototype.login = "/sbin/login.js";
GettyClass.prototype.main = function(args) {
console.log("getty: started");
this.parseArgs(args);
pathArray = new Array();
pathArray[0] = ["stdout", this.file + "/o"];
pathArray[1] = ["stdin", this.file + "/i"];
var s = "";
s += "var func = function () { ";
s += " try {";
s += " var prog = new " + Kernel.ProcessManager.getClassNameFromFileName(this.login) + "();";
s += " } catch (exception) {";
s += " console.dir(exception);";
s += " }";
s += " prog.init(" + this.pid + ");";
s += " var paths = JSON.parse('" + JSON.stringify(pathArray) + "');";
s += " for(var i = 0; i < paths.length; i++) {";
s += " prog.files[paths[i][0]] = Kernel.Filesystem.getFile(paths[i][1]);";
s += " }";
s += " Kernel.ProcessManager.add(prog);";
s += " console.log(\"getty: start shell '" + name + "'...\");";
s += " try {";
s += " prog.main(new Array());";
s += " } catch (exception) {";
s += " console.log(\"Prozess \" + prog.pid + \": \");";
s += " console.dir(exception);";
s += " }";
s += "}";
eval(s);
Kernel.ProcessManager.load(this.login + ".js", func);
var pid = Kernel.ProcessManager.exec(this.login, [], false);
var prog = Kernel.ProcessManager.getProcess(pid);
prog.files['stdin'] = new File(this.file);
prog.files['stdout'] = new File(this.file);
prog.files['stdout'].writeMode = MODE_APPND;
prog.main();
}
GettyClass.prototype.parseArgs = function(args) {
if (args.length == 1) {

View file

@ -29,7 +29,7 @@ InitClass.prototype.tick = function() {
Emulator.output("\nreseting system runlevel");
OS.runlevel = 0;
Emulator.output("\nloading /etc/inittab.json ...");
var file = Kernel.Filesystem.getFile("/etc/inittab.json");
var file = new File("/etc/inittab.json");
this.files[file.path] = file;
this.inittab = JSON.parse(file.read());
break;
@ -55,7 +55,6 @@ InitClass.prototype.tick = function() {
} else {
this.execProgram();
this.Start.index++;
this.state = 31;
}
break;
case 5:
@ -100,8 +99,8 @@ InitClass.prototype.tick = function() {
}
}
InitClass.prototype.changeRunlevel = function() {
Kernel.Filesystem.update("/tmp/destLevel.1");
var runlevel = Kernel.Filesystem.getFile("/tmp/destLevel.1").read();
var file = new File("/tmp/destLevel.1");
var runlevel = file.read();
this.destLevel = parseInt(runlevel);
this.state = 5;
}
@ -117,34 +116,16 @@ InitClass.prototype.execProgram = function() {
var name = params[0];
var files = this.Start.array[this.Start.index].files;
var pathArray = new Array();
var pid = Kernel.ProcessManager.exec(name, [], false);
var prog = Kernel.ProcessManager.getProcess(pid);
if (files)
for (var i = 0; i < files.length; i++) {
pathArray.push([files[i], this.files[files[i]].path]);
prog.files[files[i]] = this.files[files[i]];
}
var s = "";
s += "var func = function () { ";
s += " try {";
s += " var prog = new " + Kernel.ProcessManager.getClassNameFromFileName(name) + "();";
s += " } catch (exception) {";
s += " console.dir(exception);";
s += " }";
s += " prog.init(1);";
s += " var paths = JSON.parse('" + JSON.stringify(pathArray) + "');";
s += " for(var i = 0; i < paths.length; i++) {";
s += " prog.files[paths[i][0]] = Kernel.Filesystem.getFile(paths[i][1]);";
s += " }";
s += " Kernel.ProcessManager.add(prog);";
s += " console.log(\"init: start command '" + command + "'...\");";
s += " try {";
s += " prog.main(JSON.parse('" + JSON.stringify(params) + "'));";
s += " } catch (exception) {";
s += " console.log(\"Prozess \" + prog.pid + \": \");";
s += " console.dir(exception);";
s += " }";
s += " Kernel.ProcessManager.processList[1].state = 4;";
s += "}";
eval(s);
Kernel.ProcessManager.load(name, func);
console.log("init: starting program " + command)
prog.main(params);
console.log("init: process started with pid: " + prog.pid);
}
InitClass.prototype.signalHandler = function(signal) {
switch(signal) {

View file

@ -5,13 +5,14 @@ LoginClass.prototype.state = 0;
LoginClass.prototype.childList = new Array();
LoginClass.prototype.username;
LoginClass.prototype.password;
LoginClass.prototype.cpassword;
LoginClass.prototype.users;
LoginClass.prototype.user;
LoginClass.prototype.main = function(args) {
console.log("login: loading /lib/sha256.js");
Kernel.ProcessManager.load("/lib/sha256.js", nothing);
Kernel.ProcessManager.lib("/lib/sha256.js");
console.log("login: loading /lib/utf8.js");
Kernel.ProcessManager.load("/lib/utf8.js", nothing);
Kernel.ProcessManager.lib("/lib/utf8.js");
console.log("login: adding to scheduler job list");
Kernel.Scheduler.add(this);
}
@ -33,9 +34,10 @@ LoginClass.prototype.tick = function() {
this.state++;
break;
case 2:
var code = stdin.read();
if (!code)
var char = stdin.read(1);
if (!(char.length))
break;
var code = (new String(char)).charCodeAt(0);
if (KeyCodes.isEnter(code)) {
this.state++;
stdout.write("\n");
@ -48,7 +50,6 @@ LoginClass.prototype.tick = function() {
stdout.write("\033[1D \033[1D");
break;
}
var char = KeyCodes.normalKey(code);
this.username.push(char);
stdout.write(char);
break;
@ -57,9 +58,10 @@ LoginClass.prototype.tick = function() {
this.state++;
break;
case 4:
var code = stdin.read();
if (!code)
var char = stdin.read(1);
if (!char.length)
break;
var code = (new String(char)).charCodeAt(0);
if (KeyCodes.isEnter(code)) {
this.state++;
stdout.write("\n");
@ -71,21 +73,20 @@ LoginClass.prototype.tick = function() {
this.password.pop();
break;
}
var char = KeyCodes.normalKey(code);
this.password.push(char);
break;
case 5:
this.username = this.username.join("");
this.password = Sha256.hash(this.password.join(""));
this.files['passwd'] = Kernel.Filesystem.getFile("/etc/passwd.json");
Kernel.Filesystem.update("/etc/passwd.json");
this.users = JSON.parse(this.files['passwd'].read());
this.cpassword = Sha256.hash(this.password.join(""));
var file = new File("/etc/passwd.json");
this.users = JSON.parse(file.read());
file.close();
this.state++;
break;
case 6:
for (var i = 0; i < this.users.length; i++) {
if (this.users[i].username == this.username) {
if (this.users[i].password == this.password) {
if (this.users[i].password == this.cpassword) {
this.state = 7;
this.user = this.users[i];
}
@ -114,32 +115,14 @@ LoginClass.prototype.tick = function() {
LoginClass.prototype.execProgram = function(user) {
var name = user.shell;
params = [name, user.username, user.home];
var pathArray = new Array();
pathArray[0] = ["stdout", this.files['stdout'].path];
pathArray[1] = ["stdin", this.files['stdin'].path];
var s = "";
s += "var func = function () { ";
s += " try {";
s += " var prog = new " + Kernel.ProcessManager.getClassNameFromFileName(name) + "();";
s += " } catch (exception) {";
s += " console.dir(exception);";
s += " }";
s += " prog.init(" + this.pid + ");";
s += " var paths = JSON.parse('" + JSON.stringify(pathArray) + "');";
s += " for(var i = 0; i < paths.length; i++) {";
s += " prog.files[paths[i][0]] = Kernel.Filesystem.getFile(paths[i][1]);";
s += " }";
s += " Kernel.ProcessManager.add(prog);";
s += " console.log(\"login: start shell '" + name + "'...\");";
s += " try {";
s += " prog.main(JSON.parse('" + JSON.stringify(params) + "'));";
s += " } catch (exception) {";
s += " console.log(\"Prozess \" + prog.pid + \": \");";
s += " console.dir(exception);";
s += " }";
s += "}";
eval(s);
Kernel.ProcessManager.load(name, func);
var pid = Kernel.ProcessManager.exec(name, [], false);
var prog = Kernel.ProcessManager.getProcess(pid);
prog.files['stdin'] = this.files['stdin'];
prog.files['stdout'] = this.files['stdout'];
Kernel.UserManager.changeProcessUser(pid, this.user.username, this.password.join());
this.password = new Array();
console.log("login: program startet: " + name);
prog.main(params);
}
LoginClass.prototype.signalHandler = function(signal) {
switch(signal) {