Skip to contentSkip to conversation

get device from file struct

DISCUSSION Silviu Craciunas 4 participants 11 messages Dec 11, 2006 – Dec 14, 2006

lore
Share & tools
lore
#0 lore raw

quick question for the gurus.. is it possible to determine the hardware device from a file struct during read/write system call. For example in fs/read_write.c when doing a vfs_read.

thanks

#1 lore raw
Quoted 4 lines · Silviu Craciunas

quick question for the gurus.. is it possible to determine the hardware device from a file struct during read/write system call. For example in fs/read_write.c when doing a vfs_read.

file->f_dentry->d_inode gives you the inode. If the inode is on top of a block device, inode->i_bdev gives you a struct block_device that might help you.

Brice

#2 lore raw
Quoted 11 lines · Brice Goglin
Quoted 4 lines · Silviu Craciunas

quick question for the gurus.. is it possible to determine the hardware device from a file struct during read/write system call. For example in fs/read_write.c when doing a vfs_read.

file->f_dentry->d_inode gives you the inode. If the inode is on top of a block device, inode->i_bdev gives you a struct block_device that might help you.

Brice

thanks for the reply, the block device can be determined with the major and minor numbers , what I would be more interested in is if one can get the net_device struct from the file struct

silviu

#3 lore raw
Quoted 4 lines

thanks for the reply, the block device can be determined with the major and minor numbers , what I would be more interested in is if one can get the net_device struct from the file struct

Just how are you supposed to match files and network devices?

	-`J'
#4 lore raw
Quoted 8 lines · Jan Engelhardt
Quoted 3 lines

thanks for the reply, the block device can be determined with the major and minor numbers , what I would be more interested in is if one can get the net_device struct from the file struct

Just how are you supposed to match files and network devices?

	-`J'

from the struct file you can get the struct socket and from there to the struct sock . What I would like to find out is where the data is coming from (read) and where it is going to(write) or if it is even possible to find the net device out using the struct file.

Silviu

#5 lore raw
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

thanks for the reply, the block device can be determined with the major and minor numbers , what I would be more interested in is if one can get the net_device struct from the file struct

Just how are you supposed to match files and network devices?

from the struct file you can get the struct socket and from there to the struct sock .

That only applies when using PF_LOCAL sockets.

Quoted 3 lines

What I would like to find out is where the data is coming from (read) and where it is going to(write) or if it is even possible to find the net device out using the struct file.

I really don't get what you want.

Suppose a daemon reads from a socket (PF_INET), then there is a file descriptor to sockfs (look into /proc/$$/fd/). Well, then you may be able to get the struct file for that socket, but it does not connect to a regular file (S_IFREG) at all.

	-`J'
#6 lore raw
Quoted 18 lines · Jan Engelhardt
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

thanks for the reply, the block device can be determined with the major and minor numbers , what I would be more interested in is if one can get the net_device struct from the file struct

Just how are you supposed to match files and network devices?

from the struct file you can get the struct socket and from there to the struct sock .

That only applies when using PF_LOCAL sockets.

Quoted 3 lines

What I would like to find out is where the data is coming from (read) and where it is going to(write) or if it is even possible to find the net device out using the struct file.

I really don't get what you want.

Quoted 7 lines

Suppose a daemon reads from a socket (PF_INET), then there is a file descriptor to sockfs (look into /proc/$$/fd/). Well, then you may be able to get the struct file for that socket, but it does not connect to a regular file (S_IFREG) at all.

	-`J'

in fs/read_write.c, the vfs_read function does:

file->f_op->read(file, buf, count, pos);

after this call is it possible to determine where the data is coming from? e.g., the first hard disk, a pipe or from a socket. If it is a socket we are interested from which device (eth0, eth1, lo, ...) the data was received.

silviu

#7 lore raw
Quoted 8 lines

in fs/read_write.c, the vfs_read function does:

file->f_op->read(file, buf, count, pos);

after this call is it possible to determine where the data is coming from?
e.g., the first hard disk, a pipe or from a socket.

For hard disks:
file->f_dentry->d_inode->d_sb->s_bdev gives you the block device in case it is a non-virtual filesystem.

For pipes/sockets I do not know of a may to go from a filp to a struct sock or struct socket.

Quoted 2 lines

If it is a socket we are interested
from which device (eth0, eth1, lo, ...) the data was received.

I do not think that is possible either.

	-`J'
#8 lore raw
Quoted 13 lines · On Wed, 13 Dec 2006 20:19:51 +0100 (MET) Jan Engelhardt…
Quoted 8 lines

in fs/read_write.c, the vfs_read function does:

file->f_op->read(file, buf, count, pos);

after this call is it possible to determine where the data is coming from?
e.g., the first hard disk, a pipe or from a socket.

For hard disks:
file->f_dentry->d_inode->d_sb->s_bdev gives you the block device in case it is a non-virtual filesystem.

Quoted 7 lines

For pipes/sockets I do not know of a may to go from a filp to a struct sock or struct socket.

Quoted 2 lines

If it is a socket we are interested
from which device (eth0, eth1, lo, ...) the data was received.

I do not think that is possible either.

The connection between file and network device is through many layers and there is no direct binding. It could be 0 to N interfaces and even be data dependent.

Signature · 1 line
Stephen Hemminger <[email protected]>
#9 lore raw
Quoted 3 lines · Stephen Hemminger

The connection between file and network device is through many layers and there is no direct binding. It could be 0 to N interfaces and even be data dependent.

you mean protocol dependent? yes,it goes trough the layer of the vfs but I thought there may be a way to get to the struct net_device from the struct file. You have the dev_base which contains all devices and in the net_device there is the ifindex which is the unique identifier. I guess there is no way to know the ifindex directly from a socket struct.

thanks
silviu

#10 lore raw
Quoted 5 lines · On Thu, 14 Dec 2006 14:03:28 +0100 Silviu Craciunas…
Quoted 3 lines · Stephen Hemminger

The connection between file and network device is through many layers and there is no direct binding. It could be 0 to N interfaces and even be data dependent.

Quoted 9 lines

you mean protocol dependent? yes,it goes trough the layer of the vfs but I thought there may be a way to get to the struct net_device from the struct file. You have the dev_base which contains all devices and in the net_device there is the ifindex which is the unique identifier. I guess there is no way to know the ifindex directly from a socket struct.

thanks
silviu

You can have things like netfilter and traffic classifiers that look at packet.

Signature · 1 line
Stephen Hemminger <[email protected]>