Logo Search packages:      
Sourcecode: hal version File versions

HalVolume* hal_volume_from_udi ( LibHalContext hal_ctx,
const char *  udi 

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

hal_ctx libhal context
HalVolume object or NULL if UDI is invalid

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

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

Referenced by hal_volume_from_device_file().

      char *disc_type_textual;
      HalVolume *vol;
      LibHalPropertySet *properties;
      LibHalPropertySetIterator it;

      vol = NULL;
      properties = NULL;
      disc_type_textual = NULL;

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

      vol = malloc (sizeof (HalVolume));
      if (vol == NULL)
            goto error;
      memset (vol, 0x00, sizeof (HalVolume));

      vol->udi = strdup (udi);

      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_INT    ("volume.partition.msdos_part_table_type", vol->msdos_part_table_type);

            HAL_PROP_EXTRACT_INT    ("block.minor",               vol->device_minor);
            HAL_PROP_EXTRACT_INT    ("block.major",               vol->device_major);
            HAL_PROP_EXTRACT_STRING ("block.device",              vol->device_file);

            HAL_PROP_EXTRACT_STRING ("block.storage_device",      vol->storage_device);

            HAL_PROP_EXTRACT_INT    ("volume.block_size",         vol->block_size);
            HAL_PROP_EXTRACT_INT    ("volume.num_blocks",         vol->num_blocks);
            HAL_PROP_EXTRACT_STRING ("volume.label",              vol->volume_label);
            HAL_PROP_EXTRACT_STRING ("volume.mount_point",        vol->mount_point);
            HAL_PROP_EXTRACT_STRING ("volume.fstype",             vol->fstype);
            HAL_PROP_EXTRACT_BOOL   ("volume.is_mounted",         vol->is_mounted);

            HAL_PROP_EXTRACT_BOOL   ("volume.is_disc",            vol->is_disc);
            HAL_PROP_EXTRACT_STRING ("volume.disc.type",          disc_type_textual);
            HAL_PROP_EXTRACT_BOOL   ("volume.disc.has_audio",     vol->disc_has_audio);
            HAL_PROP_EXTRACT_BOOL   ("volume.disc.has_data",      vol->disc_has_data);
            HAL_PROP_EXTRACT_BOOL   ("volume.disc.is_appendable", vol->disc_is_appendable);
            HAL_PROP_EXTRACT_BOOL   ("volume.disc.is_blank",      vol->disc_is_blank);
            HAL_PROP_EXTRACT_BOOL   ("volume.disc.is_rewritable", vol->disc_is_rewritable);

            HAL_PROP_EXTRACT_BOOL   ("volume.policy.should_mount",        vol->should_mount);
            HAL_PROP_EXTRACT_STRING ("volume.policy.desired_mount_point", vol->desired_mount_point);
            HAL_PROP_EXTRACT_STRING ("volume.policy.mount_filesystem",    vol->mount_filesystem);


      if (disc_type_textual != NULL) {
            if (strcmp (disc_type_textual, "cd_rom") == 0) {
                  vol->disc_type = HAL_VOLUME_DISC_TYPE_CDROM;
            } else if (strcmp (disc_type_textual, "cd_r") == 0) {
                  vol->disc_type = HAL_VOLUME_DISC_TYPE_CDR;
            } else if (strcmp (disc_type_textual, "cd_rw") == 0) {
                  vol->disc_type = HAL_VOLUME_DISC_TYPE_CDRW;
            } else if (strcmp (disc_type_textual, "dvd_rom") == 0) {
                  vol->disc_type = HAL_VOLUME_DISC_TYPE_DVDROM;
            } else if (strcmp (disc_type_textual, "dvd_ram") == 0) {
                  vol->disc_type = HAL_VOLUME_DISC_TYPE_DVDRAM;
            } else if (strcmp (disc_type_textual, "dvd_r") == 0) {
                  vol->disc_type = HAL_VOLUME_DISC_TYPE_DVDR;
            } else if (strcmp (disc_type_textual, "dvd_rw") == 0) {
                  vol->disc_type = HAL_VOLUME_DISC_TYPE_DVDRW;
            } else if (strcmp (disc_type_textual, "dvd_plusr") == 0) {
                  vol->disc_type = HAL_VOLUME_DISC_TYPE_DVDPLUSR;
            } else if (strcmp (disc_type_textual, "dvd_plusrw") == 0) {
                  vol->disc_type = HAL_VOLUME_DISC_TYPE_DVDPLUSRW;

      hal_free_string (disc_type_textual);
      hal_free_property_set (properties);
      return vol;
      hal_free_string (disc_type_textual);
      hal_free_property_set (properties);
      hal_volume_free (vol);
      return NULL;

Generated by  Doxygen 1.6.0   Back to index