diff options
author | Alexis211 <alexis211@gmail.com> | 2009-11-25 18:42:44 +0100 |
---|---|---|
committer | Alexis211 <alexis211@gmail.com> | 2009-11-25 18:42:44 +0100 |
commit | a40fe1166ab1db972a8ca0380d603c4d90eede62 (patch) | |
tree | f92c2c02d9d78d68f7c116dff9ac508895f757af | |
parent | f367fe4e5a7712bafc121ce5c228f15e90fc5c93 (diff) | |
download | Melon-a40fe1166ab1db972a8ca0380d603c4d90eede62.tar.gz Melon-a40fe1166ab1db972a8ca0380d603c4d90eede62.zip |
Re-organized file system stuff.
-rwxr-xr-x | CopyToFDD.sh | 26 | ||||
-rwxr-xr-x | CopyToHDD.sh | 34 | ||||
-rw-r--r-- | Grub-menu-fdd.cfg | 27 | ||||
-rw-r--r-- | Grub-menu-hdd.cfg | 22 | ||||
-rw-r--r-- | Grub-menu.cfg | 29 | ||||
-rw-r--r-- | Makefile | 29 | ||||
-rw-r--r-- | README | 5 | ||||
-rw-r--r-- | Source/Applications/Demos/GOL.cpp | 5 | ||||
-rw-r--r-- | Source/Kernel/Core/Log.ns.cpp | 5 | ||||
-rw-r--r-- | Source/Kernel/Core/kmain.wtf.cpp | 58 | ||||
-rw-r--r-- | Source/Kernel/UserManager/Usr.ns.cpp | 26 | ||||
-rw-r--r-- | Source/Kernel/VFS/File.class.cpp | 3 | ||||
-rw-r--r-- | Source/Kernel/VFS/Part.ns.cpp | 27 | ||||
-rw-r--r-- | Source/Kernel/VFS/Part.ns.h | 3 | ||||
-rw-r--r-- | Source/Library/Common/BasicString.class.cpp | 1 | ||||
-rw-r--r-- | Source/Library/Common/BasicString.class.h | 2 | ||||
-rw-r--r-- | Source/Library/Common/String.class.cpp | 1 | ||||
-rw-r--r-- | Source/Library/Common/String.class.h | 2 |
18 files changed, 245 insertions, 60 deletions
diff --git a/CopyToFDD.sh b/CopyToFDD.sh new file mode 100755 index 0000000..5d6a28e --- /dev/null +++ b/CopyToFDD.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +# We assume Mount/ is the directory where the image is mounted, and Source/ is the directory with all the compiled files + +# Update GRUB's menu.cfg +cp Grub-menu-fdd.cfg Mount/boot/menu.cfg + +# Create directories +mkdir Mount/{System,Apps,Mount} +mkdir Mount/System/{Applications,Logs,Configuration} + +# Copy system files +cp Source/Kernel/Ressources/Configuration/* Mount/System/Configuration +cp Source/Applications/PaperWork/PaperWork Mount/System/Applications/PaperWork.app +cp Source/Applications/Shell/Shell Mount/Apps/Shell.app + +# Copy demo apps +cp Source/Applications/Demos/GOL Mount/Apps/GOL.app +cp Source/Applications/Demos/asmdemo Mount/Apps/ASM.dem + +# Copy kernel and ramfs +cp Source/Kernel/Melon.ke Mount/System +cp Init.rfs Mount/System + +#echo "*** Launching a BASH shell, if you want to do any maintenance ***" +#bash || exit 0 diff --git a/CopyToHDD.sh b/CopyToHDD.sh new file mode 100755 index 0000000..eb6f82c --- /dev/null +++ b/CopyToHDD.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +# We assume Mount/ is the directory where the image is mounted, and Source/ is the directory with all the compiled files + +# GRUB is already installed to image, just update config file if needed +cp Grub-menu-hdd.cfg Mount/grub/menu.lst + +# Create directories +mkdir Mount/System +mkdir Mount/System/{Applications,Configuration,Logs,Keymaps} +mkdir Mount/Applications +mkdir Mount/Applications/{Demos,Shell} + +# Copy welcome text +cp Source/Kernel/Ressources/Texts/Welcome.txt Mount + +# Copy kernel and initramfs +cp Source/Kernel/Melon.ke Mount/System +cp Init.rfs Mount/System + +# Copy system ressources +cp Source/Kernel/Ressources/Configuration/* Mount/System/Configuration +cp Source/Kernel/Ressources/Keymaps/*.mkm Mount/System/Keymaps +cp Source/Applications/PaperWork/PaperWork Mount/System/Applications/PaperWork.app +cp Source/Applications/Shell/Shell Mount/Applications/Shell/Shell.app +cp Source/Applications/Shell/Help.txt Mount/Applications/Shell + +# Copy demo apps +cp Source/Applications/Demos/GOL Mount/Applications/Demos/GOL.app +cp Source/Applications/Demos/asmdemo Mount/Applications/Demos/ASMDemo.app +cp Source/Applications/Demos/cxxdemo Mount/Applications/Demos/CPPDemo.app + +echo "*** Launching a BASH shell, if you want to do any maintenance ***" +bash || exit 0 diff --git a/Grub-menu-fdd.cfg b/Grub-menu-fdd.cfg new file mode 100644 index 0000000..578b58d --- /dev/null +++ b/Grub-menu-fdd.cfg @@ -0,0 +1,27 @@ +default 2 + +title The Melon Operating System +root (fd0) +kernel /System/Melon.ke +module /System/Init.rfs + +title Melon without VESA +root (fd0) +kernel /System/Melon.ke vesa:disabled +module /System/Init.rfs + +title Melon without init +root (fd0) +kernel /System/Melon.ke init: +module /System/Init.rfs + +title Melon without init, root is floppy +root (fd0) +kernel /System/Melon.ke init: root:block.floppy:0:0 mount:/Mount:ramfs:0 +module /System/Init.rfs + +title Game of life simulator +root (fd0) +kernel /System/Melon.ke init:/Applications/Demos/GOL.app +module /System/Init.rfs + diff --git a/Grub-menu-hdd.cfg b/Grub-menu-hdd.cfg new file mode 100644 index 0000000..d5b8612 --- /dev/null +++ b/Grub-menu-hdd.cfg @@ -0,0 +1,22 @@ +default 2 + +title The Melon Operating System +root (hd0,0) +kernel /System/Melon.ke +module /System/Init.rfs + +title Melon without VESA +root (hd0,0) +kernel /System/Melon.ke vesa:disabled +module /System/Init.rfs + +title Melon without init +root (hd0,0) +kernel /System/Melon.ke init: +module /System/Init.rfs + +title Game of life simulator +root (hd0,0) +kernel /System/Melon.ke init:/Applications/Demos/GOL.app +module /System/Init.rfs + diff --git a/Grub-menu.cfg b/Grub-menu.cfg deleted file mode 100644 index 5fe0cf5..0000000 --- a/Grub-menu.cfg +++ /dev/null @@ -1,29 +0,0 @@ -default 2 - -title The Melon Operating System -root (fd0) -kernel /Melon.ke -module /Init.rfs - -title Melon without VESA -root (fd0) -kernel /Melon.ke vesa:disabled -module /Init.rfs - -title Melon without init -root (fd0) -kernel /Melon.ke init: -module /Init.rfs - -title Game of life simulator -root (fd0) -kernel /Melon.ke init:/Applications/Demos/GOL.app -module /Init.rfs - -#kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk -#kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk -#ooooooooooooooooooooooooooooooooooooooooooooooooooo -#--------------------------------------------------- - - -#@.@ @@ -21,6 +21,7 @@ RamFSFiles = :/System :/System/Applications :/System/Configuration :/System/Keym Files = $(Kernel) $(RamFS) Floppy = Melon.img +HDD = HDD.img all: for p in $(Projects); do \ @@ -56,26 +57,32 @@ commit: mrproper $(RamFS): Source/Tools/MakeRamFS/MakeRamFS $(RamFS) $(RamFSFiles) -floppy: $(Files) +$(Floppy): $(Files) mkdir Mount; exit 0 sudo mount $(Floppy) Mount -o loop - sudo cp Grub-menu.cfg Mount/boot/menu.cfg - for f in $(Files); do \ - sudo cp $$f Mount; \ - done - sudo cp Source/Applications/Demos/GOL Mount/GOL.app - sudo cp Source/Applications/Demos/asmdemo Mount/ASM.dem + sudo ./CopyToFDD.sh sleep 0.4 sudo umount Mount -bochs: +$(HDD): $(Kernel) + mkdir Mount; exit 0 + sudo losetup -o 32256 /dev/loop3 $(HDD) + sudo mount /dev/loop3 Mount + sudo ./CopyToHDD.sh + sudo umount /dev/loop3 + sudo losetup -d /dev/loop3 + +bochs: $(Floppy) bochs -f Bochs.cfg -qemu: - qemu -fda $(Floppy) -m 16 +qemu: $(Floppy) + qemu -fda $(Floppy) -hda $(HDD) -boot a -m 16 + +qemu-hdd: $(HDD) + qemu -fda $(Floppy) -hda $(HDD) -boot c -m 16 qemu_debug: - qemu -fda $(Floppy) -m 16 -s -S & gdb Source/Kernel/Melon.ke -x Qemu-GDB-Debug-CMD + qemu -fda $(Floppy) -hda $(HDD) -boot a -m 16 -s -S & gdb Source/Kernel/Melon.ke -x Qemu-GDB-Debug-CMD stats: echo; echo " ** Statistics for project O3S ** "; \ @@ -32,3 +32,8 @@ The options for the kernel command line are the following : - init:<init_app> select the init application to run. empty string = go to kernel shell. default is /System/Applications/PaperWork.app +** About HDD.img ** +This file is not used yet, although it is attached to the qemu and bochs VMs. +Its content can be updated with `make hdd`, the file copying happens in CopyToHDD.sh. +For the moment, we use a boot floppy for loading the kernel as the floppy is the only thing the kernel can read for now, +but we could as well use the GRUB that is installed on HDD.img. 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 |