gpt4 book ai didi

c - getdents() 系统调用

转载 作者:行者123 更新时间:2023-12-04 21:03:18 24 4
gpt4 key购买 nike

我正在尝试编写一个 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 系统调用的遗留版本和“64”版本。即使在 64 位系统上,似乎也有一个遗留版本(没有 64)编写了一个缺少 d_type 成员的结构(因此名称的第一个字符会被误解为 d_type 成员,如果您使用结构的现代“64”版本)除了(正确的)getdents64 系统调用。

关于c - getdents() 系统调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21760212/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com