more modprobe work, still not functionnal

This commit is contained in:
Marc
2022-02-01 23:22:55 +01:00
parent 752be3d9a8
commit 80e8d184ab
+43 -2
View File
@@ -1,3 +1,44 @@
const { modprobe } = require('/chibrax/kernel.js')
if(process.argv[3])modprobe(process.argv[3])
//@ts-check
const { finit_module, uname } = require('../../chibrax/kernel.js')
const fs = require('fs')
const path = require('path')
const name = uname()
const modulePath = path.join('/lib/modules', name, 'kernel')
if(process.argv[3]) {
let filename = process.argv[3]
if(!filename.endsWith('.ko')) {
filename += '.ko'
}
const kernModule = findmodule(modulePath, filename)
if(kernModule) {
finit_module(kernModule)
} else {
console.log('module not found')
}
}
else console.log("missing argument")
/**
* @param { string } modulesPath
* @param { string } moduleName
* @returns {string | null }
*/
function findmodule(modulesPath, moduleName) {
if (fs.existsSync(path.join(modulesPath, moduleName))) {
return path.join(modulesPath, moduleName)
}
const subfiles = fs.readdirSync(modulesPath, { withFileTypes: true })
for (const file of subfiles) {
if(file.isDirectory()) {
const foundModule = findmodule(path.join(modulesPath, file.name), moduleName)
if(foundModule) {
return foundModule
}
}
}
return null
}