LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 06-12-2006, 02:44 PM   #1
scerenon
LQ Newbie
 
Registered: Jun 2006
Posts: 8

Rep: Reputation: 0
mapping usb device to device file


Hello,
I've been searching google for a while now for a way to do this and have come up more or less empty handed. I need to list the usb devices (flash card readers) attached to my computer in my program. The problem is that I can't find a good way to figure out what device file each reader corresponds to. I initially tried dmesg which would give me the device names and tell me it was attached to /dev/sdb or some such, but dmesg is very unreliable when I hotplug a new device in or unplug one. The only file I've found which really gives accurate information about what is actually plugged in is in /proc/bus/usb/devices. Unfortunately, I can't find a way to map the information in that file to /dev/sdb or /dev/sdc. The closest i've foudn is sg_scan and sg_map but sg_map crashes my whole system and sg_scan doesn't seem to work too well with hotplugging. fdisk -l will tell me what disks are mapped to where, but I can't find a correlation to the devices file with the names (I also need to be able to tell that they are actually usb readers).
PS- I'm running redhat 8.
Any help would be much appreciated,
-Scerenon
 
Old 06-12-2006, 06:36 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by scerenon
PS- I'm running redhat 8.
Why? I don't know remember how the older kernels did it, but nowadays, there is udev which lets you create rules for persistent naming of usb (and other) devices. I'm almost positive that there's also an entry in /proc somewhere.

Consider getting a more up-to-date distro.
 
Old 06-12-2006, 07:20 PM   #3
scerenon
LQ Newbie
 
Registered: Jun 2006
Posts: 8

Original Poster
Rep: Reputation: 0
I have heard of udev, unfortunately it isn't on rh 8. I need redhat 8 as I need a proprietary app to run on it that only wants to build under rh8. I could try to get it working on newer distros, but it would make my life much easeier if I could just figure out how to solve the device file mapping problem.

Last edited by scerenon; 06-12-2006 at 07:22 PM.
 
Old 06-12-2006, 08:23 PM   #4
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Did you check the /proc filesystem?
 
Old 06-13-2006, 11:57 AM   #5
scerenon
LQ Newbie
 
Registered: Jun 2006
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by osor
Did you check the /proc filesystem?
Thank you for your reply.

I've read through the /proc filesystem and the only file i've found in /proc that is really useful is /proc/bus/usb/devices which I mentioned above. Can you be more specific please?
-thanks
 
Old 06-13-2006, 12:49 PM   #6
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
I'm sorry, I don't think the /sys interface is available in 2.4. I thought maybe /proc might have similar information. Can you post the output of devfsd.conf or equivalent.
 
Old 06-13-2006, 01:46 PM   #7
scerenon
LQ Newbie
 
Registered: Jun 2006
Posts: 8

Original Poster
Rep: Reputation: 0
# Sample /etc/devfsd.conf configuration file.
# Richard Gooch <rgooch@atnf.csiro.au> 3-JUL-2000
#
# Enable full compatibility mode for old device names. You may comment these
# out if you don't use the old device names. Make sure you know what you're
# doing!
REGISTER .* MKOLDCOMPAT
UNREGISTER .* RMOLDCOMPAT

# You may comment out the above and uncomment the following if you've
# configured your system to use the original "new" devfs names or the really
# new names
#REGISTER vc/.* MKOLDCOMPAT
#UNREGISTER vc/.* RMOLDCOMPAT
#REGISTER pty/.* MKOLDCOMPAT
#UNREGISTER pty/.* RMOLDCOMPAT
#REGISTER misc MKOLDCOMPAT
#UNREGISTER misc RMOLDCOMPAT

# You may comment these out if you don't use the original "new" names
REGISTER .* MKNEWCOMPAT
UNREGISTER .* RMNEWCOMPAT

# Enable module autoloading. You may comment this out if you don't use
# autoloading
LOOKUP .* MODLOAD

#
# Uncomment this if you want permissions to be saved and restored
#REGISTER .* COPY /dev-state/$devname $devpath
#CHANGE .* COPY $devpath /dev-state/$devname
#CREATE .* COPY $devpath /dev-state/$devname
 
Old 06-14-2006, 05:30 PM   #8
scerenon
LQ Newbie
 
Registered: Jun 2006
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by osor
I'm sorry, I don't think the /sys interface is available in 2.4. I thought maybe /proc might have similar information. Can you post the output of devfsd.conf or equivalent.
Oh yes, and I do have the /proc/sys folder if that's what you meant, it contains the following:
abi, debug, dev, fs, kernel, net, proc, vm
 
Old 06-14-2006, 05:46 PM   #9
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by scerenon
Oh yes, and I do have the /proc/sys folder if that's what you meant, it contains the following:
abi, debug, dev, fs, kernel, net, proc, vm
No that's not the same (/sys != /proc/sys). The `/sys' folder is part of the new kernel device scheme (along with udev) which is only for 2.6 kernels.

Right now, (as I'm in the process of digesting your conf file,) I'm trying to remember how devfsd worked. I'm pretty sure that's where you'll find the answer to your problem, I'm just a little rusty on the details (it took me so long to become comfortable with udev!).


P.S.
Are you sure you want to continue with the old distro? You might be able to build or run the proprietary app on newer distros just by downloading a bunch of `legacy' libraries and old versions of gcc, etc., etc (unless your app is closely tied to the kernel). Your best bet might be to get a nice shiny new distro, and load your old setup as a virtual machine (I hear that's all the rage these days). The purpose of the virtual machine would be run only your prop. app.
 
Old 06-15-2006, 05:50 PM   #10
scerenon
LQ Newbie
 
Registered: Jun 2006
Posts: 8

Original Poster
Rep: Reputation: 0
Actually that's exactly what I'm doing. My app launches vmware in the background to run the program in linux as I was tasked to get it working on windows ( I communicate with the linux distro through the virtual network). The person that originally worked on it has suffered some health problems so changing anything or building a new one on windows would take more time than I have as I am not very familiar with it. It's kind of a clunky solution to be sure, but it's working for the most part... aside from the fact that I always assume the device file is sdb which isn't always the case.
I will take a more in depth look at devfs and let you know if I find anything, kind of depressing that someone couldn't have made a simple app like this 6 years ago though on linux, there must be a way that doesn't involve hacking the kernel.
 
Old 06-15-2006, 06:23 PM   #11
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
If you're running a linux distro on a virtual machine in windows, why do you need usb hotplugging to work? Just wondering.
 
Old 06-16-2006, 01:21 PM   #12
scerenon
LQ Newbie
 
Registered: Jun 2006
Posts: 8

Original Poster
Rep: Reputation: 0
I list the devices with names to the user in windows, and then they can select one to operate on. So the windows app just queries the linux one for a list of devices, user selects the name they want ( like imagemate 6 in 1 64mb) and linux does the operations on it. If someone were to have an external harddrive plugged in and then plug in a usb card and my program incorrectly used the wrong device file and formatted their external hard drive, it would not be good to say the least. Of course they could just use linux directly, but that is not up to me.
 
Old 07-20-2006, 04:13 PM   #13
scerenon
LQ Newbie
 
Registered: Jun 2006
Posts: 8

Original Poster
Rep: Reputation: 0
I figured it out! ... mostly.
I was having trouble to get devfs to work correctly. I found out that it was incorrectly built into the kernel, so i tried recompiling the kernel with /dev support enabled but I kept getting errors with it on make install.
The solution I found without devfs was to use a combination of /proc/bus/usb/devices and /var/log/messages as they both list the "device number". varlogmessages will tell me what devices number was assigned to what product, and then further up it will tell me when the product was first plugged in what device file it was plugged into.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
USB drive not working properly, read only device? (USB key storage device) Arodef Linux - Hardware 14 01-01-2010 07:32 AM
How to force kernel to use a USB 2.0-compatible device (ehci_hcd) as a USB 1.1 device eze Linux - Hardware 0 05-16-2006 05:24 AM
suse 9.1 device mapping for usb drives cj12345 Linux - Distributions 1 04-11-2005 02:18 PM
Assign one USB-storage device to one device file Misel Linux - Hardware 1 08-28-2004 03:52 AM
physical scsi channel mapping to scsiX device node mapping, how to configure manually drthornt Linux - Hardware 3 02-09-2003 11:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 10:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration