0

Target: In our embedded Linux system, we want to use Qt to detect the insertion of a USB storage device, to inform the system when the USB storage device is plugged in or out, then we can mount its file system. Later we can access the files on the USB storage device.

I searched a little, it seems there are two solutions: libusb and dbus. But I still don't know how to use it. Does anyone have some examples?

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
James.Zhou
  • 131
  • 1
  • 2
  • 14
  • The USB pen should be a pointer device, isn't it? Are you sure if it is installed properly? And because you are using Linux, it is very possible to access the specific USB events using Xorg. I hope someone will come up with a nice solution. – Md. Minhazul Haque Jun 01 '16 at 16:56
  • @Md.MinhazulHaque The question doesn't refer to an input device, but to a storage device, known in some places as a usb pen drive. – Kuba hasn't forgotten Monica Jun 01 '16 at 21:01
  • "I searched a little, it seems there are two solutions: [...] dbus." DBus is not a solution to this concrete problem, it's a messaging bus. You are probably talking about some service that communicates via DBus (probably udisks). – Stefan Majewsky Jun 01 '16 at 21:26
  • @Kuba Ober Yes, only the storage device. Because our users will put some files in it, and the QT program on the PCB board should access these files. – James.Zhou Jun 02 '16 at 00:42

1 Answers1

0

The typical way to auto-mount USB storage is via udev. Udev can notify you when a device is added/mounted. You could talk to udisks via dbus to be notified of storage addition/removal as well.

libusb is only tangentially related, you shouldn't be using it unless you wish to reimplement a lot of already existing code.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • Do you have any example code for this? As I understand, it is through kernel->hotplug->udev->hal/udisks->dbus. – James.Zhou Jun 03 '16 at 06:30
  • @James.Zhou The links I've posted contain some examples that bypass dbus - that should be sufficient. I don't have any links handy for dbus examples, but google should be your friend. – Kuba hasn't forgotten Monica Jun 03 '16 at 13:07