# PC as USB gadget (slave mode)?

## koan

Hello,

It it possible for a standard PC with standard USB 2.0 ports to act as a USB slave?  So that you could expose part of the file system as a usb storage device to another PC or machine?

Does anyone know what is involved?

Cheers,

Paul

----------

## NeddySeagoon

koan,

You cannot connect two USB root hubs together (the electronics in a PC) but there are adapter cables, with electronics in the middle to allow the connection.

I don't know if you can use these USB devices in Linux. 

Its lower cost to use ethernet, even if you have to buy two network cards and the cable.

----------

## koan

Yeah, something like this I guess:

http://www.linkusb.com/

So that leaves the other part of my question - how would I go about exposing part of the file system as a usb mass storage device?

----------

## John R. Graham

I don't think there is such a solution, nor, with the extremely low cost of Ethernet and WiFi, is there much incentive to create one.

The normal solution would be to use traditional networking and NFS to expose storage on one machine to another.  Any special reason why this isn't appropriate in your case?

- John

----------

## koan

 *john_r_graham wrote:*   

> I don't think there is such a solution, nor, with the extremely low cost of Ethernet and WiFi, is there much incentive to create one.
> 
> The normal solution would be to use traditional networking and NFS to expose storage on one machine to another.  Any special reason why this isn't appropriate in your case?
> 
> 

 

Yes there is.  Hence the question.

There are plenty of linux devices out there that expose file systems as usb gadgets.  The Nokia n900 for one.

I am asking if anyone here knows how to do it (leaving aside hardware issues for the time being as it has been addressed to a degree in the first response).

----------

## John R. Graham

Sorry if I was unclear.  I'm not saying it can't be done (on a generic IA32 Linux box).  I'm saying it hasn't been done and is not likely to be done.

- John

----------

## boerKrelis

sys-block/endpoint does that for Firewire. That is, it exports block devices. I haven't seen anything like that for USB.

And I'm having a hard time seeing how you intend to block-address part of a filesystem. There's a reason mount will not let you mount already mounted filesystems.

----------

## MotivatedTea

Some googling turned up this: http://www.linux-usb.org/gadget/

It looks like what you're trying to do requires special hardware that PC's don't have. Your standard PC is going to have a USB host controller, not a USB peripheral controller. Even if you do happen to have one, it looks like you'll still need to do some programming yourself to get what you're asking for working. The page above recommends implementing ethernet-over-USB and then sharing files via NFS or Samba.

----------

## depontius

```
user@localhost ~ $ grep -i gadget /usr/src/linux/.config

# CONFIG_USB_GADGET is not set

user@localhost ~ $ ls -l /usr/src/linux/Documentation/usb/*gadget*

-rw-r--r-- 1 root root 10976 Sep  9 18:13 /usr/src/linux/Documentation/usb/gadget_printer.txt

-rw-r--r-- 1 root root 13377 Sep  9 18:13 /usr/src/linux/Documentation/usb/gadget_serial.txt
```

Obviously I haven't enabled it, but I do rather wish for one.  Eventually I want to make my mythtv backend drive a cable box.  The normal way to do that is with an IR blaster, but the blaster on my capture card (hvr-1600) is out-of-tree for LIRC, and from what I've heard Scientific Atlanta boxes can be a bear on the IR modulation side.  In the meantime, the box has a USB connector on front, and just for jollies I once plugged a keyboard into it and drove the box from that.

When reading the USB gadget documentation, they suggested a keyboard driver as one possibility, if only for a demo.  If only it existed, I could get the translation hardware and I'd be in business.  As near as I can tell, it would be much simpler than getting LIRC to work with a "hostile" cable box.

----------

