| |
| /pliant/linux/kernel/module.pli |
| |
| 1 |
module "/pliant/language/stream.pli" | |
| 2 |
module "/pliant/admin/execute.pli" | |
| 3 |
module "/pliant/fullpliant/this_computer.pli" | |
| 4 |
| |
| 5 |
| |
| 6 |
function real_module name -> module | |
| 7 |
arg Str name module | |
| 8 |
module := this_computer:env:"kernel":"module":name | |
| 9 |
if module="" | |
| 10 |
module := name | |
| 11 |
| |
| 12 |
| |
| 13 |
function kernel_load_module name options -> status | |
| 14 |
arg Str name options ; arg ExtendedStatus status | |
| 15 |
var Str module := real_module name | |
| 16 |
(var Stream s) open "file:/proc/modules" in+safe | |
| 17 |
while not s:atend | |
| 18 |
if ((replace s:readline "-" "_") parse pattern:(replace module "-" "_") _ any) | |
| 19 |
return failure:"already loaded" | |
| 20 |
if (execute "insmod "+module+(shunt options<>"" " "+options "") quiet)<>0 | |
| 21 |
status := failure "module not found" | |
| 22 |
(var Stream s) open "file:/proc/sys/kernel/osrelease" in+safe | |
| 23 |
var Str version := s readline | |
| 24 |
(var Stream s) open (shunt this_computer:env:"pliant":"system":"medium"="cdrom" "file:/tmp/modules.dep" "file:/lib/modules/"+version+"/modules.dep") in+safe | |
| 25 |
while not s:atend | |
| 26 |
var Str l := s readline | |
| 27 |
while l<>"" and (l l:len-1 1)="/" | |
| 28 |
l := (l 0 l:len-1)+s:readline | |
| 29 |
if (l parse any:(var Str m) ":" any:(var Str d)) | |
| 30 |
var Str b := m | |
| 31 |
b := b (b search_last "/" -1)+1 b:len | |
| 32 |
b := b 0 (b search_last "." b:len) | |
| 33 |
if (replace b "-" "_")=(replace module "-" "_") | |
| 34 |
while d<>"" | |
| 35 |
if not (d parse any:(var Str d1) _ any:(var Str remain)) | |
| 36 |
d parse any:(var Str d1) ; remain := "" | |
| 37 |
d1 := d1 (d1 search_last "/" -1)+1 d1:len | |
| 38 |
d1 := d1 0 (d1 search "." d1:len) | |
| 39 |
kernel_load_module d1 "" | |
| 40 |
d := remain | |
| 41 |
var Int err := execute "insmod "+m+(shunt options<>"" " "+options "") quiet | |
| 42 |
status := shunt err=0 success failure:"failed to load the module" | |
| 43 |
# sleep 5 | |
| 44 |
| |
| 45 |
function kernel_load_module name -> status | |
| 46 |
arg Str name ; arg ExtendedStatus status | |
| 47 |
status := kernel_load_module name "" | |
| 48 |
| |
| 49 |
function kernel_unload_module name | |
| 50 |
arg Str name | |
| 51 |
execute "rmmod "+real_module:name quiet | |
| 52 |
| |
| 53 |
| |
| 54 |
export kernel_load_module kernel_unload_module | |
| 55 |
| |
| |