在 Linux 中,如何从“结构文件"中获取文件名?结构,同时使用 kgdb 遍历内核? [英] In Linux, how can I get the filename from the "struct file" structure, while stepping thru the kernel with kgdb?

查看:26
本文介绍了在 Linux 中,如何从“结构文件"中获取文件名?结构,同时使用 kgdb 遍历内核?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 kgdb 查看文件名,所以我无法调用函数和宏来以编程方式获取它.我需要通过手动检查数据结构来找到它.

I'm trying to view the filename via kgdb, so I cannot call functions and macros to get it programatically. I need to find it by manually inspecting data structures.

就像我在 gdb 中有一个断点一样,我怎么能用 gdb 环顾四周并找到文件名?

Like if I had a breakpoint here in gdb, how could I look around with gdb and find the filename?

我尝试在 filp.f_pathfilp.f_inode 等中环顾四周.我在任何地方都看不到文件名.

I've tried looking around in filp.f_path, filp.f_inode, etc. I cannot see the filename anywhere.

ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
{
     struct iovec iov = { .iov_base = (void __user *)buf, .iov_len = len };
     struct kiocb kiocb;
     ssize_t ret;

     init_sync_kiocb(&kiocb, filp);
     kiocb.ki_pos = *ppos;
     kiocb.ki_left = len;
     kiocb.ki_nbytes = len;

     ret = filp->f_op->aio_write(&kiocb, &iov, 1, kiocb.ki_pos);
     if (-EIOCBQUEUED == ret)
             ret = wait_on_sync_kiocb(&kiocb);
     *ppos = kiocb.ki_pos;
     return ret;
}

推荐答案

在 Linux 内核中,file 结构本质上是内核看到"文件的方式.内核对文件名不感兴趣,只对打开文件的 inode 感兴趣.这意味着对用户很重要的所有其他信息都丢失了.

In the Linux kernel, the file structure is essentially how the kernel "sees" the file. The kernel is not interested in the file name, just the inode of the open file. This means that all of the other information which is important to the user is lost.

这个答案是错误的.您可以使用 filp->f_path.dentry 获取 dentry.从那里您可以使用相关的 FS 标志获取 dentry 的名称或完整路径.

This answer is wrong. You can get the dentry using filp->f_path.dentry. From there you can get the name of the dentry or the full path using the relevant FS flags.

这篇关于在 Linux 中,如何从“结构文件"中获取文件名?结构,同时使用 kgdb 遍历内核?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆