Get USB Device Class Type and Mount point

12 messages, 3 authors, 2012-02-14 · open the first message on its own page

Get USB Device Class Type and Mount point

From: Abhijit Pawar <hidden>
Date: 2012-02-09 06:10:16

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 

Get USB Device Class Type and Mount point

From: Abhijit Pawar <hidden>
Date: 2012-02-09 06:22:00

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 [off-list ref] 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 

Get USB Device Class Type and Mount point

From: Greg KH <hidden>
Date: 2012-02-09 12:23:48

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

Get USB Device Class Type and Mount point

From: Abhijit Pawar <hidden>
Date: 2012-02-09 13:48:53

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:
quoted
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.
quoted
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

Get USB Device Class Type and Mount point

From: Greg KH <hidden>
Date: 2012-02-09 14:47:17

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:
quoted
On Thu, Feb 09, 2012 at 11:40:16AM +0530, Abhijit Pawar wrote:
quoted
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.
quoted
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?
quoted
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

Get USB Device Class Type and Mount point

From: Abhijit Pawar <hidden>
Date: 2012-02-10 13:49:26

On 02/09/2012 08:17 PM, Greg KH wrote:
On Thu, Feb 09, 2012 at 07:18:53PM +0530, Abhijit Pawar wrote:
quoted
Hi Greg,
On 02/09/2012 05:53 PM, Greg KH wrote:
quoted
On Thu, Feb 09, 2012 at 11:40:16AM +0530, Abhijit Pawar wrote:
quoted
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.
quoted
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?
quoted
quoted
What are you trying to solve here that you feel you need this
information that is easily found from userspace?

11 more quoted lines

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

Get USB Device Class Type and Mount point

From: Greg KH <hidden>
Date: 2012-02-10 14:12:29

On Fri, Feb 10, 2012 at 07:19:26PM +0530, Abhijit Pawar wrote:
quoted
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

Get USB Device Class Type and Mount point

From: Abhijit Pawar <hidden>
Date: 2012-02-13 12:14:56

On 02/10/2012 07:42 PM, Greg KH wrote:
On Fri, Feb 10, 2012 at 07:19:26PM +0530, Abhijit Pawar wrote:
quoted
quoted
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

Get USB Device Class Type and Mount point

From: Mandeep Sandhu <hidden>
Date: 2012-02-13 12:21:55

quoted
quoted
quoted
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

Get USB Device Class Type and Mount point

From: Abhijit Pawar <hidden>
Date: 2012-02-13 12:31:05

On 02/13/2012 05:51 PM, Mandeep Sandhu wrote:
quoted
quoted
quoted
quoted
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

Get USB Device Class Type and Mount point

From: Greg KH <hidden>
Date: 2012-02-13 15:02:19

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

Get USB Device Class Type and Mount point

From: Abhijit Pawar <hidden>
Date: 2012-02-14 11:38:00

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:
quoted
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.
quoted
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help