我正在尝试编写getdents()系统调用,以列出通过调用getdents()返回的所有目录条目,但是我遇到了一个似乎无法解决的小问题,不确定这是否是C错误( (因为我仍在学习)或电话本身。当我打印每个结构的d_name时,我总是缺少目录/文件的首字母。
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;
}
最佳答案
我最好的猜测是您混合了getdents
syscall的旧版和“ 64”版。即使在64位系统上,似乎也有一个旧版本(没有64位),该版本编写的结构缺少d_type
成员(因此,如果您使用的是该名称的第一个字符,则会被误解为d_type
成员)除了(正确的)getdents64
syscall外,还使用现代的“ 64”版本结构。
关于c - getdents()系统调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21760212/