我寫了一些像1年前的freebsd內核模塊,當時他們工作正常。但現在我無法編譯。FreeBSD從另一個系統調用發出系統調用
我想要做的是通過修改同義表來掛鉤現有的系統調用。
static int
mkdir_hook (struct proc *p, struct mkdir_args *ua)
{
printf("Making dir: %s\n", ua->path);
return mkdir(p, ua);
}
static int
load (struct module *module, int cmd, void *arg)
{
int error = 0;
switch (cmd) {
case MOD_LOAD :
sysent[SYS_mkdir]=mkdir_hook_sysent;
break;
case MOD_UNLOAD :
sysent[SYS_mkdir].sy_call=(sy_call_t*)mkdir;
break;
default :
error = EINVAL;
break;
}
return error;
}
我收到以下錯誤
test.c:21: warning: implicit declaration of function 'mkdir'
test.c:21: warning: nested extern declaration of 'mkdir' [-Wnested-externs]
test.c:49: error: 'mkdir' undeclared (first use in this function)
test.c:49: error: (Each undeclared identifier is reported only once
test.c:49: error: for each function it appears in.)
所以我想可能是缺少庫。這裏是我的包括
#include <sys/types.h>
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/module.h>
#include <sys/sysent.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/linker.h>
#include <sys/sysproto.h>
#include <sys/sysent.h>
#include <sys/proc.h>
#include <sys/syscall.h>
我讀man 2 mkdir
,仍然沒有線索。看起來,不再支持從內核模塊調用另一個系統調用,或者它需要額外的配置?
請大家幫忙,非常感謝。
在/usr/src/sys/sys/sysent.h中找到它, '「sys /」#name,'tyvm – bestwc 2013-02-22 06:47:42