All of lore.kernel.org
 help / color / mirror / Atom feed
* Get USB Device Class Type and Mount point
@ 2012-02-09  6:10 Abhijit Pawar
  2012-02-09  6:22 ` Abhijit Pawar
  2012-02-09 12:23 ` Greg KH
  0 siblings, 2 replies; 12+ messages in thread
From: Abhijit Pawar @ 2012-02-09  6:10 UTC (permalink / raw)
  To: kernelnewbies

Hi ,
Is there any way we can get the class type of the attached USB device
through struct usb_device in a kernel module?

I tried getting the device descriptor and interface descriptor and then use
them to get the Device and Interface Class and Subclass.

struct usb_device_descriptor *descriptor = &usbDev->descriptor;

struct usb_interface_descriptor *idesc = to_usb_interface(usbDev);

Whenever I run my kernel module, I get 0 for DeviceClass and Interface
Class. I checked the meaning and it says its the information and to be
gathered through interface.

Am I missing something here? What I want is to get the mount point / device
path of the USB devices. Like for Storage Device I would like to get its
mount path and for HID I would like to get its device path.

Regards,
Abhijit Pawar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120209/db9157b1/attachment.html 

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

* Get USB Device Class Type and Mount point
  2012-02-09  6:10 Get USB Device Class Type and Mount point Abhijit Pawar
@ 2012-02-09  6:22 ` Abhijit Pawar
  2012-02-09 12:23 ` Greg KH
  1 sibling, 0 replies; 12+ messages in thread
From: Abhijit Pawar @ 2012-02-09  6:22 UTC (permalink / raw)
  To: kernelnewbies

oops. I tried getting interface descriptor from usb interface which is
wrong. However still I am not able to get the class type from device
descriptor.

Regards,
Abhijit Pawar


On 9 February 2012 11:40, Abhijit Pawar <apawar.linux@gmail.com> wrote:

> Hi ,
> Is there any way we can get the class type of the attached USB device
> through struct usb_device in a kernel module?
>
> I tried getting the device descriptor and interface descriptor and then
> use them to get the Device and Interface Class and Subclass.
>
> struct usb_device_descriptor *descriptor = &usbDev->descriptor;
>
> struct usb_interface_descriptor *idesc = to_usb_interface(usbDev);
>
> Whenever I run my kernel module, I get 0 for DeviceClass and Interface
> Class. I checked the meaning and it says its the information and to be
> gathered through interface.
>
> Am I missing something here? What I want is to get the mount point /
> device path of the USB devices. Like for Storage Device I would like to get
> its mount path and for HID I would like to get its device path.
>
> Regards,
> Abhijit Pawar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120209/10f9510d/attachment.html 

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

* Get USB Device Class Type and Mount point
  2012-02-09  6:10 Get USB Device Class Type and Mount point Abhijit Pawar
  2012-02-09  6:22 ` Abhijit Pawar
@ 2012-02-09 12:23 ` Greg KH
  2012-02-09 13:48   ` Abhijit Pawar
  1 sibling, 1 reply; 12+ messages in thread
From: Greg KH @ 2012-02-09 12:23 UTC (permalink / raw)
  To: kernelnewbies

On Thu, Feb 09, 2012 at 11:40:16AM +0530, Abhijit Pawar wrote:
> Hi ,
> Is there any way we can get the class type of the attached USB device through
> struct usb_device in a kernel module?
> 
> I tried getting the device descriptor and interface descriptor and then use
> them to get the Device and Interface Class and Subclass.
> 
> struct usb_device_descriptor *descriptor = &usbDev->descriptor;
> ?
> struct usb_interface_descriptor *idesc = to_usb_interface(usbDev);
> 
> Whenever I run my kernel module, I get 0 for DeviceClass and Interface Class. I
> checked the meaning and it says its the information and to be gathered through
> interface.

That is correct, look at the interface pointer given to your driver.

> Am I missing something here? What I want is to get the mount point / device
> path of the USB devices. Like for Storage Device I would like to get its mount
> path and for HID I would like to get its device path.

Both of those things make no sense within the kernel, and you will not
be able to detect them from your driver, especially as it is not your
driver bound to this type of device, the in-kernel drivers are.  Also,
these have nothing to do with the class type of a device's interface.

What are you trying to solve here that you feel you need this
information that is easily found from userspace?

greg k-h

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

* Get USB Device Class Type and Mount point
  2012-02-09 12:23 ` Greg KH
@ 2012-02-09 13:48   ` Abhijit Pawar
  2012-02-09 14:47     ` Greg KH
  0 siblings, 1 reply; 12+ messages in thread
From: Abhijit Pawar @ 2012-02-09 13:48 UTC (permalink / raw)
  To: kernelnewbies

Hi Greg,
On 02/09/2012 05:53 PM, Greg KH wrote:
> On Thu, Feb 09, 2012 at 11:40:16AM +0530, Abhijit Pawar wrote:
>> Hi ,
>> Is there any way we can get the class type of the attached USB device through
>> struct usb_device in a kernel module?
>>
>> I tried getting the device descriptor and interface descriptor and then use
>> them to get the Device and Interface Class and Subclass.
>>
>> struct usb_device_descriptor *descriptor =&usbDev->descriptor;
>>   
>> struct usb_interface_descriptor *idesc = to_usb_interface(usbDev);
>>
>> Whenever I run my kernel module, I get 0 for DeviceClass and Interface Class. I
>> checked the meaning and it says its the information and to be gathered through
>> interface.
> That is correct, look at the interface pointer given to your driver.
>
>> Am I missing something here? What I want is to get the mount point / device
>> path of the USB devices. Like for Storage Device I would like to get its mount
>> path and for HID I would like to get its device path.
> Both of those things make no sense within the kernel, and you will not
> be able to detect them from your driver, especially as it is not your
> driver bound to this type of device, the in-kernel drivers are.  Also,
> these have nothing to do with the class type of a device's interface.
Yes. As I am dealing with USB Core, I am not in  a position to get the 
interface directly. However I checked the usb_dump_interface_descriptor( 
) from usb/core/devices.c and it gives the interface class ( 8 for 
Storage) correctly.
Isnt it forwared to my module which is relying on the linux usb notifier 
chain? This chain gives me the device pointer and I am trying to 
enumerate its interface to know its class.
>
> What are you trying to solve here that you feel you need this
> information that is easily found from userspace?
I am trying to use USB notifier chains to get the device details and 
then find out its mount path ( in case of Storage).  Are you saying that 
I should be looking into sysFS and udev rules for getting this mount path?


> greg k-h

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

* Get USB Device Class Type and Mount point
  2012-02-09 13:48   ` Abhijit Pawar
@ 2012-02-09 14:47     ` Greg KH
  2012-02-10 13:49       ` Abhijit Pawar
  2012-02-13 12:14       ` Abhijit Pawar
  0 siblings, 2 replies; 12+ messages in thread
From: Greg KH @ 2012-02-09 14:47 UTC (permalink / raw)
  To: kernelnewbies

On Thu, Feb 09, 2012 at 07:18:53PM +0530, Abhijit Pawar wrote:
> Hi Greg,
> On 02/09/2012 05:53 PM, Greg KH wrote:
> >On Thu, Feb 09, 2012 at 11:40:16AM +0530, Abhijit Pawar wrote:
> >>Hi ,
> >>Is there any way we can get the class type of the attached USB device through
> >>struct usb_device in a kernel module?
> >>
> >>I tried getting the device descriptor and interface descriptor and then use
> >>them to get the Device and Interface Class and Subclass.
> >>
> >>struct usb_device_descriptor *descriptor =&usbDev->descriptor;
> >>struct usb_interface_descriptor *idesc = to_usb_interface(usbDev);
> >>
> >>Whenever I run my kernel module, I get 0 for DeviceClass and Interface Class. I
> >>checked the meaning and it says its the information and to be gathered through
> >>interface.
> >That is correct, look at the interface pointer given to your driver.
> >
> >>Am I missing something here? What I want is to get the mount point / device
> >>path of the USB devices. Like for Storage Device I would like to get its mount
> >>path and for HID I would like to get its device path.
> >Both of those things make no sense within the kernel, and you will not
> >be able to detect them from your driver, especially as it is not your
> >driver bound to this type of device, the in-kernel drivers are.  Also,
> >these have nothing to do with the class type of a device's interface.
> Yes. As I am dealing with USB Core, I am not in  a position to get
> the interface directly. However I checked the
> usb_dump_interface_descriptor( ) from usb/core/devices.c and it
> gives the interface class ( 8 for Storage) correctly.
> Isnt it forwared to my module which is relying on the linux usb
> notifier chain? This chain gives me the device pointer and I am
> trying to enumerate its interface to know its class.

Ah, I thought you were a "real" driver.  Yes, just enumerate the
interfaces of the device.

Have a pointer to your code anywhere?

> >What are you trying to solve here that you feel you need this
> >information that is easily found from userspace?
> I am trying to use USB notifier chains to get the device details and
> then find out its mount path ( in case of Storage).  Are you saying
> that I should be looking into sysFS and udev rules for getting this
> mount path?

I'm saying you shouldn't be doing any of this from within the kernel at
all, as again, it can be trivially found from userspace today with no
kernel changes needed.

Step back again, what is the problem you are trying to solve?

greg k-h

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

* Get USB Device Class Type and Mount point
  2012-02-09 14:47     ` Greg KH
@ 2012-02-10 13:49       ` Abhijit Pawar
  2012-02-10 14:12         ` Greg KH
  2012-02-13 12:14       ` Abhijit Pawar
  1 sibling, 1 reply; 12+ messages in thread
From: Abhijit Pawar @ 2012-02-10 13:49 UTC (permalink / raw)
  To: kernelnewbies

On 02/09/2012 08:17 PM, Greg KH wrote:
> On Thu, Feb 09, 2012 at 07:18:53PM +0530, Abhijit Pawar wrote:
>> Hi Greg,
>> On 02/09/2012 05:53 PM, Greg KH wrote:
>>> On Thu, Feb 09, 2012 at 11:40:16AM +0530, Abhijit Pawar wrote:
>>>> Hi ,
>>>> Is there any way we can get the class type of the attached USB device through
>>>> struct usb_device in a kernel module?
>>>>
>>>> I tried getting the device descriptor and interface descriptor and then use
>>>> them to get the Device and Interface Class and Subclass.
>>>>
>>>> struct usb_device_descriptor *descriptor =&usbDev->descriptor;
>>>> struct usb_interface_descriptor *idesc = to_usb_interface(usbDev);
>>>>
>>>> Whenever I run my kernel module, I get 0 for DeviceClass and Interface Class. I
>>>> checked the meaning and it says its the information and to be gathered through
>>>> interface.
>>> That is correct, look at the interface pointer given to your driver.
>>>
>>>> Am I missing something here? What I want is to get the mount point / device
>>>> path of the USB devices. Like for Storage Device I would like to get its mount
>>>> path and for HID I would like to get its device path.
>>> Both of those things make no sense within the kernel, and you will not
>>> be able to detect them from your driver, especially as it is not your
>>> driver bound to this type of device, the in-kernel drivers are.  Also,
>>> these have nothing to do with the class type of a device's interface.
>> Yes. As I am dealing with USB Core, I am not in  a position to get
>> the interface directly. However I checked the
>> usb_dump_interface_descriptor( ) from usb/core/devices.c and it
>> gives the interface class ( 8 for Storage) correctly.
>> Isnt it forwared to my module which is relying on the linux usb
>> notifier chain? This chain gives me the device pointer and I am
>> trying to enumerate its interface to know its class.
> Ah, I thought you were a "real" driver.  Yes, just enumerate the
> interfaces of the device.
>
> Have a pointer to your code anywhere?
>
>>> What are you trying to solve here that you feel you need this
>>> information that is easily found from userspace?
>> I am trying to use USB notifier chains to get the device details and
>> then find out its mount path ( in case of Storage).  Are you saying
>> that I should be looking into sysFS and udev rules for getting this
>> mount path?
> I'm saying you shouldn't be doing any of this from within the kernel at
> all, as again, it can be trivially found from userspace today with no
> kernel changes needed.
>
> Step back again, what is the problem you are trying to solve?
>
> greg k-h
I am trying to find out if any storage disk is connected to USB port and 
get its mount so that I an encrypt that mount with encrypted filesystem.

Regards,
Abhijit Pawar

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

* Get USB Device Class Type and Mount point
  2012-02-10 13:49       ` Abhijit Pawar
@ 2012-02-10 14:12         ` Greg KH
  0 siblings, 0 replies; 12+ messages in thread
From: Greg KH @ 2012-02-10 14:12 UTC (permalink / raw)
  To: kernelnewbies

On Fri, Feb 10, 2012 at 07:19:26PM +0530, Abhijit Pawar wrote:
> >Step back again, what is the problem you are trying to solve?
> >
> >greg k-h
> I am trying to find out if any storage disk is connected to USB port
> and get its mount so that I an encrypt that mount with encrypted
> filesystem.

Great, then do that from userspace, like it is done today.  Or do you
have a problem with how things are done today with encrypted
filesystems?  If so, why?

greg k-h

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

* Get USB Device Class Type and Mount point
  2012-02-09 14:47     ` Greg KH
  2012-02-10 13:49       ` Abhijit Pawar
@ 2012-02-13 12:14       ` Abhijit Pawar
  2012-02-13 12:21         ` Mandeep Sandhu
  2012-02-13 15:02         ` Greg KH
  1 sibling, 2 replies; 12+ messages in thread
From: Abhijit Pawar @ 2012-02-13 12:14 UTC (permalink / raw)
  To: kernelnewbies

On 02/10/2012 07:42 PM, Greg KH wrote:
> On Fri, Feb 10, 2012 at 07:19:26PM +0530, Abhijit Pawar wrote:
>>> Step back again, what is the problem you are trying to solve?
>>>
>>> greg k-h
>> I am trying to find out if any storage disk is connected to USB port
>> and get its mount so that I an encrypt that mount with encrypted
>> filesystem.
> Great, then do that from userspace, like it is done today.  Or do you
> have a problem with how things are done today with encrypted
> filesystems?  If so, why?
>
> greg k-h
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Hi Greg,
The  reason I went for kernel module is to get the device add 
notification. However once I get the notification, I can have netlink 
socket pass the device data to my user space application.
Here the tricky part is I can get the device info, but not able to 
figure out how can I get the mount path from this device. I tried 
looking at linux automount feature but its doc is limited and its on 
demand feature may not allow me to know for sure if the drive is mounted 
properly.
So is there any way I can get the mount path from the USB device 
structure in userspace?

for encrypted filesystem there isnt any problem as I would be overlaying 
that on the USB device default filesystem.

Regards,
Abhijit Pawar

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

* Get USB Device Class Type and Mount point
  2012-02-13 12:14       ` Abhijit Pawar
@ 2012-02-13 12:21         ` Mandeep Sandhu
  2012-02-13 12:31           ` Abhijit Pawar
  2012-02-13 15:02         ` Greg KH
  1 sibling, 1 reply; 12+ messages in thread
From: Mandeep Sandhu @ 2012-02-13 12:21 UTC (permalink / raw)
  To: kernelnewbies

>>>> greg k-h
>>> I am trying to find out if any storage disk is connected to USB port
>>> and get its mount so that I an encrypt that mount with encrypted
>>> filesystem.
>> Great, then do that from userspace, like it is done today. ?Or do you
>> have a problem with how things are done today with encrypted
>> filesystems? ?If so, why?
>>
>> greg k-h
>>
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies at kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> Hi Greg,
> The ?reason I went for kernel module is to get the device add
> notification. However once I get the notification, I can have netlink

Well, thats not a good enough reason to go to kernel space! :)

Have you looked at Udev? It nicely handles device attach/detach events
(hotplug events) from userspace. You should probably look at using it
for your purpose.

http://en.wikipedia.org/wiki/Udev

HTH,
-mandeep


> socket pass the device data to my user space application.
> Here the tricky part is I can get the device info, but not able to
> figure out how can I get the mount path from this device. I tried
> looking at linux automount feature but its doc is limited and its on
> demand feature may not allow me to know for sure if the drive is mounted
> properly.
> So is there any way I can get the mount path from the USB device
> structure in userspace?
>
> for encrypted filesystem there isnt any problem as I would be overlaying
> that on the USB device default filesystem.
>
> Regards,
> Abhijit Pawar
>
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

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

* Get USB Device Class Type and Mount point
  2012-02-13 12:21         ` Mandeep Sandhu
@ 2012-02-13 12:31           ` Abhijit Pawar
  0 siblings, 0 replies; 12+ messages in thread
From: Abhijit Pawar @ 2012-02-13 12:31 UTC (permalink / raw)
  To: kernelnewbies

On 02/13/2012 05:51 PM, Mandeep Sandhu wrote:
>>>>> greg k-h
>>>> I am trying to find out if any storage disk is connected to USB port
>>>> and get its mount so that I an encrypt that mount with encrypted
>>>> filesystem.
>>> Great, then do that from userspace, like it is done today.  Or do you
>>> have a problem with how things are done today with encrypted
>>> filesystems?  If so, why?
>>>
>>> greg k-h
>>>
>>> _______________________________________________
>>> Kernelnewbies mailing list
>>> Kernelnewbies at kernelnewbies.org
>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>> Hi Greg,
>> The  reason I went for kernel module is to get the device add
>> notification. However once I get the notification, I can have netlink
> Well, thats not a good enough reason to go to kernel space! :)
>
> Have you looked at Udev? It nicely handles device attach/detach events
> (hotplug events) from userspace. You should probably look at using it
> for your purpose.
>
> http://en.wikipedia.org/wiki/Udev
>
> HTH,
> -mandeep
>
Yes. I should have looked into libudev and libsysfs which I am doing now. :)
Regarding going to kernel , I thought that would be help me in 
controlling the device in a better way (where I can enable or disable 
the data transfer interfaces  preventing the data copy (if at all thats 
possible).

Regards,
Abhijit Pawar

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

* Get USB Device Class Type and Mount point
  2012-02-13 12:14       ` Abhijit Pawar
  2012-02-13 12:21         ` Mandeep Sandhu
@ 2012-02-13 15:02         ` Greg KH
  2012-02-14 11:38           ` Abhijit Pawar
  1 sibling, 1 reply; 12+ messages in thread
From: Greg KH @ 2012-02-13 15:02 UTC (permalink / raw)
  To: kernelnewbies

On Mon, Feb 13, 2012 at 05:44:56PM +0530, Abhijit Pawar wrote:
> The  reason I went for kernel module is to get the device add
> notification. However once I get the notification, I can have
> netlink socket pass the device data to my user space application.

Like others pointed out, use libudev for this, that's the only way you
can properly do it.

> Here the tricky part is I can get the device info, but not able to
> figure out how can I get the mount path from this device.

Within the kernel you can not.  Think of namespaces, and all that fun
stuff, it will not work properly within the kernel.

Again, if you are using an encrypted filesystem, just use what Linux
provides for this today.  Is there something there that does not meet
your needs?

greg k-h

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

* Get USB Device Class Type and Mount point
  2012-02-13 15:02         ` Greg KH
@ 2012-02-14 11:38           ` Abhijit Pawar
  0 siblings, 0 replies; 12+ messages in thread
From: Abhijit Pawar @ 2012-02-14 11:38 UTC (permalink / raw)
  To: kernelnewbies

On Mon, 2012-02-13 at 07:02 -0800, Greg KH wrote:
> On Mon, Feb 13, 2012 at 05:44:56PM +0530, Abhijit Pawar wrote:
> > The  reason I went for kernel module is to get the device add
> > notification. However once I get the notification, I can have
> > netlink socket pass the device data to my user space application.
> 
> Like others pointed out, use libudev for this, that's the only way you
> can properly do it.
I am getting the device node from libudev and witht his devnode I would
be traversing the mnttab to get the actual mount path for this
device.struct mntent* has helped me lot here.
> 
> > Here the tricky part is I can get the device info, but not able to
> > figure out how can I get the mount path from this device.
> 
> Within the kernel you can not.  Think of namespaces, and all that fun
> stuff, it will not work properly within the kernel.
> 
> Again, if you are using an encrypted filesystem, just use what Linux
> provides for this today.  Is there something there that does not meet
> your needs?
There isnt any special filesystem need for my app. I am planning to use
ecryptfs module (with its overlay capability) which is available today.
Or is there any other module i should look into for this?

> greg k-h

If I am using the monitor capabilities of libudev then I may need to
write a daemon process to run this in background. There is always a
chance that user with root access can kill this application. 

I read about call_usermodehelper_exec API which can launch a user
application from kernel mode which can prove useful. However still
writing a kernel module and making it compatible for each kerne is time
consuming.

As everyone is saying, I will go with user mode app for this
functionality. 


Thanks,
Abhijit Pawar

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

end of thread, other threads:[~2012-02-14 11:38 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-09  6:10 Get USB Device Class Type and Mount point Abhijit Pawar
2012-02-09  6:22 ` Abhijit Pawar
2012-02-09 12:23 ` Greg KH
2012-02-09 13:48   ` Abhijit Pawar
2012-02-09 14:47     ` Greg KH
2012-02-10 13:49       ` Abhijit Pawar
2012-02-10 14:12         ` Greg KH
2012-02-13 12:14       ` Abhijit Pawar
2012-02-13 12:21         ` Mandeep Sandhu
2012-02-13 12:31           ` Abhijit Pawar
2012-02-13 15:02         ` Greg KH
2012-02-14 11:38           ` Abhijit Pawar

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.