Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Linux, how can I get the filename from the "struct file" structure, while stepping thru the kernel with kgdb?

Tags:

linux-kernel

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.

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

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;
}
like image 651
Joe C Avatar asked Jul 26 '13 15:07

Joe C


1 Answers

You can get the filename from struct file *filp with filp->f_path.dentry->d_iname.

To get the full path call dentry_path_raw(filp->f_path.dentry,buf,buflen).

like image 168
PLA Avatar answered Oct 04 '22 04:10

PLA