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

查看:173
本文介绍了在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标志获得牙科的名称或完整路径.

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天全站免登陆