Logo Search packages:      
Sourcecode: hal version File versions

HalDrive* hal_drive_from_udi ( LibHalContext hal_ctx,
const char *  udi 
)

Given a UDI for a HAL device of capability 'storage', this function retrieves all the relevant properties into convenient in-process data structures.

Parameters:
hal_ctx libhal context
udi HAL UDI
Returns:
HalDrive object or NULL if UDI is invalid

Definition at line 775 of file libhal-storage.c.

References hal_device_get_all_properties(), hal_device_get_property_string(), hal_device_query_capability(), hal_drive_free(), hal_free_property_set(), hal_free_string(), hal_psi_get_key(), hal_psi_get_type(), hal_psi_has_more(), hal_psi_init(), and hal_psi_next().

Referenced by hal_drive_from_device_file().

{
      char *bus_textual;
      HalDrive *drive;
      LibHalPropertySet *properties;
      LibHalPropertySetIterator it;

      drive = NULL;
      properties = NULL;
      bus_textual = NULL;

      if (!hal_device_query_capability (hal_ctx, udi, "storage"))
            goto error;

      drive = malloc (sizeof (HalDrive));
      if (drive == NULL)
            goto error;
      memset (drive, 0x00, sizeof (HalDrive));

      drive->hal_ctx = hal_ctx;

      drive->udi = strdup (udi);
      if (drive->udi == NULL)
            goto error;

      properties = hal_device_get_all_properties (hal_ctx, udi);
      if (properties == NULL)
            goto error;

      /* we can count on hal to give us all these properties */
      for (hal_psi_init (&it, properties); hal_psi_has_more (&it); hal_psi_next (&it)) {
            int type;
            char *key;
            
            type = hal_psi_get_type (&it);
            key = hal_psi_get_key (&it);

            HAL_PROP_EXTRACT_BEGIN;

            HAL_PROP_EXTRACT_INT    ("block.minor",               drive->device_minor);
            HAL_PROP_EXTRACT_INT    ("block.major",               drive->device_major);
            HAL_PROP_EXTRACT_STRING ("block.device",              drive->device_file);
            HAL_PROP_EXTRACT_STRING ("storage.bus",               bus_textual);
            HAL_PROP_EXTRACT_STRING ("storage.vendor",            drive->vendor);
            HAL_PROP_EXTRACT_STRING ("storage.model",             drive->model);
            HAL_PROP_EXTRACT_STRING ("storage.drive_type",        drive->type_textual);


            HAL_PROP_EXTRACT_STRING ("storage.icon.drive",        drive->dedicated_icon_drive);
            HAL_PROP_EXTRACT_STRING ("storage.icon.volume",       drive->dedicated_icon_volume);

            HAL_PROP_EXTRACT_BOOL   ("storage.hotpluggable",      drive->is_hotpluggable);
            HAL_PROP_EXTRACT_BOOL   ("storage.removable",         drive->is_removable);
            HAL_PROP_EXTRACT_BOOL   ("storage.requires_eject",    drive->requires_eject);

            HAL_PROP_EXTRACT_STRING ("storage.physical_device",   drive->physical_device);
            HAL_PROP_EXTRACT_STRING ("storage.firmware_version",  drive->firmware_version);
            HAL_PROP_EXTRACT_STRING ("storage.serial",            drive->serial);

            HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.cdr", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_CDR);
            HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.cdrw", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_CDRW);
            HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvd", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDROM);
            HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdplusr", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDPLUSR);
            HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdplusrw", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDPLUSRW);
            HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdr", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDR);
            HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdrw", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDRW);
            HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdram", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDRAM);

            HAL_PROP_EXTRACT_BOOL   ("storage.policy.should_mount",        drive->should_mount);
            HAL_PROP_EXTRACT_STRING ("storage.policy.desired_mount_point", drive->desired_mount_point);
            HAL_PROP_EXTRACT_STRING ("storage.policy.mount_filesystem",    drive->mount_filesystem);

            HAL_PROP_EXTRACT_BOOL   ("storage.no_partitions_hint",        drive->no_partitions_hint);

            HAL_PROP_EXTRACT_END;
      }

      if (drive->type_textual != NULL) {
            if (strcmp (drive->type_textual, "cdrom") == 0) {
                  drive->cdrom_caps |= HAL_DRIVE_CDROM_CAPS_CDROM;
                  drive->type = HAL_DRIVE_TYPE_CDROM;
            } else if (strcmp (drive->type_textual, "floppy") == 0) {
                  drive->type = HAL_DRIVE_TYPE_FLOPPY;
            } else if (strcmp (drive->type_textual, "disk") == 0) {
                  if (drive->is_removable)
                        drive->type = HAL_DRIVE_TYPE_REMOVABLE_DISK;
                  else
                        drive->type = HAL_DRIVE_TYPE_DISK;                    
            } else if (strcmp (drive->type_textual, "tape") == 0) {
                  drive->type = HAL_DRIVE_TYPE_TAPE;
            } else if (strcmp (drive->type_textual, "compact_flash") == 0) {
                  drive->type = HAL_DRIVE_TYPE_COMPACT_FLASH;
            } else if (strcmp (drive->type_textual, "memory_stick") == 0) {
                  drive->type = HAL_DRIVE_TYPE_MEMORY_STICK;
            } else if (strcmp (drive->type_textual, "smart_media") == 0) {
                  drive->type = HAL_DRIVE_TYPE_SMART_MEDIA;
            } else if (strcmp (drive->type_textual, "sd_mmc") == 0) {
                  drive->type = HAL_DRIVE_TYPE_SD_MMC;
/*
            } else if (strcmp (drive->type_textual, "zip") == 0) {
                  drive->type = HAL_DRIVE_TYPE_ZIP;
            } else if (strcmp (drive->type_textual, "jaz") == 0) {
                  drive->type = HAL_DRIVE_TYPE_JAZ;
*/
            } else {
                    drive->type = HAL_DRIVE_TYPE_DISK; 
            }

      }

      /* check if physical device is a camera or mp3 player */
      if (drive->physical_device != NULL) {
            char *category;

            category = hal_device_get_property_string (hal_ctx, drive->physical_device, "info.category");
            if (category != NULL) {
                  if (strcmp (category, "portable_audio_player") == 0) {
                        drive->type = HAL_DRIVE_TYPE_PORTABLE_AUDIO_PLAYER;
                  } else if (strcmp (category, "camera") == 0) {
                        drive->type = HAL_DRIVE_TYPE_CAMERA;
                  }

                  hal_free_string (category);
            }
      }

      if (bus_textual != NULL) {
            if (strcmp (bus_textual, "usb") == 0) {
                  drive->bus = HAL_DRIVE_BUS_USB;
            } else if (strcmp (bus_textual, "ieee1394") == 0) {
                  drive->bus = HAL_DRIVE_BUS_IEEE1394;
            } else if (strcmp (bus_textual, "ide") == 0) {
                  drive->bus = HAL_DRIVE_BUS_IDE;
            } else if (strcmp (bus_textual, "scsi") == 0) {
                  drive->bus = HAL_DRIVE_BUS_SCSI;
            }
      }

      hal_free_string (bus_textual);
      hal_free_property_set (properties);

      return drive;

error:
      hal_free_string (bus_textual);
      hal_free_property_set (properties);
      hal_drive_free (drive);
      return NULL;
}


Generated by  Doxygen 1.6.0   Back to index