Subfire
Subfire

Reputation:

Detect when a USB device is connected in C

I am new to C and am trying to write a program that syncs files on my computer to a USB device. It currently works my me cd'ing to the directory that the device mounts to and typing "myprog init" which creates a .myprog file. The idea then is that when a USB device is connected my program checks for the .myprog file, if it finds it then it syncs. Problem is that I can't figure out how to detect when a new USB device is connected.

I am writing the program for Linux (I'm using Ubuntu 9.04) and using GCC.

Thanks for any help :)

Upvotes: 8

Views: 14412

Answers (1)

ChristopheD
ChristopheD

Reputation: 116097

Look into udev documentation for this (writing udev rules).

Also have a look at this stackoverflow thread.

Upvotes: 4

Related Questions