Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
06-23-2008, 12:30 AM
|
#1
|
LQ Newbie
Registered: Jun 2008
Posts: 3
Rep:
|
How to know which usb port usb device is connected to?
Hi,
The usb device I am working with doesnot have a serial no, so to uniquely identify I thought I may use the information of which port it is connected to , to uniquely identify it.
I found out all the usb ports are listed in /dev/input/by-path. On my machine I have four entries in this directory . How can I find out which usb port My usb device is connected to. Is there some API call or something which I can use. I have to do this from inside a c code.
Thanks
Shivu
|
|
|
06-23-2008, 04:46 AM
|
#2
|
Member
Registered: Jun 2008
Location: Kolkata, India
Posts: 57
Rep:
|
hi,
use the command "tail -f /var/log/messages"
plug the USB device to any usb port.
Wait & see the changes on the conmmand screen.
then,use the command "lsusb" to get the Bus & Device ID.
Repeat the operations by unplugging & plugging the device to another port.
|
|
|
06-23-2008, 05:08 AM
|
#3
|
LQ Newbie
Registered: Jun 2008
Posts: 3
Original Poster
Rep:
|
I need to know the port no programatically I guess I can get it by parsing the /proc/bus/usb/devices file but is their no better way like a API or something
Thanks
Shivu
|
|
|
03-04-2010, 01:02 AM
|
#4
|
Member
Registered: Jun 2006
Posts: 50
Rep:
|
Hey,
I have the same problem. I need to know the port to which my usb drive is conncted. But, it seems that the bus ID and the device ID are not constant but keep changing depending on the pen-drive. Thus, they are not unique to the port.
Here is the output of /var/log/messages, when i plug in two different drives, one 128 MB and one 512 MB, into the same port.
Mar 4 08:19:18 localhost kernel: usb 3-1: new full speed USB device using uhci_hcd and address 6
Mar 4 08:19:18 localhost kernel: usb 3-1: New USB device found, idVendor=09a6, idProduct=8001
Mar 4 08:19:18 localhost kernel: usb 3-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
Mar 4 08:19:18 localhost kernel: usb 3-1: configuration #1 chosen from 1 choice
Mar 4 08:19:18 localhost kernel: scsi18 : SCSI emulation for USB Mass Storage devices
Mar 4 08:19:23 localhost kernel: scsi 18:0:0:0: Direct-Access USB 2.0 Flash Disk 1.06 PQ: 0 ANSI: 0 CCS
Mar 4 08:19:23 localhost kernel: sd 18:0:0:0: Attached scsi generic sg3 type 0
Mar 4 08:19:23 localhost kernel: sd 18:0:0:0: [sdc] 260320 512-byte logical blocks: (133 MB/127 MiB)
Mar 4 08:19:23 localhost kernel: sd 18:0:0:0: [sdc] Write Protect is off
Mar 4 08:19:23 localhost kernel: sd 18:0:0:0: [sdc] Assuming drive cache: write through
Mar 4 08:19:23 localhost kernel: sd 18:0:0:0: [sdc] Assuming drive cache: write through
Mar 4 08:19:23 localhost kernel: sdc: sdc1
Mar 4 08:19:23 localhost kernel: sdc: p1 size 260320 exceeds device capacity, limited to end of disk
Mar 4 08:19:23 localhost kernel: sd 18:0:0:0: [sdc] Assuming drive cache: write through
Mar 4 08:19:23 localhost kernel: sd 18:0:0:0: [sdc] Attached SCSI removable disk
Mar 4 08:19:52 localhost kernel: usb 3-1: USB disconnect, address 6
Mar 4 08:20:10 localhost kernel: usb 1-3: new high speed USB device using ehci_hcd and address 19
Mar 4 08:20:10 localhost kernel: usb 1-3: New USB device found, idVendor=0ea0, idProduct=2168
Mar 4 08:20:10 localhost kernel: usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Mar 4 08:20:10 localhost kernel: usb 1-3: Product: Flash Disk
Mar 4 08:20:10 localhost kernel: usb 1-3: Manufacturer: USB
Mar 4 08:20:10 localhost kernel: usb 1-3: SerialNumber: 611041FD6E02003C
Mar 4 08:20:10 localhost kernel: usb 1-3: configuration #1 chosen from 1 choice
Mar 4 08:20:10 localhost kernel: scsi19 : SCSI emulation for USB Mass Storage devices
Mar 4 08:20:15 localhost kernel: scsi 19:0:0:0: Direct-Access JetFlash TS512MJF2B 2.00 PQ: 0 ANSI: 2
Mar 4 08:20:15 localhost kernel: sd 19:0:0:0: Attached scsi generic sg3 type 0
Mar 4 08:20:16 localhost kernel: ready
Mar 4 08:20:16 localhost kernel: sd 19:0:0:0: [sdc] 1022720 512-byte logical blocks: (523 MB/499 MiB)
Mar 4 08:20:16 localhost kernel: sd 19:0:0:0: [sdc] Write Protect is off
Mar 4 08:20:16 localhost kernel: sd 19:0:0:0: [sdc] Assuming drive cache: write through
Mar 4 08:20:16 localhost kernel: sd 19:0:0:0: [sdc] Assuming drive cache: write through
Mar 4 08:20:16 localhost kernel: sdc: sdc1
Mar 4 08:20:16 localhost kernel: sd 19:0:0:0: [sdc] Assuming drive cache: write through
Mar 4 08:20:16 localhost kernel: sd 19:0:0:0: [sdc] Attached SCSI removable disk
Mar 4 08:22:00 localhost kernel: usb 1-3: USB disconnect, address 19
Please tell me how to identify that these two devices have been connected to the same port.
Thanks,
|
|
|
05-22-2012, 11:21 AM
|
#5
|
LQ Newbie
Registered: Apr 2012
Posts: 7
Rep: 
|
use following command
cdrecrod --scanbus
|
|
|
02-27-2014, 12:59 AM
|
#6
|
Senior Member
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,639
Rep: 
|
Quote:
Originally Posted by nwazsohail
cdrecrod --scanbus
|
Just for the record  , I presume you meant the command "cdrec ord --scanbus".
Whether it solves the original problem I don't know...
|
|
|
02-27-2014, 02:51 AM
|
#7
|
Senior Member
Registered: Jan 2008
Location: Urbana IL
Distribution: Slackware, Slacko,
Posts: 3,716
|
Quote:
Mar 4 08:19:23 localhost kernel: sdc: sdc1
|
there you go.
|
|
|
02-27-2014, 03:02 AM
|
#8
|
Senior Member
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,639
Rep: 
|
That works only for hard disks.
|
|
|
02-28-2014, 04:36 AM
|
#9
|
Member
Registered: Jun 2013
Location: Ipswich, Australia
Distribution: Slackware
Posts: 74
Rep: 
|
For a particular device you can create a udev.rule that creates a symlink each time that device is plugged in. Then you can open it in your c program by using the symlink.
|
|
|
02-28-2014, 04:43 AM
|
#10
|
Member
Registered: Jun 2013
Location: Ipswich, Australia
Distribution: Slackware
Posts: 74
Rep: 
|
Another way you could do it is to use one of the functions provided by libusb
|
|
|
02-28-2014, 08:12 AM
|
#11
|
Senior Member
Registered: Jan 2008
Location: Urbana IL
Distribution: Slackware, Slacko,
Posts: 3,716
|
Quote:
Originally Posted by JZL240I-U
That works only for hard disks.
|
are you really serious this goes back to the 2.6.18 kernel where all drives will be looked at a scsi. it was well noted. that kernel log shows the kernel placing that as sdc and shows the partition to mount will be 1 .
Quote:
Mar 4 08:19:18 localhost kernel: usb 3-1: new full speed USB device using uhci_hcd and address 6
Mar 4 08:19:18 localhost kernel: usb 3-1: New USB device found, idVendor=09a6, idProduct=8001
Mar 4 08:19:18 localhost kernel: usb 3-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
Mar 4 08:19:18 localhost kernel: usb 3-1: configuration #1 chosen from 1 choice
Mar 4 08:19:18 localhost kernel: scsi18 : SCSI emulation for USB Mass Storage devices
Mar 4 08:19:23 localhost kernel: scsi 18:0:0:0: Direct-Access USB 2.0 Flash Disk 1.06 PQ: 0 ANSI: 0 CCS
Mar 4 08:19:23 localhost kernel: sd 18:0:0:0: Attached scsi generic sg3 type 0
Mar 4 08:19:23 localhost kernel: sd 18:0:0:0: [sdc] 260320 512-byte logical blocks: (133 MB/127 MiB)
Mar 4 08:19:23 localhost kernel: sd 18:0:0:0: [sdc] Write Protect is off
Mar 4 08:19:23 localhost kernel: sd 18:0:0:0: [sdc] Assuming drive cache: write through
Mar 4 08:19:23 localhost kernel: sd 18:0:0:0: [sdc] Assuming drive cache: write through
Mar 4 08:19:23 localhost kernel: sdc: sdc1
|
|
|
|
02-28-2014, 02:00 PM
|
#12
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,955
|
Um ... most recent question in this conversation was posting #4, in 2010.
The original question was posted in 2008.
|
|
|
02-28-2014, 02:41 PM
|
#13
|
Senior Member
Registered: Jan 2008
Location: Urbana IL
Distribution: Slackware, Slacko,
Posts: 3,716
|
wonders how it made quick links
|
|
|
03-03-2014, 01:39 AM
|
#14
|
Senior Member
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,639
Rep: 
|
Quote:
Originally Posted by Drakeo
are you really serious this goes back to the 2.6.18 kernel where all drives will be looked at a scsi. ...
|
The OP didn't restrict her/his question to hard disks. There it will work, of course, but what will you do, when it is e.g. a keyboard?
|
|
|
03-03-2014, 01:48 AM
|
#15
|
LQ Guru
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726
|
Hi,
yes I know this thread is a bit of a zombie, but I think I have a comprehensive answer: the "usb-devices" script by Greg K-H et. al.. This is packaged in the usbutils package on Debian along with the also useful lsusb command.
HTH,
Evo2.
|
|
|
All times are GMT -5. The time now is 02:42 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|