How to access all the channels in the system from the Linux kernel space

I want to add a new system call to the Linux kernel, which will display information about all the pipes created in the system.

How can I get an inode (or any other related structure that will allow me to access pipe_inode_info) for each pipe in pipefs?

I looked at struct vfsmount , struct dentry and struct super_block , but I did not find a suitable path. Is there a way to get the file structure of each file in pipefs?

+3
source share
1 answer

First I go to the / proc directory and the problem is:

ls -al */fd |grep pipe

( "" , u .) ( ):

l-wx------ 1 root     root     64 2011-05-14 23:12 17 -> pipe:[39208]
l-wx------ 1 root     root     64 2011-05-14 23:12 2 -> pipe:[16245]
lr-x------ 1 root     root     64 2011-05-14 23:12 4 -> pipe:[23406]
l-wx------ 1 root     root     64 2011-05-14 23:12 8 -> pipe:[23406]
l-wx------ 1 root     root     64 2011-05-14 23:12 17 -> pipe:[39532]
l-wx------ 1 root     root     64 2011-05-14 23:12 2 -> pipe:[16245]
lr-x------ 1 root     root     64 2011-05-14 23:12 4 -> pipe:[23406]
l-wx------ 1 root     root     64 2011-05-14 23:12 8 -> pipe:[23406]
l-wx------ 1 root     root     64 2011-05-14 23:12 1 -> pipe:[16245]
lr-x------ 1 root     root     64 2011-05-14 23:12 16 -> pipe:[40032]
l-wx------ 1 root     root     64 2011-05-14 23:12 17 -> pipe:[40032]
l-wx------ 1 root     root     64 2011-05-14 23:12 2 -> pipe:[16245]
lr-x------ 1 root     root     64 2011-05-14 23:12 4 -> pipe:[23406]
l-wx------ 1 root     root     64 2011-05-14 23:12 8 -> pipe:[23406]
l-wx------ 1 tteikhua tteikhua 64 2011-05-14 23:13 1 -> pipe:[16245]
l-wx------ 1 tteikhua tteikhua 64 2011-05-14 23:13 12 -> pipe:[66674]
lr-x------ 1 tteikhua tteikhua 64 2011-05-14 23:13 13 -> pipe:[66674]
l-wx------ 1 root root 64 2011-05-14 23:30 1 -> pipe:[101794]

u , , "grep", :

, pid = 1 fd 6759:

1/fd:
total 0
dr-x------ 2 root root  0 2011-05-14 23:29 .
dr-xr-xr-x 7 root root  0 2011-05-14 22:59 ..
lrwx------ 1 root root 64 2011-05-14 23:29 0 -> /dev/console (deleted)
lrwx------ 1 root root 64 2011-05-14 23:29 1 -> /dev/console (deleted)
lrwx------ 1 root root 64 2011-05-14 23:29 2 -> /dev/console (deleted)
lr-x------ 1 root root 64 2011-05-14 23:29 3 -> pipe:[6759]

fs/pipe.c( linux, ):

/*
 * pipefs_dname() is called from d_path().
 */
static char *pipefs_dname(struct dentry *dentry, char *buffer, int buflen)
{
        return dynamic_dname(dentry, buffer, buflen, "pipe:[%lu]",
                                dentry->d_inode->i_ino);
}

static const struct dentry_operations pipefs_dentry_operations = {
        .d_dname        = pipefs_dname,
};

fs/dcache.c:

char *d_path(const struct path *path, char *buf, int buflen)
{
        if (path->dentry->d_op && path->dentry->d_op->d_dname)
                return path->dentry->d_op->d_dname(path->dentry, buf, buflen);

and since d_path() is an exported symbol,

EXPORT_SYMBOL(d_path);

- , pipefs_dname() - :

./fs/pipe.c:
    .d_dname    = pipefs_dname,

inode.c: init_inode_always(), , i_pipe NULL. , inode PIPE.

, , inode i_pipe - -NULL, , inode .

, ( - ), (, "ls -al" ", ), - , , , , ..

+1

All Articles