summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-11-25 18:42:44 +0100
committerAlexis211 <alexis211@gmail.com>2009-11-25 18:42:44 +0100
commita40fe1166ab1db972a8ca0380d603c4d90eede62 (patch)
treef92c2c02d9d78d68f7c116dff9ac508895f757af /Source
parentf367fe4e5a7712bafc121ce5c228f15e90fc5c93 (diff)
downloadMelon-a40fe1166ab1db972a8ca0380d603c4d90eede62.tar.gz
Melon-a40fe1166ab1db972a8ca0380d603c4d90eede62.zip
Re-organized file system stuff.
Diffstat (limited to 'Source')
-rw-r--r--Source/Applications/Demos/GOL.cpp5
-rw-r--r--Source/Kernel/Core/Log.ns.cpp5
-rw-r--r--Source/Kernel/Core/kmain.wtf.cpp58
-rw-r--r--Source/Kernel/UserManager/Usr.ns.cpp26
-rw-r--r--Source/Kernel/VFS/File.class.cpp3
-rw-r--r--Source/Kernel/VFS/Part.ns.cpp27
-rw-r--r--Source/Kernel/VFS/Part.ns.h3
-rw-r--r--Source/Library/Common/BasicString.class.cpp1
-rw-r--r--Source/Library/Common/BasicString.class.h2
-rw-r--r--Source/Library/Common/String.class.cpp1
-rw-r--r--Source/Library/Common/String.class.h2
11 files changed, 113 insertions, 20 deletions
diff --git a/Source/Applications/Demos/GOL.cpp b/Source/Applications/Demos/GOL.cpp
index 32eb30a..298c73a 100644
--- a/Source/Applications/Demos/GOL.cpp
+++ b/Source/Applications/Demos/GOL.cpp
@@ -1,6 +1,7 @@
#include <Binding/VirtualTerminal.class.h>
#include <Binding/Thread.class.h>
#include <String.class.h>
+#include <ByteArray.class.h>
#include <Rand.ns.h>
int main(Vector<String> args) {
@@ -22,7 +23,7 @@ int main(Vector<String> args) {
}
}
- char *tmp = new char[w * h + 1];
+ ByteArray tmp((w + 1) * (h + 1));
bool run = true;
while (run) {
@@ -37,7 +38,7 @@ int main(Vector<String> args) {
}
}
outvt.moveCursor(0, 0);
- outvt << String(tmp, w*h) << "Press Ctrl+h for help";
+ outvt << tmp.toString() << "Press Ctrl+h for help";
//Compute next generation
for (int y = 0; y < h; y++) {
diff --git a/Source/Kernel/Core/Log.ns.cpp b/Source/Kernel/Core/Log.ns.cpp
index 1727024..c8ccd80 100644
--- a/Source/Kernel/Core/Log.ns.cpp
+++ b/Source/Kernel/Core/Log.ns.cpp
@@ -1,4 +1,5 @@
#include "Log.ns.h"
+#include <FileSystems/RamFS/RamFS.class.h>
#include <VFS/VFS.ns.h>
namespace Log {
@@ -11,6 +12,10 @@ void init(u8int loglevel) {
if (VFS::find("/System/Logs") == 0) VFS::createDirectory("/System/Logs");
logs[KL_PANIC] = new TextFile("/System/Logs/Panic.log", FM_APPEND);
+ if (!logs[KL_PANIC]->valid()) { //FS maybee not read/write, mount a ramfs
+ RamFS::mount(1024*1024, (DirectoryNode*)VFS::find("/System/Logs"));
+ logs[KL_PANIC] = new TextFile("/System/Logs/Panic.log", FM_APPEND);
+ }
if (KL_CRITICAL <= loglevel) logs[KL_CRITICAL] = new TextFile("/System/Logs/Critical.log", FM_APPEND);
if (KL_ERROR <= loglevel) logs[KL_ERROR] = new TextFile("/System/Logs/Error.log", FM_APPEND);
if (KL_WARNING <= loglevel) logs[KL_WARNING] = new TextFile("/System/Logs/Warning.log", FM_APPEND);
diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp
index bb77eeb..1d438ed 100644
--- a/Source/Kernel/Core/kmain.wtf.cpp
+++ b/Source/Kernel/Core/kmain.wtf.cpp
@@ -115,6 +115,43 @@ void selectVideoMode(SimpleVT& v) {
}
}
+bool mountFS(multiboot_info_t* mbd, String str) {
+ module_t *mods = (module_t*)mbd->mods_addr;
+ Vector<String> fs = str.split(":");
+ DirectoryNode* root;
+ if (fs[0] == "/") {
+ root = NULL;
+ } else {
+ FSNode* n = VFS::find(fs[0]);
+ if (n == NULL) {
+ *kvt << "Mountpoint does not exist : " << fs[0] << "\n";
+ return false;
+ }
+ if (n->type() != NT_DIRECTORY) {
+ *kvt << "Mountpoint is not a directory : " << fs[0] << "\n";
+ return false;
+ }
+ root = (DirectoryNode*)n;
+ }
+ if (fs[1] == "ramfs") {
+ if (fs[2].toInt() >= mbd->mods_count) {
+ *kvt << "Invalid module number for filesystem to mount on " << fs[0] << "\n";
+ return false;
+ }
+ RamFS::mount((u8int*)mods[fs[2].toInt()].mod_start, 1024 * 1024, root);
+ } else {
+ if (fs.size() < 5) fs.push("fat");
+ BlockDevice* d = Part::dev(fs[1], fs[2].toInt());
+ Partition* p = Part::part(d, fs[3].toInt());
+ if (fs[4] == "fat") {
+ FATFS::mount(p, root);
+ } else {
+ PANIC("Unknown filesystem type for root file system.");
+ }
+ }
+ return true;
+}
+
void kmain(multiboot_info_t* mbd, u32int magic) {
DEBUG("Entering kmain.");
@@ -167,13 +204,17 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
//*************************************** PARSE COMMAND LINE
Vector<String> opts = kcmdline.split(" ");
- String keymap = "fr", init = "/System/Applications/PaperWork.app";
+ String keymap = "builtin", init = "/System/Applications/PaperWork.app";
+ String root = "ramfs:0";
+ Vector<String> mount;
bool enableVESA = true;
for (u32int i = 0; i < opts.size(); i++) {
Vector<String> opt = opts[i].split(":");
if (opt[0] == "vesa" && opt[1] != "enabled") enableVESA = false;
if (opt[0] == "keymap") keymap = opt[1];
if (opt[0] == "init") init = opt[1];
+ if (opt[0] == "root") root = opts[i].substr(5);
+ if (opt[0] == "mount") mount.push(opts[i].substr(6));
}
//*************************************** DEVICE SETUP
@@ -183,14 +224,23 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
if (enableVESA) Dev::registerDevice(new VESADisplay());
FloppyController::detect();
- //*************************************** MOUNT ROOT FILESYSTEM
+ //*************************************** MOUNT FILESYSTEMS
- RamFS::mount((u8int*)mods[0].mod_start, 1024 * 1024, NULL);
+ { // mount root filesystem
+ if (!mountFS(mbd, String("/:") += root)) PANIC("Cannot mount root filesystem.");
+ }
DirectoryNode* cwd;
cwd = VFS::getRootNode();
Task::currProcess()->setCwd(cwd);
- FATFS::mount(Part::partitions[0], (DirectoryNode*)VFS::createDirectory("/Mount"));
+ // mount other filesystems
+ for (u32int i = 0; i < mount.size(); i++) {
+ mountFS(mbd, mount[i]);
+ }
+
+ //FATFS::mount(Part::partitions[0], (DirectoryNode*)VFS::createDirectory("/Mount"));
+
+ //*************************************** LOAD SYSTEM STUFF
if (keymap != "builtin") {
if (!Kbd::loadKeymap(keymap)) *kvt << "\nWARNING : Could not load keymap " << keymap << ", using built-in keymap instead.";
diff --git a/Source/Kernel/UserManager/Usr.ns.cpp b/Source/Kernel/UserManager/Usr.ns.cpp
index ecf9bae..66e159e 100644
--- a/Source/Kernel/UserManager/Usr.ns.cpp
+++ b/Source/Kernel/UserManager/Usr.ns.cpp
@@ -26,11 +26,13 @@ void load() {
if (VFS::find("/System/Configuration/Groups")) VFS::find("/System/Configuration/Groups")->setPermissions(0600);
if (VFS::find("/System/Configuration/Users")) VFS::find("/System/Configuration/Users")->setPermissions(0600);
TextFile groups("/System/Configuration/Groups", FM_READ);
- while (!groups.eof()) {
- String s = groups.readLine();
- Vector<String> data = s.split(":");
- if (data.size() == 2 and !(s[0] == WChar("#"))) {
- m_groups = m_groups->cons(Group(data[1], data[0].toInt()));
+ if (groups.valid()) {
+ while (!groups.eof()) {
+ String s = groups.readLine();
+ Vector<String> data = s.split(":");
+ if (data.size() == 2 and !(s[0] == WChar("#"))) {
+ m_groups = m_groups->cons(Group(data[1], data[0].toInt()));
+ }
}
}
if (m_groups == 0) {
@@ -39,12 +41,14 @@ void load() {
}
TextFile users("/System/Configuration/Users", FM_READ);
- while (!users.eof()) {
- String s = users.readLine();
- if (s == "" or s[0] == WChar("#")) continue;
- Vector<String> data = s.split(":");
- if (data.size() == 6) {
- m_users = m_users->cons(User(data[1], data[4], data[5], group(data[2].toInt()), data[3], data[0].toInt()));
+ if (users.valid()) {
+ while (!users.eof()) {
+ String s = users.readLine();
+ if (s == "" or s[0] == WChar("#")) continue;
+ Vector<String> data = s.split(":");
+ if (data.size() == 6) {
+ m_users = m_users->cons(User(data[1], data[4], data[5], group(data[2].toInt()), data[3], data[0].toInt()));
+ }
}
}
if (m_users == 0) {
diff --git a/Source/Kernel/VFS/File.class.cpp b/Source/Kernel/VFS/File.class.cpp
index c5ddcd6..84561a5 100644
--- a/Source/Kernel/VFS/File.class.cpp
+++ b/Source/Kernel/VFS/File.class.cpp
@@ -33,7 +33,7 @@ bool File::open(String filename, u8int mode, FSNode* start, bool vrfyperm) {
if (node == NULL){
if (mode == FM_READ) return false;
node = VFS::createFile(filename, start, vrfyperm);
- if (node == 0) return false;
+ if (node == NULL) return false;
}
if (node->type() != NT_FILE) return false;
@@ -137,6 +137,7 @@ bool File::seek(u64int count, u8int mode) {
}
bool File::eof() {
+ if (!m_valid) return false;
return m_position == m_file->getLength();
}
diff --git a/Source/Kernel/VFS/Part.ns.cpp b/Source/Kernel/VFS/Part.ns.cpp
index 6408dbd..7184f90 100644
--- a/Source/Kernel/VFS/Part.ns.cpp
+++ b/Source/Kernel/VFS/Part.ns.cpp
@@ -56,4 +56,31 @@ u32int getDeviceID(BlockDevice* dev) {
return (u32int) - 1;
}
+BlockDevice* dev(String _class, u32int idx) {
+ for (u32int i = 0; i < devices.size(); i++) {
+ String devclass = devices[i]->getClass();
+ if (devclass == _class or (devclass.size() > _class.size() and devclass.substr(0, _class.size()) == _class)) {
+ if (idx == 0) {
+ return devices[i];
+ } else {
+ idx--;
+ }
+ }
+ }
+ return NULL;
+}
+
+Partition* part(BlockDevice* dev, u32int idx) {
+ for (u32int i = 0; i < partitions.size(); i++) {
+ if (partitions[i]->getDevice() == dev) {
+ if (idx == 0) {
+ return partitions[i];
+ } else {
+ idx--;
+ }
+ }
+ }
+ return NULL;
+}
+
}
diff --git a/Source/Kernel/VFS/Part.ns.h b/Source/Kernel/VFS/Part.ns.h
index 40a0fb2..4373a2d 100644
--- a/Source/Kernel/VFS/Part.ns.h
+++ b/Source/Kernel/VFS/Part.ns.h
@@ -13,6 +13,9 @@ namespace Part {
void unregisterDevice(BlockDevice* dev);
u32int getDeviceID(BlockDevice* dev);
+
+ BlockDevice* dev(String _class, u32int idx);
+ Partition* part(BlockDevice* dev, u32int idx);
}
#endif
diff --git a/Source/Library/Common/BasicString.class.cpp b/Source/Library/Common/BasicString.class.cpp
index f3a6164..58fa926 100644
--- a/Source/Library/Common/BasicString.class.cpp
+++ b/Source/Library/Common/BasicString.class.cpp
@@ -175,6 +175,7 @@ Vector< BasicString<T> > BasicString<T>::split(T sep) const {
template <typename T>
BasicString<T> BasicString<T>::substr(s32int start, u32int size) {
if (start < 0) start = m_length - start;
+ if (size == 0) size = m_length - start;
BasicString<T> ret;
ret.m_string = new T[size + 1];
ret.m_length = size;
diff --git a/Source/Library/Common/BasicString.class.h b/Source/Library/Common/BasicString.class.h
index 21041e8..be74cf3 100644
--- a/Source/Library/Common/BasicString.class.h
+++ b/Source/Library/Common/BasicString.class.h
@@ -46,7 +46,7 @@ class BasicString {
bool contains(const T& chr) const;
Vector< BasicString<T> > split(T sep) const;
- BasicString<T> substr(s32int start, u32int size);
+ BasicString<T> substr(s32int start, u32int size = 0);
};
#include "BasicString.class.cpp"
diff --git a/Source/Library/Common/String.class.cpp b/Source/Library/Common/String.class.cpp
index a824eac..da2b93e 100644
--- a/Source/Library/Common/String.class.cpp
+++ b/Source/Library/Common/String.class.cpp
@@ -193,6 +193,7 @@ Vector<String> String::split(WChar c) const {
String String::substr(s32int start, u32int size) {
if (start < 0) start = m_length - start;
+ if (size == 0) size = m_length - start;
String ret;
ret.m_string = new WChar[size + 1];
ret.m_length = size;
diff --git a/Source/Library/Common/String.class.h b/Source/Library/Common/String.class.h
index 0d48ce6..473624b 100644
--- a/Source/Library/Common/String.class.h
+++ b/Source/Library/Common/String.class.h
@@ -43,7 +43,7 @@ class String : public BasicString<WChar> {
Vector<String> split(WChar c) const;
- String substr(s32int start, u32int size);
+ String substr(s32int start, u32int size = 0);
};
#endif