aboutsummaryrefslogtreecommitdiffstats
path: root/libfsosystem
diff options
context:
space:
mode:
authorMichael 'Mickey' Lauer <mickey@vanille-media.de>2011-01-03 00:30:55 +0100
committerMichael 'Mickey' Lauer <mickey@vanille-media.de>2011-01-03 00:30:55 +0100
commit1ec85893612e1d1718d06322ace205fc97086c5c (patch)
treec842dd8a05dd703e77cd2d82d91716e56d531223 /libfsosystem
parent7daa90d90de07fbf52c6add34511eee13a0ead20 (diff)
downloadcornucopia-1ec85893612e1d1718d06322ace205fc97086c5c.tar.gz
cornucopia-1ec85893612e1d1718d06322ace205fc97086c5c.tar.bz2
cornucopia-1ec85893612e1d1718d06322ace205fc97086c5c.zip
libfsosystem: add insertModule and removeModule
Diffstat (limited to 'libfsosystem')
-rw-r--r--libfsosystem/fsosystem/modules.vala53
-rw-r--r--libfsosystem/tests/testmodules.vala20
2 files changed, 65 insertions, 8 deletions
diff --git a/libfsosystem/fsosystem/modules.vala b/libfsosystem/fsosystem/modules.vala
index 9b64cc16..fbfba5a0 100644
--- a/libfsosystem/fsosystem/modules.vala
+++ b/libfsosystem/fsosystem/modules.vala
@@ -17,15 +17,60 @@
*
*/
+public errordomain SystemError
+{
+ ERROR
+}
+
/* libc */
-extern int init_module( string name, void* data );
+extern long init_module( void* data, ulong length, string options );
+extern long delete_module( string name, uint flags );
namespace FsoFramework { namespace Kernel {
-public bool loadModule( string name )
+/**
+ * Insert a module into the running kernel
+ **/
+public void insertModule( string filename, string? options = null ) throws Error
+{
+ uint8[] contents;
+ FileUtils.get_data( filename, out contents );
+
+ var ok = init_module( contents, contents.length, options );
+ if ( ok != 0 )
+ {
+ throw new SystemError.ERROR( @"Can't insert module: $(strerror(errno))" );
+ }
+}
+
+/**
+ * Remove a module out of the running kernel
+ **/
+public void removeModule( string filename, bool wait = false, bool force = false ) throws Error
+{
+ uint flags = Posix.O_EXCL | Posix.O_NONBLOCK;
+ if ( wait )
+ {
+ flags &= ~Posix.O_NONBLOCK;
+ }
+ if ( force )
+ {
+ flags |= Posix.O_TRUNC;
+ }
+
+ var ok = delete_module( filename, flags );
+ if ( ok != 0 )
+ {
+ throw new SystemError.ERROR( @"Can't insert module: $(strerror(errno))" );
+ }
+}
+
+/**
+ * Load a module and its dependencies into the running kernel
+ **/
+public void probeModule( string modulename, string? options = null )
{
- message( "yo" );
- return true;
+ throw new SystemError.ERROR( @"Not yet implemented" );
}
} /* namespace Kernel */
diff --git a/libfsosystem/tests/testmodules.vala b/libfsosystem/tests/testmodules.vala
index 6ec404bc..53303fc4 100644
--- a/libfsosystem/tests/testmodules.vala
+++ b/libfsosystem/tests/testmodules.vala
@@ -20,11 +20,21 @@
using GLib;
//===========================================================================
-void test_modules_load()
+void test_modules_insert()
+{
+ FsoFramework.Kernel.insertModule( "/lib/modules/2.6.35-23-generic/kernel/drivers/block/floppy.ko" );
+}
+
+//===========================================================================
+void test_modules_remove()
+{
+ FsoFramework.Kernel.removeModule( "/lib/modules/2.6.35-23-generic/kernel/drivers/block/floppy.ko" );
+}
+
//===========================================================================
+void test_modules_probe()
{
- bool ok = FsoFramework.Kernel.loadModule( "/lib/modules/2.6.35-23-generic/kernel/drivers/block/floppy.ko" );
- assert( ok );
+ FsoFramework.Kernel.probeModule( "mtdblock" );
}
//===========================================================================
@@ -33,7 +43,9 @@ void main( string[] args )
{
Test.init( ref args );
- Test.add_func( "/Modules/Load", test_modules_load );
+ Test.add_func( "/Modules/Insert", test_modules_insert );
+ Test.add_func( "/Modules/Remove", test_modules_remove );
+ Test.add_func( "/Modules/Probe", test_modules_probe );
Test.run();
}