简体   繁体   中英

How do I detect usb drive insertion in Linux?

I've written an application for an embedded linux project, and I want my application to display a particular menu when the user inserts a USB drive. I'm programming the application in C++ with Qt.

My system doesn't have d-bus but it is using udev. It seems to me that udev is the "proper" way to do this detection, but seems complicated.

Can anyone point me in the right direction to get started with this? Is there a way to do it without udev, and if not, is there a good "getting started" guide for udev I could use? I really don't need much functionality, just a way for my application to be notified when a drive is inserted (and enough info for my app to mount the drive).

Thanks

Marlon

The section "libudev - Monitoring Interface" of this document http://www.signal11.us/oss/udev/ should get you started.
Instead of a while(1) loop and a sleep, just make a function with that stuff and then set up a periodic Qt timer to call it every half second or whatever.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM