Browse Source

Improved device detection: use storage device instead of usb device

Andrea Luzzardi 17 years ago
parent
commit
407928caaa
3 changed files with 31 additions and 31 deletions
  1. +17
    -7
      src/device.c
  2. +3
    -3
      tools/pamusb-agent
  3. +11
    -21
      tools/pamusb-conf

+ 17
- 7
src/device.c View File

@ -32,15 +32,25 @@ static int pusb_device_connected(t_pusb_options *opts, LibHalContext *ctx)
log_debug("Searching for \"%s\" in the hardware database...\n", log_debug("Searching for \"%s\" in the hardware database...\n",
opts->device.name); opts->device.name);
udi = pusb_hal_find_item(ctx, udi = pusb_hal_find_item(ctx,
"usb_device.serial", opts->device.serial,
"usb_device.vendor", opts->device.vendor,
"info.product", opts->device.model,
NULL);
"storage.serial", opts->device.serial,
"storage.vendor", opts->device.vendor,
"info.product", opts->device.model);
if (!udi) if (!udi)
{ {
log_error("Device \"%s\" is not connected.\n",
opts->device.name);
return (0);
/* Backward compatibility with older versions (0.4.1) */
udi = pusb_hal_find_item(ctx,
"usb_device.serial", opts->device.serial,
"usb_device.vendor", opts->device.vendor,
"info.product", opts->device.model,
NULL);
if (!udi)
{
log_error("Device \"%s\" is not connected.\n",
opts->device.name);
return (0);
}
log_error("Warning: The configuration file has been " \
"generated by an older version of pamusb-conf\n");
} }
libhal_free_string(udi); libhal_free_string(udi);
log_info("Device \"%s\" is connected (good).\n", opts->device.name); log_info("Device \"%s\" is connected (good).\n", opts->device.name);


+ 3
- 3
tools/pamusb-agent View File

@ -56,7 +56,7 @@ class HotPlugDevice:
halService = self.__bus.get_object('org.freedesktop.Hal', halService = self.__bus.get_object('org.freedesktop.Hal',
'/org/freedesktop/Hal/Manager') '/org/freedesktop/Hal/Manager')
halManager = dbus.Interface(halService, 'org.freedesktop.Hal.Manager') halManager = dbus.Interface(halService, 'org.freedesktop.Hal.Manager')
for udi in halManager.FindDeviceStringMatch('info.bus', 'usb_device'):
for udi in halManager.FindDeviceByCapability('storage'):
self.__deviceAdded(udi) self.__deviceAdded(udi)
def __registerSignals(self): def __registerSignals(self):
@ -75,9 +75,9 @@ class HotPlugDevice:
udi) udi)
deviceProperties = deviceObj.GetAllProperties( deviceProperties = deviceObj.GetAllProperties(
dbus_interface = 'org.freedesktop.Hal.Device') dbus_interface = 'org.freedesktop.Hal.Device')
if not deviceProperties.has_key('usb_device.serial'):
if not deviceProperties.has_key('storage.serial'):
return return
if deviceProperties['usb_device.serial'] != self.__serial:
if deviceProperties['storage.serial'] != self.__serial:
return return
self.__udi = udi self.__udi = udi
if self.__running: if self.__running:


+ 11
- 21
tools/pamusb-conf View File

@ -28,27 +28,14 @@ class Device:
udi) udi)
deviceProperties = deviceObj.GetAllProperties( deviceProperties = deviceObj.GetAllProperties(
dbus_interface = 'org.freedesktop.Hal.Device') dbus_interface = 'org.freedesktop.Hal.Device')
self.vendor = deviceProperties['usb_device.vendor']
self.product = deviceProperties['info.product']
self.serialNumber = deviceProperties['usb_device.serial']
if deviceProperties['storage.removable'] != 1:
raise Exception, 'Not a removable device'
self.vendor = deviceProperties['info.vendor']
self.product = deviceProperties['storage.model']
self.serialNumber = deviceProperties['storage.serial']
if len(self.volumes()) < 1: if len(self.volumes()) < 1:
raise Exception, 'Device does not contain any volume' raise Exception, 'Device does not contain any volume'
def __isChildOfDevice(self, udi):
obj = bus.get_object('org.freedesktop.Hal', udi)
properties = obj.GetAllProperties(
dbus_interface = 'org.freedesktop.Hal.Device')
if not properties.has_key('info.parent'):
return False
if properties.has_key('info.bus') and properties['info.bus'] == 'usb_device':
return False
if properties['info.parent'] == self.__udi:
return True
return self.__isChildOfDevice(properties['info.parent'])
def __repr__(self):
return "%s %s (%s)" % (self.vendor, self.product, self.serialNumber)
def volumes(self): def volumes(self):
vols = [] vols = []
for volume in halManager.FindDeviceByCapability('volume'): for volume in halManager.FindDeviceByCapability('volume'):
@ -56,14 +43,17 @@ class Device:
volume) volume)
deviceProperties = deviceObj.GetAllProperties( deviceProperties = deviceObj.GetAllProperties(
dbus_interface = 'org.freedesktop.Hal.Device') dbus_interface = 'org.freedesktop.Hal.Device')
if deviceProperties['block.major'] != 8:
if deviceProperties['info.parent'] != self.__udi:
continue continue
if not self.__isChildOfDevice(volume):
if deviceProperties['volume.is_partition'] != True:
continue continue
vols.append({'uuid' : deviceProperties['volume.uuid'], vols.append({'uuid' : deviceProperties['volume.uuid'],
'device' : deviceProperties['block.device']}) 'device' : deviceProperties['block.device']})
return vols return vols
def __repr__(self):
return "%s %s (%s)" % (self.vendor, self.product, self.serialNumber)
def listOptions(question, options, autodetect = True): def listOptions(question, options, autodetect = True):
if autodetect == True and len(options) == 1: if autodetect == True and len(options) == 1:
print question print question
@ -151,7 +141,7 @@ def addUser(options):
def addDevice(options): def addDevice(options):
devices = [] devices = []
for udi in halManager.FindDeviceStringMatch('info.bus', 'usb_device'):
for udi in halManager.FindDeviceByCapability('storage'):
try: try:
if options['verbose']: if options['verbose']:
print 'Inspecting %s' % udi print 'Inspecting %s' % udi


Loading…
Cancel
Save