Chinaunix首页 | 论坛 | 博客
  • 博客访问: 914603
  • 博文数量: 132
  • 博客积分: 9976
  • 博客等级: 中将
  • 技术积分: 1781
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-30 20:40
文章分类

全部博文(132)

文章存档

2013年(1)

2011年(1)

2010年(15)

2009年(77)

2008年(36)

2007年(2)

我的朋友

分类: C/C++

2009-04-02 15:13:15

在Linux系统下检测U盘是否已连接的方法

===========================================================================
Plug-and-Play-HOWTO: PnP for External and Plug-in Devices

The USB () is a high speed bus on an external cable that plugs into a PC. The external has its own communication protocols and doesn't use any IRQs, I/0 addresses (or other bus-resources). Communication is by packets, something like the Internet, only there are time-slice allocations which prevent any one device from hogging the bus if other devices need it. There are free time slots which allow every device to send a short message to the bus controller without any need for IRQs on the bus.

However, the USB bus controller inside the PC does have an IRQ and an address on the (or ISA) which are used for communication between the CPU and all devices on the USB. Thus there's no resource allocations needed for the individual devices on the USB. One could also think of this as all devices on the USB sharing the one interrupt and address. If a device is on the USB it needs a driver that understands the USB.

But each device on the USB does have an IDs, just like cards do on the PCI bus. So Linux likely maintains a table of these IDs so that device drivers can check them to find their device. The USB also support "hot plug". To find out what is on the USB bus, you could use a general hardware detection tool like "discover" or "hwinfo".

"" is where you plug something into a PC (usually via a ) and it is instantly detected. If required, it is configured with bus-resources. The driver for it is also started, perhaps by loading a module for it. For this to work the hardware used must be designed for hot plugging. One can hot plug certain (Cardbus), USB devices, and IEEE 1394 devices (Firewire).

When a new device is detected, it's registers are read so as to get the ID number of the device. Then to find a driver, Linux must maintain a table mapping ID numbers to drivers. It wasn't until kernel 2.4 that such a table existed since Linux once shunned centralized PnP. It's named: MODULE_DEVICE_TABLE.

"Hot Swap" is where you remove an old device and then plug in a new device to replace the old one. You have thus "swapped" devices. Now in addition to being able to detect that a new device has been plugged in, the removal of the old device needs to be detected too.

External devices that connect to the serial port via a cable (such as external modems) can also be called Plug-and-Play. Since only the serial port itself needs bus-resources (an IRQ and I/O address) there are no bus-resources to allocate to such plug-in devices. In this case, PnP is used only to identify the modem (read it's model code number). This could be important if the modem is a software modem (linmodem) and requires a special driver. There is a special PnP specification for such external serial devices (something connected to the serial port).

Linux doesn't support this yet ?? For a hardware modem, the ordinary serial driver will work OK so there's little need for using the special serial PnP to find a driver. You still need to tell the communications program what port (such as /dev/ttyS1) the modem is on. With PnP you wouldn't need to even do this. With the advent of software modems that have Linux drivers (linmodems), it would be nice to have the appropriate driver install itself automatically via PnP.



===========================================================================
在Linux系统下检测U盘是否已连接的方法

Linux的文件系统是异步的,也就是说写一个文件不是立刻保存到介质(硬盘,U盘等)中,而是存到缓冲区内,等积累到一定程度再一起保存到介质中。如果没有umount就非法拔出U盘,程序是不知道的,fopen,fwrite等函数都依然返回正确,知道操作系统要把写介质的时候,才会提示I/O错误。可是很多数据都会因为这个不及时的错误报告而丢失。

事实上,USB驱动程序在U盘插入和拔出时,都对系统配置文件做了修改。

例如U盘驱动程序会在插入或拔出时往 /proc/scsi/usb-storage-0/0 里面记上 Attached:Yes or No

通过查看这个文件就不难检测U盘是否插入或拔出了。

注意:U盘是否插入的状态与是否挂载(mount)无关。
===========================================================================
from:

Linux poised to plug in USB 2

    * Tags:
    * Operating System,
    * Usb Support,
    * Open Source,
    * Linux Kernel

Stephen Shankland, CNET News.com CNET News.com

Published: 26 Jul 2002 12:42 BST

    * Email
    * Trackback
    * Clip Link
    * Print friendly
    * Post Comment

Support for a faster version of USB in Linux is imminent and will become a permanent part of the Linux landscape when the next version of the operating system is introduced.

The upcoming 2.4.19 version of the Linux kernel -- the core part of the Unix-like operating system -- for the first time will include support for many USB (universal serial bus) 2.0 features and devices. USB lets people easily plug devices such as digital cameras, mice or printers into a computer.

The support, crucial to making Linux fully compatible with the mass of PCs and gadgets on the market, demonstrates the ability of a host of volunteer programmers to keep up with computing trends. Linux, though bankrolled by some companies, remains a cooperative software project.

USB 2.0 support is a timely issue; the higher-speed interface is being built into the latest PCs and workstations.

Where the first version of USB had a top data-transfer speed of 12Mbps, USB 2.0 can reach 480Mbps, making it useful for higher-speed devices such as CD-RW drives, digital video cameras and network adapters. At these speeds, USB rivals FireWire -- the favourite connection technology for when high data-transfer rates are required -- but costs less to implement.

The new version won't instantly enable USB 2.0 to work with Linux-based devices, but will let the legions of Linux programmers get down to serious work writing "drivers," the software interfaces to all those devices.

"Before (the new version of Linux), it wasn't really practical for developers to start writing drivers for those devices," said David Brownell, a key programmer for the USB 2.0 features. But just this week, he's seen improvements for high-resolution Webcams, and the ability for a single USB port to simultaneously communicate with a handful of high-speed networking cards.

Some USB support has been included in the most recent versions of Linux sold by Red Hat and SuSE through custom patches, but the coming kernel will mean that the "stock" versions of Linux will include it.

Newer versions of Microsoft Windows, by far the most popular operating system for desktops and laptops, began supporting USB 2.0 earlier this year through the company's Windows Update service. USB 2.0, though, didn't start to take off until recently, after Intel incorporated the functions to control it in its desktop chipsets.

A window into Linux development
The arrival of USB 2.0 support in Linux provides a window into the "open source" community world under which programmers freely swap software source code, or blueprints.

The Linux-USB project serves as an information clearinghouse where programmers can find out details such as the unique identification codes assigned to each USB device or download software. VA Software's SourceForge site hosts a mailing list through which programmers contribute software updates and hash out issues.

Linux founder Linus Torvalds took a stab at updating the first USB support in March 1999, spawning an active developer community that mixes several regular contributors with others just stopping by. The USB group tests new software, with the "maintainer" Greg Kroah-Hartman keeping primary responsibility, and various other maintainers staying on top of smaller sections.

At times, the USB group submits patches to higher-ranking maintainers who have responsibility for the overall production and developer versions of the Linux kernel.

Two versions of Linux are under development simultaneously. One, the 2.5 series of "development" kernels, is for trying out new code. It has more cutting-edge features but isn't well tested, and has included USB 2.0 support for months.

The other branch -- the 2.4 "production" kernel series that's changed more conservatively -- is for use in shipping products and on computers. Commonly, features tested in the development kernel are "back ported" or added to earlier versions of the production kernel. By this process, USB 2.0 support will arrive in the forthcoming 2.4.19 kernel.

Work to be done
Much work remains to be done; namely, rewriting software to keep up with the faster USB infrastructure.

"Performance work hasn't really started," Brownell said. While some USB devices can transfer data at 200 megabits per second -- less than half of USB 2.0's total capacity -- most hardware and software is about half that, he said.

In addition, Linux developers have to build support for features of USB hubs, the hardware devices that let single USB ports be shared to accommodate several USB devices. USB hubs can be connected in chains, providing lots of USB ports but making for a lot of complications -- especially when mixing USB 1.1 and 2.0 hubs.

Some of that new hub support is in the 2.5 kernel, Brownell said.

Then there's the challenge of bringing Linux USB support to the real world. Mainstream Linux versions are in the midst of a transition to USB 2.0 support, with some more cautious than others.

"USB 2.0 support is still in the development stage," Linux seller MandrakeSoft said in a statement. The USB 2.0 updates "are not mature enough yet for most production usage," the company said.

Red Hat put some early USB support into its current version 7.3 Linux product, though Michael K. Johnson, manager of kernel engineering, said "USB 2.0 support is new in Linux, and so we expect to find and fix occasional defects."

SuSE is thinking of providing software that lets customers upgrade to the 2.4.19 kernel, said Holger Dyroff, director of North American sales at SuSE, and standard support will come later this year. "SuSE Linux will definitely support USB 2.0 with our new upcoming products in the third quarter," he said.

The built-in hardware will kick USB 2 development into a higher gear, Brownell said.

"Linux is ready for the generation of PC hardware that's becoming available starting this summer, Brownell said. "The big problem with USB 2.0 adoption has been lack of devices."

For all your GNU/Linux and open source news, from the latest kernel releases to the newest distributions, see ZDNet UK's Linux Lounge.

Have your say instantly, and see what others have said. Go to the Linux forum.
===========================================================================
from:

How do I check that my USB ports are working?

This is probably gonna come off looking painfully naive... I apologise in advance, this is my first time with Linux and I'm no technical expert

In Windows XP, the OS I am trying to move away from, I know USB devices has been recognised because a handy little noise is made when I plug in a USB device, and a set of little info bubbles appear in my system tray. I at least know that Windows has acknowledged the presence of such devices.

Now... I can't get my USB modem to work (the light on it saying "USB" doesn't even work) and I can't find any drivers on the entire net for my USB printer (not that I'd probably know what to do with them, in any event).

Which leads me to wonder how I check whether in fact my new Linux OS in fact works with the USB ports on my computer. Whether in fact I could plug anything in there and it would work or not. I've installed SuSE 9.0, and the computer is a Medion MD 8000 Titanium, 2.66 GHZ P4, 512MB RAM. THat's about as much as I know

Anyone know how I find out if my USB ports are working on Linux?

Ta

Mogh

---------------------------------------------------------------------------
Member
 
Registered: Mar 2004
Location: US
Distribution: Redhat 9 - Linux 2.6.3
Posts: 836
Thanked: 0
type 'dmesg | more' and sift through there to look for any USB recognition.

'lsusb' would also work to display device statistics/hardware.

That is considering you have both dmesg and lsusb. Chances are you do.

run these commands as root.
AutOPSY is offline     Reply With Quote
Old 03-21-2004, 03:33 PM   #
Member
 
Registered: Mar 2004
Location: Leeds, West Yorkshire, UK
Distribution: OpenSUSE 10.3 x86_64
Posts: 69
Thanked: 0
Thanks for the advice. I'll try it
MoghNX01 is offline     Reply With Quote
Old 03-21-2004, 09:51 PM   #
Senior Member
 
Registered: Nov 2003
Location: Knoxville, TN
Distribution: Mandy 2009.0
Posts: 1,100
Thanked: 3
USBView is a good GUI diagnostic:
Crito is offline     Reply With Quote
Old 03-22-2004, 01:11 AM   #
Member
 
Registered: Jan 2004
Location: Lancaster, OH
Distribution: Gentoo
Posts: 393
Thanked: 0
linuxprinting.org is a great place to go to get .

As for the USB, Linux doesn't play dumb sounds when you connect USB devices, but it more than likely registers them. Your kernel might not have support for the USB modem though, and to fix that you'll have to compile a new kernel from the sources. However, typing lsusb is a good way to see if your stuff is detected.
Pwnz3r is offline     Reply With Quote
Old 03-22-2004, 04:33 AM   #
Member
 
Registered: Mar 2004
Location: Leeds, West Yorkshire, UK
Distribution: OpenSUSE 10.3 x86_64
Posts: 69
Thanked: 0
I tried Linnuxprinting.org- it seems they don't have drivers for my printer. I was rather suprised and disappointed- I'd been told that Linux generally had more drivers and compatibility than Windows

Still, I'll give the USB stuff a go. Just need to restart computer in Linux to do it. My modem is an Alcatel Speedtouch USB... there seems to be dozens of tutorials on the net on how to get it working- for some reason, I seem to have completed none of them successfully. Hence me wondering whether the USB ports were actually working...

Oh well. Here goes...

Ta guys

Mogh
MoghNX01 is offline     Reply With Quote
Old 03-22-2004, 07:40 AM   #
Moderator
 
Registered: Aug 2002
Posts: 7,646
Thanked: 10
Quote:
Originally posted by MoghNX01
I tried Linnuxprinting.org- it seems they don't have drivers for my printer. I was rather suprised and disappointed- I'd been told that Linux generally had more drivers and compatibility than Windows
Besides for the few manufactures like Nvidia most drivers/modules AFAIK are written once the equipment is on the market. Some manufactures will not release information required to write a driver and therefore must be reversed engineered. In addition, a lot of linux stuff is developed by people in their spare time.

Last edited by michaelk; 03-22-2004 at 07:43 AM..
michaelk is offline     Reply With Quote
Old 12-20-2005, 12:26 AM   #
LQ Newbie
 
Registered: Dec 2005
Location: Bangalore
Distribution: suse 10
Posts: 3
Thanked: 0
Question How To Bring Life 2 My Webcam

hello linux members,
i want my USB driven webcaM 2 WORK IN 4.PLEASE HELP ME.I HAVE LOGITECH EXPRESS WEBCAM.I ALSO TRIED LSUSB COMMAND AND I GOT THE FOLLOWING MSG:

Bus 004 Device 001: ID 0000:0000
Bus 003 Device 001: ID 0000:0000
Bus 002 Device 002: ID 046d:0928 Logitech, Inc.
Bus 002 Device 001: ID 0000:0000
Bus 001 Device 001: ID 0000:0000

PLEASE HELP ME.tHANK YOU

rAKESH h.p
rakesh2485 is offline     Reply With Quote


---------------------------------------------------------------------------

===========================================================================
lsusb(8)                                            Linux USB Utilities                                            lsusb(8)



NAME
       lsusb - list USB devices

SYNOPSIS
       lsusb [ options ]

DESCRIPTION
       lsusb is a utility for displaying information about USB buses in the system and the devices connected to them.


OPTIONS
       -v, --verbose
              Tells lsusb to be verbose and display detailed information about the devices shown.  This includes configura‐
              tion descriptors for the device's current speed.  Class descriptors will be shown, when  available,  for  USB
              device classes including hub, audio, HID, communications, and chipcard.

       -s [[bus]:][devnum]
              Show only devices in specified bus and/or devnum.  Both ID's are given in decimal and may be omitted.

       -d [vendor]:[product]
              Show only devices with the specified vendor and product ID.  Both ID's are given in hexadecimal.

       -D device
              Do  not  scan the /dev/bus/usb directory, instead display only information about the device whose device file
              is given.  The device file should be something like  /dev/bus/usb/001/001.   This  option  displays  detailed
              information like the v option; you must be root to do this.

       -t     Tells lsusb to dump the physical USB device hierarchy as a tree.

       -V, --version
              Print  version information on standard output, then exit successfully.


RETURN VALUE
       If the specified device is not found, a non-zero exit code is returned.


FILES
       /usr/share/usb.ids
              A list of all known USB ID's (vendors, products, classes, subclasses and protocols).


SEE ALSO
       lspci(8)
 Manual page lsusb(8) line 1/56 91%

===========================================================================
阅读(1310) | 评论(0) | 转发(0) |
0

上一篇:i2c 协议介绍

下一篇:静态库的生成方法

给主人留下些什么吧!~~