00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 # include <config.h>
00030 #endif
00031
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035 #include <dbus/dbus.h>
00036
00037 #include "../libhal/libhal.h"
00038 #include "libhal-storage.h"
00039
00040
00041 #ifdef ENABLE_NLS
00042 # include <libintl.h>
00043 # define _(String) dgettext (GETTEXT_PACKAGE, String)
00044 # ifdef gettext_noop
00045 # define N_(String) gettext_noop (String)
00046 # else
00047 # define N_(String) (String)
00048 # endif
00049 #else
00050
00051 # define textdomain(String) (String)
00052 # define gettext(String) (String)
00053 # define dgettext(Domain,Message) (Message)
00054 # define dcgettext(Domain,Message,Type) (Message)
00055 # define bindtextdomain(Domain,Directory) (Domain)
00056 # define _(String)
00057 # define N_(String) (String)
00058 #endif
00059
00067 typedef struct IconMappingEntry_s {
00068 HalStoragePolicyIcon icon;
00069 char *path;
00070 struct IconMappingEntry_s *next;
00071 } IconMappingEntry;
00072
00073 struct HalStoragePolicy_s {
00074 IconMappingEntry *icon_mappings;
00075 };
00076
00077 HalStoragePolicy *
00078 hal_storage_policy_new ()
00079 {
00080 HalStoragePolicy *p;
00081
00082 p = malloc (sizeof (HalStoragePolicy));
00083 if (p == NULL)
00084 goto out;
00085
00086 p->icon_mappings = NULL;
00087 out:
00088 return p;
00089 }
00090
00091 void
00092 hal_storage_policy_free (HalStoragePolicy *policy)
00093 {
00094 IconMappingEntry *i;
00095 IconMappingEntry *j;
00096
00097
00098 for (i = policy->icon_mappings; i != NULL; i = j) {
00099 j = i->next;
00100 free (i->path);
00101 free (i);
00102 }
00103
00104 free (policy);
00105 }
00106
00107 void
00108 hal_storage_policy_set_icon_path (HalStoragePolicy *policy, HalStoragePolicyIcon icon, const char *path)
00109 {
00110 IconMappingEntry *i;
00111
00112
00113 for (i = policy->icon_mappings; i != NULL; i = i->next) {
00114 if (i->icon == icon) {
00115 free (i->path);
00116 i->path = strdup (path);
00117 goto out;
00118 }
00119 }
00120
00121 i = malloc (sizeof (IconMappingEntry));
00122 if (i == NULL)
00123 goto out;
00124 i->icon = icon;
00125 i->path = strdup (path);
00126 i->next = policy->icon_mappings;
00127 policy->icon_mappings = i;
00128
00129 out:
00130 return;
00131 }
00132
00133 void
00134 hal_storage_policy_set_icon_mapping (HalStoragePolicy *policy, HalStoragePolicyIconPair *pairs)
00135 {
00136 HalStoragePolicyIconPair *i;
00137
00138 for (i = pairs; i->icon != 0x00; i++) {
00139 hal_storage_policy_set_icon_path (policy, i->icon, i->icon_path);
00140 }
00141 }
00142
00143 const char *
00144 hal_storage_policy_lookup_icon (HalStoragePolicy *policy, HalStoragePolicyIcon icon)
00145 {
00146 IconMappingEntry *i;
00147 const char *path;
00148
00149 path = NULL;
00150 for (i = policy->icon_mappings; i != NULL; i = i->next) {
00151 if (i->icon == icon) {
00152 path = i->path;
00153 goto out;
00154 }
00155 }
00156 out:
00157 return path;
00158 }
00159
00160
00161 #define MAX_STRING_SZ 256
00162
00163 char *
00164 hal_volume_policy_compute_size_as_string (HalVolume *volume)
00165 {
00166 dbus_uint64_t size;
00167 char *result;
00168 char* sizes_str[] = {"K", "M", "G", "T", NULL};
00169 dbus_uint64_t cur = 1000L;
00170 dbus_uint64_t base = 10L;
00171 dbus_uint64_t step = 10L*10L*10L;
00172 int cur_str = 0;
00173 char buf[MAX_STRING_SZ];
00174
00175 result = NULL;
00176
00177 size = hal_volume_get_size (volume);
00178
00179 do {
00180 if (sizes_str[cur_str+1] == NULL || size < cur*step) {
00181
00182 if (size < cur*base) {
00183 snprintf (buf, MAX_STRING_SZ, "%.01f%s",
00184 ((double)size)/((double)cur), sizes_str[cur_str]);
00185 result = strdup (buf);
00186 } else {
00187 snprintf (buf, MAX_STRING_SZ, "%lld%s", size / cur, sizes_str[cur_str]);
00188 result = strdup (buf);
00189 }
00190 goto out;
00191 }
00192
00193 cur *= step;
00194 cur_str++;
00195 } while (1);
00196
00197 out:
00198 return result;
00199 }
00200
00201 static void
00202 fixup_string (char *s)
00203 {
00204
00205
00206
00207
00208 }
00209
00210
00211 char *
00212 hal_drive_policy_compute_display_name (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy)
00213 {
00214 char *name;
00215 char *size_str;
00216 char *vendormodel_str;
00217 const char *model;
00218 const char *vendor;
00219 HalDriveType drive_type;
00220 dbus_bool_t drive_is_hotpluggable;
00221 dbus_bool_t drive_is_removable;
00222 HalDriveCdromCaps drive_cdrom_caps;
00223 char buf[MAX_STRING_SZ];
00224
00225 model = hal_drive_get_model (drive);
00226 vendor = hal_drive_get_vendor (drive);
00227 drive_type = hal_drive_get_type (drive);
00228 drive_is_hotpluggable = hal_drive_is_hotpluggable (drive);
00229 drive_is_removable = hal_drive_uses_removable_media (drive);
00230 drive_cdrom_caps = hal_drive_get_cdrom_caps (drive);
00231
00232 if (volume != NULL)
00233 size_str = hal_volume_policy_compute_size_as_string (volume);
00234 else
00235 size_str = NULL;
00236
00237 if (vendor == NULL || strlen (vendor) == 0) {
00238 if (model == NULL || strlen (model) == 0)
00239 vendormodel_str = strdup ("");
00240 else
00241 vendormodel_str = strdup (model);
00242 } else {
00243 if (model == NULL || strlen (model) == 0)
00244 vendormodel_str = strdup (vendor);
00245 else {
00246 snprintf (buf, MAX_STRING_SZ, "%s %s", vendor, model);
00247 vendormodel_str = strdup (buf);
00248 }
00249 }
00250
00251 fixup_string (vendormodel_str);
00252
00253 if (drive_type==HAL_DRIVE_TYPE_CDROM) {
00254
00255
00256 char *first;
00257 char *second;
00258
00259
00260 first = "CD-ROM";
00261 if (drive_cdrom_caps & HAL_DRIVE_CDROM_CAPS_CDR)
00262 first = "CD-R";
00263 if (drive_cdrom_caps & HAL_DRIVE_CDROM_CAPS_CDRW)
00264 first = "CD-RW";
00265
00266 second = "";
00267 if (drive_cdrom_caps & HAL_DRIVE_CDROM_CAPS_DVDROM)
00268 second = "/DVD-ROM";
00269 if (drive_cdrom_caps & HAL_DRIVE_CDROM_CAPS_DVDPLUSR)
00270 second = "/DVD+R";
00271 if (drive_cdrom_caps & HAL_DRIVE_CDROM_CAPS_DVDPLUSRW)
00272 second = "/DVD+RW";
00273 if (drive_cdrom_caps & HAL_DRIVE_CDROM_CAPS_DVDR)
00274 second = "/DVD-R";
00275 if (drive_cdrom_caps & HAL_DRIVE_CDROM_CAPS_DVDRW)
00276 second = "/DVD-RW";
00277 if (drive_cdrom_caps & HAL_DRIVE_CDROM_CAPS_DVDRAM)
00278 second = "/DVD-RAM";
00279 if ((drive_cdrom_caps & HAL_DRIVE_CDROM_CAPS_DVDR) &&
00280 (drive_cdrom_caps & HAL_DRIVE_CDROM_CAPS_DVDPLUSR))
00281 second = "/DVD±R";
00282 if ((drive_cdrom_caps & HAL_DRIVE_CDROM_CAPS_DVDRW) &&
00283 (drive_cdrom_caps & HAL_DRIVE_CDROM_CAPS_DVDPLUSRW))
00284 second = "/DVD±RW";
00285
00286
00287 if (drive_is_hotpluggable) {
00288 snprintf (buf, MAX_STRING_SZ, _("External %s%s Drive"), first, second);
00289 name = strdup (buf);
00290 } else {
00291 snprintf (buf, MAX_STRING_SZ, _("%s%s Drive"), first, second);
00292 name = strdup (buf);
00293 }
00294
00295 } else if (drive_type==HAL_DRIVE_TYPE_FLOPPY) {
00296
00297
00298
00299 if (drive_is_hotpluggable)
00300 name = strdup (_("External Floppy Drive"));
00301 else
00302 name = strdup (_("Floppy Drive"));
00303 } else if (drive_type==HAL_DRIVE_TYPE_DISK && !drive_is_removable) {
00304
00305
00306
00307 if (size_str != NULL) {
00308 if (drive_is_hotpluggable) {
00309 snprintf (buf, MAX_STRING_SZ, _("%s External Hard Drive"), size_str);
00310 name = strdup (buf);
00311 } else {
00312 snprintf (buf, MAX_STRING_SZ, _("%s Hard Drive"), size_str);
00313 name = strdup (buf);
00314 }
00315 } else {
00316 if (drive_is_hotpluggable)
00317 name = strdup (_("External Hard Drive"));
00318 else
00319 name = strdup (_("Hard Drive"));
00320 }
00321 } else {
00322
00323
00324
00325 if (strlen (vendormodel_str) > 0)
00326 name = strdup (vendormodel_str);
00327 else
00328 name = strdup (_("Drive"));
00329 }
00330
00331 free (vendormodel_str);
00332 free (size_str);
00333
00334 return name;
00335 }
00336
00337 char *
00338 hal_volume_policy_compute_display_name (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy)
00339 {
00340 char *name;
00341 char *size_str;
00342 const char *volume_label;
00343 const char *model;
00344 const char *vendor;
00345 HalDriveType drive_type;
00346 dbus_bool_t drive_is_hotpluggable;
00347 dbus_bool_t drive_is_removable;
00348 HalDriveCdromCaps drive_cdrom_caps;
00349 char buf[MAX_STRING_SZ];
00350
00351 volume_label = hal_volume_get_label (volume);
00352 model = hal_drive_get_model (drive);
00353 vendor = hal_drive_get_vendor (drive);
00354 drive_type = hal_drive_get_type (drive);
00355 drive_is_hotpluggable = hal_drive_is_hotpluggable (drive);
00356 drive_is_removable = hal_drive_uses_removable_media (drive);
00357 drive_cdrom_caps = hal_drive_get_cdrom_caps (drive);
00358
00359 size_str = hal_volume_policy_compute_size_as_string (volume);
00360
00361
00362
00363
00364
00365 if (volume_label != NULL) {
00366 name = strdup (volume_label);
00367 goto out;
00368 }
00369
00370
00371 if (drive_type==HAL_DRIVE_TYPE_CDROM) {
00372 switch (hal_volume_get_disc_type (volume)) {
00373
00374 default:
00375
00376 case HAL_VOLUME_DISC_TYPE_CDROM:
00377 name = strdup (_("CD-ROM Disc"));
00378 break;
00379
00380 case HAL_VOLUME_DISC_TYPE_CDR:
00381 if (hal_volume_disc_is_blank (volume))
00382 name = strdup (_("Blank CD-R Disc"));
00383 else
00384 name = strdup (_("CD-R Disc"));
00385 break;
00386
00387 case HAL_VOLUME_DISC_TYPE_CDRW:
00388 if (hal_volume_disc_is_blank (volume))
00389 name = strdup (_("Blank CD-RW Disc"));
00390 else
00391 name = strdup (_("CD-RW Disc"));
00392 break;
00393
00394 case HAL_VOLUME_DISC_TYPE_DVDROM:
00395 name = strdup (_("DVD-ROM Disc"));
00396 break;
00397
00398 case HAL_VOLUME_DISC_TYPE_DVDRAM:
00399 if (hal_volume_disc_is_blank (volume))
00400 name = strdup (_("Blank DVD-RAM Disc"));
00401 else
00402 name = strdup (_("DVD-RAM Disc"));
00403 break;
00404
00405 case HAL_VOLUME_DISC_TYPE_DVDR:
00406 if (hal_volume_disc_is_blank (volume))
00407 name = strdup (_("Blank DVD-R Disc"));
00408 else
00409 name = strdup (_("DVD-R Disc"));
00410 break;
00411
00412 case HAL_VOLUME_DISC_TYPE_DVDRW:
00413 if (hal_volume_disc_is_blank (volume))
00414 name = strdup (_("Blank DVD-RW Disc"));
00415 else
00416 name = strdup (_("DVD-RW Disc"));
00417
00418 break;
00419
00420 case HAL_VOLUME_DISC_TYPE_DVDPLUSR:
00421 if (hal_volume_disc_is_blank (volume))
00422 name = strdup (_("Blank DVD+R Disc"));
00423 else
00424 name = strdup (_("DVD+R Disc"));
00425 break;
00426
00427 case HAL_VOLUME_DISC_TYPE_DVDPLUSRW:
00428 if (hal_volume_disc_is_blank (volume))
00429 name = strdup (_("Blank DVD+RW Disc"));
00430 else
00431 name = strdup (_("DVD+RW Disc"));
00432 break;
00433 }
00434
00435
00436 if (hal_volume_disc_has_audio (volume) && !hal_volume_disc_has_data (volume)) {
00437 free (name);
00438 name = strdup (_("Audio Disc"));
00439 }
00440
00441 goto out;
00442 }
00443
00444
00445 if (drive_is_removable) {
00446 snprintf (buf, MAX_STRING_SZ, _("%s Removable Media"), size_str);
00447 name = strdup (buf);
00448 } else {
00449 snprintf (buf, MAX_STRING_SZ, _("%s Media"), size_str);
00450 name = strdup (buf);
00451 }
00452
00453
00454
00455
00456 out:
00457 free (size_str);
00458 return name;
00459 }
00460
00461 char *
00462 hal_drive_policy_compute_icon_name (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy)
00463 {
00464 const char *name;
00465 HalDriveBus bus;
00466 HalDriveType drive_type;
00467
00468 bus = hal_drive_get_bus (drive);
00469 drive_type = hal_drive_get_type (drive);
00470
00471
00472
00473 switch (drive_type) {
00474 case HAL_DRIVE_TYPE_REMOVABLE_DISK:
00475 case HAL_DRIVE_TYPE_DISK:
00476 case HAL_DRIVE_TYPE_CDROM:
00477 case HAL_DRIVE_TYPE_FLOPPY:
00478 name = hal_storage_policy_lookup_icon (policy, 0x10000 + drive_type*0x100 + bus);
00479 break;
00480
00481 default:
00482 name = hal_storage_policy_lookup_icon (policy, 0x10000 + drive_type*0x100);
00483 }
00484
00485 if (name != NULL)
00486 return strdup (name);
00487 else
00488 return NULL;
00489 }
00490
00491 char *
00492 hal_volume_policy_compute_icon_name (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy)
00493 {
00494 const char *name;
00495 HalDriveBus bus;
00496 HalDriveType drive_type;
00497 HalVolumeDiscType disc_type;
00498
00499
00500
00501 if (hal_volume_is_disc (volume)) {
00502 disc_type = hal_volume_get_disc_type (volume);
00503 name = hal_storage_policy_lookup_icon (policy, 0x30000 + disc_type);
00504 goto out;
00505 }
00506
00507 if (drive == NULL) {
00508 name = hal_storage_policy_lookup_icon (policy, HAL_STORAGE_ICON_VOLUME_REMOVABLE_DISK);
00509 goto out;
00510 }
00511
00512 bus = hal_drive_get_bus (drive);
00513 drive_type = hal_drive_get_type (drive);
00514
00515 switch (drive_type) {
00516 case HAL_DRIVE_TYPE_REMOVABLE_DISK:
00517 case HAL_DRIVE_TYPE_DISK:
00518 case HAL_DRIVE_TYPE_CDROM:
00519 case HAL_DRIVE_TYPE_FLOPPY:
00520 name = hal_storage_policy_lookup_icon (policy, 0x20000 + drive_type*0x100 + bus);
00521 break;
00522
00523 default:
00524 name = hal_storage_policy_lookup_icon (policy, 0x20000 + drive_type*0x100);
00525 }
00526 out:
00527 if (name != NULL)
00528 return strdup (name);
00529 else
00530 return NULL;
00531 }
00532
00549 dbus_bool_t
00550 hal_volume_policy_should_be_visible (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy,
00551 const char *target_mount_point)
00552 {
00553 unsigned int i;
00554 dbus_bool_t is_visible;
00555 const char *label;
00556 const char *mount_point;
00557 const char *fstype;
00558 const char *fhs23_toplevel_mount_points[] = {
00559 "/",
00560 "/bin",
00561 "/boot",
00562 "/dev",
00563 "/etc",
00564 "/home",
00565 "/lib",
00566 "/lib64",
00567 "/media",
00568 "/mnt",
00569 "/opt",
00570 "/root",
00571 "/sbin",
00572 "/srv",
00573 "/tmp",
00574 "/usr",
00575 "/var",
00576 "/proc",
00577 "/sbin",
00578 NULL
00579 };
00580
00581 is_visible = FALSE;
00582
00583
00584 if (hal_volume_get_fsusage (volume) != HAL_VOLUME_USAGE_MOUNTABLE_FILESYSTEM)
00585 goto out;
00586
00587 label = hal_volume_get_label (volume);
00588 mount_point = hal_volume_get_mount_point (volume);
00589 fstype = hal_volume_get_fstype (volume);
00590
00591
00592 if (mount_point == NULL)
00593 mount_point = target_mount_point;
00594
00595
00596 if (mount_point != NULL) {
00597 for (i = 0; fhs23_toplevel_mount_points[i] != NULL; i++) {
00598 if (strcmp (mount_point, fhs23_toplevel_mount_points[i]) == 0)
00599 goto out;
00600 }
00601 }
00602
00603
00604 if (label != NULL && fstype != NULL && strcmp (label, "bootstrap") == 0 && strcmp (fstype, "hfs") == 0)
00605 goto out;
00606
00607
00608 is_visible = TRUE;
00609
00610 out:
00611 return is_visible;
00612 }
00613
00614
00615
00616 #define MOUNT_OPTIONS_SIZE 256
00617
00618 struct HalDrive_s {
00619 char *udi;
00620
00621 int device_major;
00622 int device_minor;
00623 char *device_file;
00624
00625 HalDriveBus bus;
00626 char *vendor;
00627 char *model;
00628 dbus_bool_t is_hotpluggable;
00629 dbus_bool_t is_removable;
00630 dbus_bool_t requires_eject;
00631
00632 HalDriveType type;
00633 char *type_textual;
00634
00635 char *physical_device;
00636
00637
00638 char *dedicated_icon_drive;
00639 char *dedicated_icon_volume;
00640
00641 char *serial;
00642 char *firmware_version;
00643 HalDriveCdromCaps cdrom_caps;
00644
00645 char *desired_mount_point;
00646 char *mount_filesystem;
00647 dbus_bool_t should_mount;
00648
00649 dbus_bool_t no_partitions_hint;
00650
00651 LibHalContext *hal_ctx;
00652
00653 char mount_options[MOUNT_OPTIONS_SIZE];
00654 };
00655
00656 struct HalVolume_s {
00657 char *udi;
00658
00659 int device_major;
00660 int device_minor;
00661 char *device_file;
00662 char *volume_label;
00663 dbus_bool_t is_mounted;
00664 char *mount_point;
00665 char *fstype;
00666 char *fsversion;
00667 char *uuid;
00668 char *storage_device;
00669
00670 HalVolumeUsage fsusage;
00671
00672 dbus_bool_t is_partition;
00673 unsigned int partition_number;
00674
00675 int msdos_part_table_type;
00676
00677
00678 dbus_bool_t is_disc;
00679 HalVolumeDiscType disc_type;
00680 dbus_bool_t disc_has_audio;
00681 dbus_bool_t disc_has_data;
00682 dbus_bool_t disc_is_appendable;
00683 dbus_bool_t disc_is_blank;
00684 dbus_bool_t disc_is_rewritable;
00685
00686 unsigned int block_size;
00687 unsigned int num_blocks;
00688
00689 char *desired_mount_point;
00690 char *mount_filesystem;
00691 dbus_bool_t should_mount;
00692
00693 char mount_options[MOUNT_OPTIONS_SIZE];
00694 };
00695
00696 const char *
00697 hal_drive_get_dedicated_icon_drive (HalDrive *drive)
00698 {
00699 return drive->dedicated_icon_drive;
00700 }
00701
00702 const char *
00703 hal_drive_get_dedicated_icon_volume (HalDrive *drive)
00704 {
00705 return drive->dedicated_icon_volume;
00706 }
00707
00712 void
00713 hal_drive_free (HalDrive *drive)
00714 {
00715 if (drive == NULL )
00716 return;
00717
00718 free (drive->udi);
00719 hal_free_string (drive->device_file);
00720 hal_free_string (drive->vendor);
00721 hal_free_string (drive->model);
00722 hal_free_string (drive->type_textual);
00723 hal_free_string (drive->physical_device);
00724 hal_free_string (drive->serial);
00725 hal_free_string (drive->firmware_version);
00726 hal_free_string (drive->desired_mount_point);
00727 hal_free_string (drive->mount_filesystem);
00728 }
00729
00730
00735 void
00736 hal_volume_free (HalVolume *vol)
00737 {
00738 if (vol == NULL )
00739 return;
00740
00741 free (vol->udi);
00742 hal_free_string (vol->device_file);
00743 hal_free_string (vol->volume_label);
00744 hal_free_string (vol->fstype);
00745 hal_free_string (vol->mount_point);
00746 hal_free_string (vol->fsversion);
00747 hal_free_string (vol->uuid);
00748 hal_free_string (vol->desired_mount_point);
00749 hal_free_string (vol->mount_filesystem);
00750 }
00751
00752
00753
00754
00755 #define HAL_PROP_EXTRACT_BEGIN if (FALSE)
00756 #define HAL_PROP_EXTRACT_END ;
00757 #define HAL_PROP_EXTRACT_INT(_property_, _where_) else if (strcmp (key, _property_) == 0 && type == DBUS_TYPE_INT32) _where_ = hal_psi_get_int (&it)
00758 #define HAL_PROP_EXTRACT_STRING(_property_, _where_) else if (strcmp (key, _property_) == 0 && type == DBUS_TYPE_STRING) _where_ = (hal_psi_get_string (&it) != NULL && strlen (hal_psi_get_string (&it)) > 0) ? strdup (hal_psi_get_string (&it)) : NULL
00759 #define HAL_PROP_EXTRACT_BOOL(_property_, _where_) else if (strcmp (key, _property_) == 0 && type == DBUS_TYPE_BOOLEAN) _where_ = hal_psi_get_bool (&it)
00760 #define HAL_PROP_EXTRACT_BOOL_BITFIELD(_property_, _where_, _field_) else if (strcmp (key, _property_) == 0 && type == DBUS_TYPE_BOOLEAN) _where_ |= hal_psi_get_bool (&it) ? _field_ : 0
00761
00770 HalDrive *
00771 hal_drive_from_udi (LibHalContext *hal_ctx, const char *udi)
00772 {
00773 char *bus_textual;
00774 HalDrive *drive;
00775 LibHalPropertySet *properties;
00776 LibHalPropertySetIterator it;
00777
00778 drive = NULL;
00779 properties = NULL;
00780 bus_textual = NULL;
00781
00782 if (!hal_device_query_capability (hal_ctx, udi, "storage"))
00783 goto error;
00784
00785 drive = malloc (sizeof (HalDrive));
00786 if (drive == NULL)
00787 goto error;
00788 memset (drive, 0x00, sizeof (HalDrive));
00789
00790 drive->hal_ctx = hal_ctx;
00791
00792 drive->udi = strdup (udi);
00793 if (drive->udi == NULL)
00794 goto error;
00795
00796 properties = hal_device_get_all_properties (hal_ctx, udi);
00797 if (properties == NULL)
00798 goto error;
00799
00800
00801 for (hal_psi_init (&it, properties); hal_psi_has_more (&it); hal_psi_next (&it)) {
00802 int type;
00803 char *key;
00804
00805 type = hal_psi_get_type (&it);
00806 key = hal_psi_get_key (&it);
00807
00808 HAL_PROP_EXTRACT_BEGIN;
00809
00810 HAL_PROP_EXTRACT_INT ("block.minor", drive->device_minor);
00811 HAL_PROP_EXTRACT_INT ("block.major", drive->device_major);
00812 HAL_PROP_EXTRACT_STRING ("block.device", drive->device_file);
00813 HAL_PROP_EXTRACT_STRING ("storage.bus", bus_textual);
00814 HAL_PROP_EXTRACT_STRING ("storage.vendor", drive->vendor);
00815 HAL_PROP_EXTRACT_STRING ("storage.model", drive->model);
00816 HAL_PROP_EXTRACT_STRING ("storage.drive_type", drive->type_textual);
00817
00818
00819 HAL_PROP_EXTRACT_STRING ("storage.icon.drive", drive->dedicated_icon_drive);
00820 HAL_PROP_EXTRACT_STRING ("storage.icon.volume", drive->dedicated_icon_volume);
00821
00822 HAL_PROP_EXTRACT_BOOL ("storage.hotpluggable", drive->is_hotpluggable);
00823 HAL_PROP_EXTRACT_BOOL ("storage.removable", drive->is_removable);
00824 HAL_PROP_EXTRACT_BOOL ("storage.requires_eject", drive->requires_eject);
00825
00826 HAL_PROP_EXTRACT_STRING ("storage.physical_device", drive->physical_device);
00827 HAL_PROP_EXTRACT_STRING ("storage.firmware_version", drive->firmware_version);
00828 HAL_PROP_EXTRACT_STRING ("storage.serial", drive->serial);
00829
00830 HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.cdr", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_CDR);
00831 HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.cdrw", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_CDRW);
00832 HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvd", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDROM);
00833 HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdplusr", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDPLUSR);
00834 HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdplusrw", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDPLUSRW);
00835 HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdr", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDR);
00836 HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdrw", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDRW);
00837 HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdram", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDRAM);
00838
00839 HAL_PROP_EXTRACT_BOOL ("storage.policy.should_mount", drive->should_mount);
00840 HAL_PROP_EXTRACT_STRING ("storage.policy.desired_mount_point", drive->desired_mount_point);
00841 HAL_PROP_EXTRACT_STRING ("storage.policy.mount_filesystem", drive->mount_filesystem);
00842
00843 HAL_PROP_EXTRACT_BOOL ("storage.no_partitions_hint", drive->no_partitions_hint);
00844
00845 HAL_PROP_EXTRACT_END;
00846 }
00847
00848 if (drive->type_textual != NULL) {
00849 if (strcmp (drive->type_textual, "cdrom") == 0) {
00850 drive->cdrom_caps |= HAL_DRIVE_CDROM_CAPS_CDROM;
00851 drive->type = HAL_DRIVE_TYPE_CDROM;
00852 } else if (strcmp (drive->type_textual, "floppy") == 0) {
00853 drive->type = HAL_DRIVE_TYPE_FLOPPY;
00854 } else if (strcmp (drive->type_textual, "disk") == 0) {
00855 if (drive->is_removable)
00856 drive->type = HAL_DRIVE_TYPE_REMOVABLE_DISK;
00857 else
00858 drive->type = HAL_DRIVE_TYPE_DISK;
00859 } else if (strcmp (drive->type_textual, "tape") == 0) {
00860 drive->type = HAL_DRIVE_TYPE_TAPE;
00861 } else if (strcmp (drive->type_textual, "compact_flash") == 0) {
00862 drive->type = HAL_DRIVE_TYPE_COMPACT_FLASH;
00863 } else if (strcmp (drive->type_textual, "memory_stick") == 0) {
00864 drive->type = HAL_DRIVE_TYPE_MEMORY_STICK;
00865 } else if (strcmp (drive->type_textual, "smart_media") == 0) {
00866 drive->type = HAL_DRIVE_TYPE_SMART_MEDIA;
00867 } else if (strcmp (drive->type_textual, "sd_mmc") == 0) {
00868 drive->type = HAL_DRIVE_TYPE_SD_MMC;
00869
00870
00871
00872
00873
00874
00875 } else {
00876 drive->type = HAL_DRIVE_TYPE_DISK;
00877 }
00878
00879 }
00880
00881
00882 if (drive->physical_device != NULL) {
00883 char *category;
00884
00885 category = hal_device_get_property_string (hal_ctx, drive->physical_device, "info.category");
00886 if (category != NULL) {
00887 if (strcmp (category, "portable_audio_player") == 0) {
00888 drive->type = HAL_DRIVE_TYPE_PORTABLE_AUDIO_PLAYER;
00889 } else if (strcmp (category, "camera") == 0) {
00890 drive->type = HAL_DRIVE_TYPE_CAMERA;
00891 }
00892
00893 hal_free_string (category);
00894 }
00895 }
00896
00897 if (bus_textual != NULL) {
00898 if (strcmp (bus_textual, "usb") == 0) {
00899 drive->bus = HAL_DRIVE_BUS_USB;
00900 } else if (strcmp (bus_textual, "ieee1394") == 0) {
00901 drive->bus = HAL_DRIVE_BUS_IEEE1394;
00902 } else if (strcmp (bus_textual, "ide") == 0) {
00903 drive->bus = HAL_DRIVE_BUS_IDE;
00904 } else if (strcmp (bus_textual, "scsi") == 0) {
00905 drive->bus = HAL_DRIVE_BUS_SCSI;
00906 }
00907 }
00908
00909 hal_free_string (bus_textual);
00910 hal_free_property_set (properties);
00911
00912 return drive;
00913
00914 error:
00915 hal_free_string (bus_textual);
00916 hal_free_property_set (properties);
00917 hal_drive_free (drive);
00918 return NULL;
00919 }
00920
00921 const char *
00922 hal_volume_get_storage_device_udi (HalVolume *volume)
00923 {
00924 return volume->storage_device;
00925 }
00926
00927 const char *hal_drive_get_physical_device_udi (HalDrive *drive)
00928 {
00929 return drive->physical_device;
00930 }
00931
00932 dbus_bool_t
00933 hal_drive_requires_eject (HalDrive *drive)
00934 {
00935 return drive->requires_eject;
00936 }
00937
00946 HalVolume *
00947 hal_volume_from_udi (LibHalContext *hal_ctx, const char *udi)
00948 {
00949 char *disc_type_textual;
00950 HalVolume *vol;
00951 LibHalPropertySet *properties;
00952 LibHalPropertySetIterator it;
00953
00954 vol = NULL;
00955 properties = NULL;
00956 disc_type_textual = NULL;
00957
00958 if (!hal_device_query_capability (hal_ctx, udi, "volume"))
00959 goto error;
00960
00961 vol = malloc (sizeof (HalVolume));
00962 if (vol == NULL)
00963 goto error;
00964 memset (vol, 0x00, sizeof (HalVolume));
00965
00966 vol->udi = strdup (udi);
00967
00968 properties = hal_device_get_all_properties (hal_ctx, udi);
00969 if (properties == NULL)
00970 goto error;
00971
00972
00973 for (hal_psi_init (&it, properties); hal_psi_has_more (&it); hal_psi_next (&it)) {
00974 int type;
00975 char *key;
00976
00977 type = hal_psi_get_type (&it);
00978 key = hal_psi_get_key (&it);
00979
00980 HAL_PROP_EXTRACT_BEGIN;
00981
00982 HAL_PROP_EXTRACT_INT ("volume.partition.msdos_part_table_type", vol->msdos_part_table_type);
00983
00984 HAL_PROP_EXTRACT_INT ("block.minor", vol->device_minor);
00985 HAL_PROP_EXTRACT_INT ("block.major", vol->device_major);
00986 HAL_PROP_EXTRACT_STRING ("block.device", vol->device_file);
00987
00988 HAL_PROP_EXTRACT_STRING ("block.storage_device", vol->storage_device);
00989
00990 HAL_PROP_EXTRACT_INT ("volume.block_size", vol->block_size);
00991 HAL_PROP_EXTRACT_INT ("volume.num_blocks", vol->num_blocks);
00992 HAL_PROP_EXTRACT_STRING ("volume.label", vol->volume_label);
00993 HAL_PROP_EXTRACT_STRING ("volume.mount_point", vol->mount_point);
00994 HAL_PROP_EXTRACT_STRING ("volume.fstype", vol->fstype);
00995 HAL_PROP_EXTRACT_BOOL ("volume.is_mounted", vol->is_mounted);
00996
00997 HAL_PROP_EXTRACT_BOOL ("volume.is_disc", vol->is_disc);
00998 HAL_PROP_EXTRACT_STRING ("volume.disc.type", disc_type_textual);
00999 HAL_PROP_EXTRACT_BOOL ("volume.disc.has_audio", vol->disc_has_audio);
01000 HAL_PROP_EXTRACT_BOOL ("volume.disc.has_data", vol->disc_has_data);
01001 HAL_PROP_EXTRACT_BOOL ("volume.disc.is_appendable", vol->disc_is_appendable);
01002 HAL_PROP_EXTRACT_BOOL ("volume.disc.is_blank", vol->disc_is_blank);
01003 HAL_PROP_EXTRACT_BOOL ("volume.disc.is_rewritable", vol->disc_is_rewritable);
01004
01005 HAL_PROP_EXTRACT_BOOL ("volume.policy.should_mount", vol->should_mount);
01006 HAL_PROP_EXTRACT_STRING ("volume.policy.desired_mount_point", vol->desired_mount_point);
01007 HAL_PROP_EXTRACT_STRING ("volume.policy.mount_filesystem", vol->mount_filesystem);
01008
01009 HAL_PROP_EXTRACT_END;
01010 }
01011
01012 if (disc_type_textual != NULL) {
01013 if (strcmp (disc_type_textual, "cd_rom") == 0) {
01014 vol->disc_type = HAL_VOLUME_DISC_TYPE_CDROM;
01015 } else if (strcmp (disc_type_textual, "cd_r") == 0) {
01016 vol->disc_type = HAL_VOLUME_DISC_TYPE_CDR;
01017 } else if (strcmp (disc_type_textual, "cd_rw") == 0) {
01018 vol->disc_type = HAL_VOLUME_DISC_TYPE_CDRW;
01019 } else if (strcmp (disc_type_textual, "dvd_rom") == 0) {
01020 vol->disc_type = HAL_VOLUME_DISC_TYPE_DVDROM;
01021 } else if (strcmp (disc_type_textual, "dvd_ram") == 0) {
01022 vol->disc_type = HAL_VOLUME_DISC_TYPE_DVDRAM;
01023 } else if (strcmp (disc_type_textual, "dvd_r") == 0) {
01024 vol->disc_type = HAL_VOLUME_DISC_TYPE_DVDR;
01025 } else if (strcmp (disc_type_textual, "dvd_rw") == 0) {
01026 vol->disc_type = HAL_VOLUME_DISC_TYPE_DVDRW;
01027 } else if (strcmp (disc_type_textual, "dvd_plusr") == 0) {
01028 vol->disc_type = HAL_VOLUME_DISC_TYPE_DVDPLUSR;
01029 } else if (strcmp (disc_type_textual, "dvd_plusrw") == 0) {
01030 vol->disc_type = HAL_VOLUME_DISC_TYPE_DVDPLUSRW;
01031 }
01032 }
01033
01034 hal_free_string (disc_type_textual);
01035 hal_free_property_set (properties);
01036 return vol;
01037 error:
01038 hal_free_string (disc_type_textual);
01039 hal_free_property_set (properties);
01040 hal_volume_free (vol);
01041 return NULL;
01042 }
01043
01044
01053 int
01054 hal_volume_get_msdos_part_table_type (HalVolume *volume)
01055 {
01056 return volume->msdos_part_table_type;
01057 }
01058
01059
01060
01068 HalDrive *
01069 hal_drive_from_device_file (LibHalContext *hal_ctx, const char *device_file)
01070 {
01071 int i;
01072 char **hal_udis;
01073 int num_hal_udis;
01074 HalDrive *result;
01075 char *found_udi;
01076
01077 result = NULL;
01078 found_udi = NULL;
01079
01080 if ((hal_udis = hal_manager_find_device_string_match (hal_ctx, "block.device",
01081 device_file, &num_hal_udis)) == NULL)
01082 goto out;
01083
01084 for (i = 0; i < num_hal_udis; i++) {
01085 char *udi;
01086 char *storage_udi;
01087 udi = hal_udis[i];
01088 if (hal_device_query_capability (hal_ctx, udi, "volume")) {
01089
01090 storage_udi = hal_device_get_property_string (hal_ctx, udi, "block.storage_device");
01091 if (storage_udi == NULL)
01092 continue;
01093 found_udi = strdup (storage_udi);
01094 hal_free_string (storage_udi);
01095 break;
01096 } else if (hal_device_query_capability (hal_ctx, udi, "storage")) {
01097 found_udi = strdup (udi);
01098 }
01099 }
01100
01101 hal_free_string_array (hal_udis);
01102
01103 if (found_udi != NULL)
01104 result = hal_drive_from_udi (hal_ctx, found_udi);
01105
01106 free (found_udi);
01107 out:
01108 return result;
01109 }
01110
01111
01118 HalVolume *
01119 hal_volume_from_device_file (LibHalContext *hal_ctx, const char *device_file)
01120 {
01121 int i;
01122 char **hal_udis;
01123 int num_hal_udis;
01124 HalVolume *result;
01125 char *found_udi;
01126
01127 result = NULL;
01128 found_udi = NULL;
01129
01130 if ((hal_udis = hal_manager_find_device_string_match (hal_ctx, "block.device",
01131 device_file, &num_hal_udis)) == NULL)
01132 goto out;
01133
01134 for (i = 0; i < num_hal_udis; i++) {
01135 char *udi;
01136 udi = hal_udis[i];
01137 if (hal_device_query_capability (hal_ctx, udi, "volume")) {
01138 found_udi = strdup (udi);
01139 break;
01140 }
01141 }
01142
01143 hal_free_string_array (hal_udis);
01144
01145 if (found_udi != NULL)
01146 result = hal_volume_from_udi (hal_ctx, found_udi);
01147
01148 free (found_udi);
01149 out:
01150 return result;
01151 }
01152
01153 dbus_uint64_t
01154 hal_volume_get_size (HalVolume *volume)
01155 {
01156 return ((dbus_uint64_t)volume->block_size) * ((dbus_uint64_t)volume->num_blocks);
01157 }
01158
01159
01160 dbus_bool_t
01161 hal_drive_is_hotpluggable (HalDrive *drive)
01162 {
01163 return drive->is_hotpluggable;
01164 }
01165
01166 dbus_bool_t
01167 hal_drive_uses_removable_media (HalDrive *drive)
01168 {
01169 return drive->is_removable;
01170 }
01171
01172 HalDriveType
01173 hal_drive_get_type (HalDrive *drive)
01174 {
01175 return drive->type;
01176 }
01177
01178 HalDriveBus
01179 hal_drive_get_bus (HalDrive *drive)
01180 {
01181 return drive->bus;
01182 }
01183
01184 HalDriveCdromCaps
01185 hal_drive_get_cdrom_caps (HalDrive *drive)
01186 {
01187 return drive->cdrom_caps;
01188 }
01189
01190 unsigned int
01191 hal_drive_get_device_major (HalDrive *drive)
01192 {
01193 return drive->device_major;
01194 }
01195
01196 unsigned int
01197 hal_drive_get_device_minor (HalDrive *drive)
01198 {
01199 return drive->device_minor;
01200 }
01201
01202 const char *
01203 hal_drive_get_type_textual (HalDrive *drive)
01204 {
01205 return drive->type_textual;
01206 }
01207
01208 const char *
01209 hal_drive_get_device_file (HalDrive *drive)
01210 {
01211 return drive->device_file;
01212 }
01213
01214 const char *
01215 hal_drive_get_udi (HalDrive *drive)
01216 {
01217 return drive->udi;
01218 }
01219
01220 const char *
01221 hal_drive_get_serial (HalDrive *drive)
01222 {
01223 return drive->serial;
01224 }
01225
01226 const char *
01227 hal_drive_get_firmware_version (HalDrive *drive)
01228 {
01229 return drive->firmware_version;
01230 }
01231
01232 const char *
01233 hal_drive_get_model (HalDrive *drive)
01234 {
01235 return drive->model;
01236 }
01237
01238 const char *
01239 hal_drive_get_vendor (HalDrive *drive)
01240 {
01241 return drive->vendor;
01242 }
01243
01244
01245
01246 const char *
01247 hal_volume_get_udi (HalVolume *volume)
01248 {
01249 return volume->udi;
01250 }
01251
01252 const char *
01253 hal_volume_get_device_file (HalVolume *volume)
01254 {
01255 return volume->device_file;
01256 }
01257
01258 unsigned int hal_volume_get_device_major (HalVolume *volume)
01259 {
01260 return volume->device_major;
01261 }
01262
01263 unsigned int hal_volume_get_device_minor (HalVolume *volume)
01264 {
01265 return volume->device_minor;
01266 }
01267
01268 const char *
01269 hal_volume_get_fstype (HalVolume *volume)
01270 {
01271 return volume->fstype;
01272 }
01273
01274 const char *
01275 hal_volume_get_fsversion (HalVolume *volume)
01276 {
01277 return volume->fsversion;
01278 }
01279
01280 HalVolumeUsage
01281 hal_volume_get_fsusage (HalVolume *volume)
01282 {
01283 return volume->fsusage;
01284 }
01285
01286 dbus_bool_t
01287 hal_volume_is_mounted (HalVolume *volume)
01288 {
01289 return volume->is_mounted;
01290 }
01291
01292 dbus_bool_t
01293 hal_volume_is_partition (HalVolume *volume)
01294 {
01295 return volume->is_partition;
01296 }
01297
01298 dbus_bool_t
01299 hal_volume_is_disc (HalVolume *volume)
01300 {
01301 return volume->is_disc;
01302 }
01303
01304 unsigned int
01305 hal_volume_get_partition_number (HalVolume *volume)
01306 {
01307 return volume->partition_number;
01308 }
01309
01310 const char *
01311 hal_volume_get_label (HalVolume *volume)
01312 {
01313 return volume->volume_label;
01314 }
01315
01316 const char *
01317 hal_volume_get_mount_point (HalVolume *volume)
01318 {
01319 return volume->mount_point;
01320 }
01321
01322 const char *
01323 hal_volume_get_uuid (HalVolume *volume)
01324 {
01325 return volume->uuid;
01326 }
01327
01328 dbus_bool_t
01329 hal_volume_disc_has_audio (HalVolume *volume)
01330 {
01331 return volume->disc_has_audio;
01332 }
01333
01334 dbus_bool_t
01335 hal_volume_disc_has_data (HalVolume *volume)
01336 {
01337 return volume->disc_has_data;
01338 }
01339
01340 dbus_bool_t
01341 hal_volume_disc_is_blank (HalVolume *volume)
01342 {
01343 return volume->disc_is_blank;
01344 }
01345
01346 dbus_bool_t
01347 hal_volume_disc_is_rewritable (HalVolume *volume)
01348 {
01349 return volume->disc_is_rewritable;
01350 }
01351
01352 dbus_bool_t
01353 hal_volume_disc_is_appendable (HalVolume *volume)
01354 {
01355 return volume->disc_is_appendable;
01356 }
01357
01358 HalVolumeDiscType
01359 hal_volume_get_disc_type (HalVolume *volume)
01360 {
01361 return volume->disc_type;
01362 }
01363
01364 char **
01365 hal_drive_find_all_volumes (LibHalContext *hal_ctx, HalDrive *drive, int *num_volumes)
01366 {
01367 int i;
01368 char **udis;
01369 int num_udis;
01370 const char *drive_udi;
01371 char **result;
01372
01373 udis = NULL;
01374 result = NULL;
01375 *num_volumes = 0;
01376
01377 drive_udi = hal_drive_get_udi (drive);
01378 if (drive_udi == NULL)
01379 goto out;
01380
01381
01382 if ((udis = hal_manager_find_device_string_match (hal_ctx, "block.storage_device",
01383 drive_udi, &num_udis)) == NULL)
01384 goto out;
01385
01386 result = malloc (sizeof (char *) * num_udis);
01387 if (result == NULL)
01388 goto out;
01389
01390
01391 for (i = 0; i < num_udis; i++) {
01392 if (strcmp (udis[i], drive_udi) == 0)
01393 continue;
01394 result[*num_volumes] = strdup (udis[i]);
01395 *num_volumes = (*num_volumes) + 1;
01396 }
01397
01398 out:
01399 hal_free_string_array (udis);
01400 return result;
01401 }
01402
01403
01404
01405 char *
01406 hal_drive_policy_default_get_mount_root (LibHalContext *hal_ctx)
01407 {
01408 return hal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer",
01409 "storage.policy.default.mount_root");
01410 }
01411
01412 dbus_bool_t
01413 hal_drive_policy_default_use_managed_keyword (LibHalContext *hal_ctx)
01414 {
01415 return hal_device_get_property_bool (hal_ctx, "/org/freedesktop/Hal/devices/computer",
01416 "storage.policy.default.use_managed_keyword");
01417 }
01418
01419 char *
01420 hal_drive_policy_default_get_managed_keyword_primary (LibHalContext *hal_ctx)
01421 {
01422 return hal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer",
01423 "storage.policy.default.managed_keyword.primary");
01424 }
01425
01426 char *
01427 hal_drive_policy_default_get_managed_keyword_secondary (LibHalContext *hal_ctx)
01428 {
01429 return hal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer",
01430 "storage.policy.default.managed_keyword.secondary");
01431 }
01432
01433
01434
01435 dbus_bool_t
01436 hal_drive_policy_is_mountable (HalDrive *drive, HalStoragePolicy *policy)
01437 {
01438 return drive->should_mount && drive->no_partitions_hint;
01439 }
01440
01441 const char *
01442 hal_drive_policy_get_desired_mount_point (HalDrive *drive, HalStoragePolicy *policy)
01443 {
01444 return drive->desired_mount_point;
01445 }
01446
01447
01448 #define strcat_len(dst, src, dstmaxlen) do { \
01449 dst[dstmaxlen - 1] = '\0'; \
01450 strncat (dst, src, dstmaxlen - strlen (dst) - 1); \
01451 } while(0)
01452
01453
01454 static void
01455 mopts_collect (LibHalContext *hal_ctx, const char *namespace, int namespace_len,
01456 const char *udi, char *options_string, size_t options_max_len, dbus_bool_t only_collect_imply_opts)
01457 {
01458 LibHalPropertySet *properties;
01459 LibHalPropertySetIterator it;
01460
01461
01462 properties = hal_device_get_all_properties (hal_ctx, udi);
01463 if (properties == NULL)
01464 goto error;
01465 for (hal_psi_init (&it, properties); hal_psi_has_more (&it); hal_psi_next (&it)) {
01466 int type;
01467 char *key;
01468
01469 type = hal_psi_get_type (&it);
01470 key = hal_psi_get_key (&it);
01471 if (hal_psi_get_type (&it) == DBUS_TYPE_BOOLEAN &&
01472 strncmp (key, namespace, namespace_len - 1) == 0) {
01473 const char *option = key + namespace_len - 1;
01474 char *location;
01475 dbus_bool_t is_imply_opt;
01476
01477 is_imply_opt = FALSE;
01478 if (strcmp (option, "user") == 0 ||
01479 strcmp (option, "users") == 0 ||
01480 strcmp (option, "defaults") == 0 ||
01481 strcmp (option, "pamconsole") == 0)
01482 is_imply_opt = TRUE;
01483
01484
01485 if (only_collect_imply_opts) {
01486 if (!is_imply_opt)
01487 continue;
01488 } else {
01489 if (is_imply_opt)
01490 continue;
01491 }
01492
01493 if (hal_psi_get_bool (&it)) {
01494
01495 location = strstr (options_string, option);
01496 if (location == NULL) {
01497 if (strlen (options_string) > 0)
01498 strcat_len (options_string, ",", options_max_len);
01499 strcat_len (options_string, option, options_max_len);
01500 }
01501 } else {
01502
01503 location = strstr (options_string, option);
01504 if (location != NULL) {
01505 char *end;
01506
01507 end = strchr (location, ',');
01508 if (end == NULL) {
01509 location[0] = '\0';
01510 } else {
01511 strcpy (location, end + 1);
01512 }
01513 }
01514
01515 }
01516 }
01517 }
01518 error:
01519 hal_free_property_set (properties);
01520 }
01521
01522
01523 const char *
01524 hal_drive_policy_get_mount_options (HalDrive *drive, HalStoragePolicy *policy)
01525 {
01526 const char *result;
01527 char stor_mount_option_default_begin[] = "storage.policy.default.mount_option.";
01528 char stor_mount_option_begin[] = "storage.policy.mount_option.";
01529
01530 result = NULL;
01531 drive->mount_options[0] = '\0';
01532
01533
01534 mopts_collect (drive->hal_ctx, stor_mount_option_default_begin, sizeof (stor_mount_option_default_begin),
01535 "/org/freedesktop/Hal/devices/computer", drive->mount_options, MOUNT_OPTIONS_SIZE, TRUE);
01536 mopts_collect (drive->hal_ctx, stor_mount_option_begin, sizeof (stor_mount_option_begin),
01537 drive->udi, drive->mount_options, MOUNT_OPTIONS_SIZE, TRUE);
01538
01539 mopts_collect (drive->hal_ctx, stor_mount_option_default_begin, sizeof (stor_mount_option_default_begin),
01540 "/org/freedesktop/Hal/devices/computer", drive->mount_options, MOUNT_OPTIONS_SIZE, FALSE);
01541 mopts_collect (drive->hal_ctx, stor_mount_option_begin, sizeof (stor_mount_option_begin),
01542 drive->udi, drive->mount_options, MOUNT_OPTIONS_SIZE, FALSE);
01543
01544 result = drive->mount_options;
01545
01546 return result;
01547 }
01548
01549 const char *
01550 hal_drive_policy_get_mount_fs (HalDrive *drive, HalStoragePolicy *policy)
01551 {
01552 return drive->mount_filesystem;
01553 }
01554
01555
01556 dbus_bool_t
01557 hal_volume_policy_is_mountable (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy)
01558 {
01559 return drive->should_mount && volume->should_mount;
01560 }
01561
01562 const char *hal_volume_policy_get_desired_mount_point (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy)
01563 {
01564 return volume->desired_mount_point;
01565 }
01566
01567 const char *hal_volume_policy_get_mount_options (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy)
01568 {
01569 const char *result;
01570 char stor_mount_option_default_begin[] = "storage.policy.default.mount_option.";
01571 char vol_mount_option_begin[] = "volume.policy.mount_option.";
01572
01573 result = NULL;
01574 volume->mount_options[0] = '\0';
01575
01576
01577 mopts_collect (drive->hal_ctx, stor_mount_option_default_begin, sizeof (stor_mount_option_default_begin),
01578 "/org/freedesktop/Hal/devices/computer", volume->mount_options, MOUNT_OPTIONS_SIZE, TRUE);
01579 mopts_collect (drive->hal_ctx, vol_mount_option_begin, sizeof (vol_mount_option_begin),
01580 volume->udi, volume->mount_options, MOUNT_OPTIONS_SIZE, TRUE);
01581
01582 mopts_collect (drive->hal_ctx, stor_mount_option_default_begin, sizeof (stor_mount_option_default_begin),
01583 "/org/freedesktop/Hal/devices/computer", volume->mount_options, MOUNT_OPTIONS_SIZE, FALSE);
01584 mopts_collect (drive->hal_ctx, vol_mount_option_begin, sizeof (vol_mount_option_begin),
01585 volume->udi, volume->mount_options, MOUNT_OPTIONS_SIZE, FALSE);
01586
01587 result = volume->mount_options;
01588
01589 return result;
01590 }
01591
01592 const char *hal_volume_policy_get_mount_fs (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy)
01593 {
01594 return volume->mount_filesystem;
01595 }
01596
01597 dbus_bool_t
01598 hal_drive_no_partitions_hint (HalDrive *drive)
01599 {
01600 return drive->no_partitions_hint;
01601 }
01602