mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* associating miscdevice with inode
@ 2010-02-04  6:24 vb
  2010-02-04 11:13 ` Alan Cox
  0 siblings, 1 reply; 3+ messages in thread
From: vb @ 2010-02-04  6:24 UTC (permalink / raw)
  To: linux-kernel

guys,

say I have a misc device driver which instantiates several devices.
When a file operation on this device is invoked, I need to be able to
figure out which device is being accessed. All available information
are

struct inode and struct file. Is there a way to find the address of
the miscdevice structure passed to misc_register() when this device
was created?

TIA,
/vadim

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: associating miscdevice with inode
  2010-02-04  6:24 associating miscdevice with inode vb
@ 2010-02-04 11:13 ` Alan Cox
  2010-02-04 15:00   ` vb
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Cox @ 2010-02-04 11:13 UTC (permalink / raw)
  To: vb; +Cc: linux-kernel

On Wed, 3 Feb 2010 22:24:46 -0800
vb@vsbe.com wrote:

> guys,
> 
> say I have a misc device driver which instantiates several devices.
> When a file operation on this device is invoked, I need to be able to
> figure out which device is being accessed. All available information
> are
> 
> struct inode and struct file. Is there a way to find the address of
> the miscdevice structure passed to misc_register() when this device
> was created?

Not really. If you have a single misc device which each open creates a
new context of some sort then use filp->private_data to store your own
cotntext pointer.

Misc doesn't expect people to be registering lots of devices - its for
one offs and weirdnesses. You could I guess work backwards from

	minor = iminor(inode);

and see which of your miscdevs has c->minor == minor.

If you have more than a couple of instances being put into misc you
should probably register an anonymous device major/minor range instead
and go direct.

Alan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: associating miscdevice with inode
  2010-02-04 11:13 ` Alan Cox
@ 2010-02-04 15:00   ` vb
  0 siblings, 0 replies; 3+ messages in thread
From: vb @ 2010-02-04 15:00 UTC (permalink / raw)
  To: Alan Cox; +Cc: linux-kernel

On Thu, Feb 4, 2010 at 3:13 AM, Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> On Wed, 3 Feb 2010 22:24:46 -0800
> vb@vsbe.com wrote:
>
>> guys,
>>
>> say I have a misc device driver which instantiates several devices.
>> When a file operation on this device is invoked, I need to be able to
>> figure out which device is being accessed. All available information
>> are
>>
>> struct inode and struct file. Is there a way to find the address of
>> the miscdevice structure passed to misc_register() when this device
>> was created?
>
> Not really. If you have a single misc device which each open creates a
> new context of some sort then use filp->private_data to store your own
> cotntext pointer.
>
> Misc doesn't expect people to be registering lots of devices - its for
> one offs and weirdnesses. You could I guess work backwards from
>
>        minor = iminor(inode);
>
> and see which of your miscdevs has c->minor == minor.
>

Alan, thanks a lot for your reply, this is exactly what I was looking for,

cheers,
/vb

> If you have more than a couple of instances being put into misc you
> should probably register an anonymous device major/minor range instead
> and go direct.
>
> Alan
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-02-04 15:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-04  6:24 associating miscdevice with inode vb
2010-02-04 11:13 ` Alan Cox
2010-02-04 15:00   ` vb

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®