C getdents()系统调用

C getdents()系统调用,c,system-calls,C,System Calls,我试图编写一个getdents()系统调用,列出调用getdents()返回的所有目录项,但我遇到了一个似乎无法解决的小问题,不确定这是一个C错误(因为我还在学习)还是调用本身的问题。当我打印每个结构的d_名称时,我总是缺少目录/文件的第一个字母 Feb 13 11:39:04 node35 kernel: [ 911.353033] entry: ootkit.c Feb 13 11:39:04 node35 kernel: [ 911.353035] entry: ootkit.mod.

我试图编写一个getdents()系统调用,列出调用getdents()返回的所有目录项,但我遇到了一个似乎无法解决的小问题,不确定这是一个C错误(因为我还在学习)还是调用本身的问题。当我打印每个结构的d_名称时,我总是缺少目录/文件的第一个字母

Feb 13 11:39:04 node35 kernel: [  911.353033] entry: ootkit.c
Feb 13 11:39:04 node35 kernel: [  911.353035] entry: ootkit.mod.c
Feb 13 11:39:04 node35 kernel: [  911.353036] entry: ootkit.ko
文件名为rootkit*

我的代码:

asmlinkage int new_getdents(unsigned int fd, struct linux_dirent64 *dirp, unsigned int     count)
{
    int nread;
    int bpos;
    struct linux_dirent64 *d;
    int (*orig_func)(unsigned int fd, struct linux_dirent64 *dirp, unsigned int count);
    t_syscall_hook *open_hook;

    open_hook = find_syscall_hook(__NR_getdents);
    orig_func = (void*) open_hook->orig_func;

    nread = (*orig_func)(fd, dirp, count);
    d = dirp;

    for (bpos = 0; bpos < nread;) {
      d = (struct linux_dirent64 *) ((char*)dirp + bpos);
      printk(KERN_INFO "%s\n", d->d_name);
      bpos += d->d_reclen;
    }

    return nread;
}
asmlinkage int new\u getdents(unsigned int fd,struct linux\u dirent64*dirp,unsigned int count)
{
国际nread;
int BPO;
struct linux_dirent64*d;
int(*orig_func)(无符号int fd,结构linux_dirent64*dirp,无符号int count);
t_syscall_hook*open_hook;
open_hook=find_syscall_hook(uu NR_getdents);
原始函数=(void*)打开钩子->原始函数;
nread=(*orig_func)(fd、dirp、count);
d=dirp;
对于(bpos=0;bposd\u名称);
bpos+=d->d_recen;
}
返回nread;
}

我最好的猜测是您混淆了
getdents
syscall的遗留版本和“64”版本。即使在64位系统上,除了(正确的)之外,似乎还有一个遗留版本(没有64位)编写的结构缺少
d_类型
成员(因此,如果使用的是结构的现代“64”版本,则名称的第一个字符将被误解为
d_类型
成员)
getdents64
syscall.

“…是rootkit。”那么你在做什么呢?;->也许OP应该保留这个bug。将rootkit文件显示为“ootkit”是隐藏它们的好方法…;-)我的意思是所有的文件都被命名为rootkit.*其中*可以是很多东西。对不起,语法错误。非常感谢!我的操作系统实际上使用的是传统版本的getdents!