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_CDROM)
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 (fstype == NULL)
00597 goto out;
00598
00599
00600 if (mount_point != NULL) {
00601 for (i = 0; fhs23_toplevel_mount_points[i] != NULL; i++) {
00602 if (strcmp (mount_point, fhs23_toplevel_mount_points[i]) == 0)
00603 goto out;
00604 }
00605 }
00606
00607
00608 if (label != NULL && strcmp (label, "bootstrap") == 0 && strcmp (fstype, "hfs") == 0)
00609 goto out;
00610
00611
00612 is_visible = TRUE;
00613
00614 out:
00615 return is_visible;
00616 }
00617
00618
00619
00620 #define MOUNT_OPTIONS_SIZE 256
00621
00622 struct HalDrive_s {
00623 char *udi;
00624
00625 int device_major;
00626 int device_minor;
00627 char *device_file;
00628
00629 HalDriveBus bus;
00630 char *vendor;
00631 char *model;
00632 dbus_bool_t is_hotpluggable;
00633 dbus_bool_t is_removable;
00634 dbus_bool_t requires_eject;
00635
00636 HalDriveType type;
00637 char *type_textual;
00638
00639 char *physical_device;
00640
00641
00642 char *dedicated_icon_drive;
00643 char *dedicated_icon_volume;
00644
00645 char *serial;
00646 char *firmware_version;
00647 HalDriveCdromCaps cdrom_caps;
00648
00649 char *desired_mount_point;
00650 char *mount_filesystem;
00651 dbus_bool_t should_mount;
00652
00653 dbus_bool_t no_partitions_hint;
00654
00655 LibHalContext *hal_ctx;
00656
00657 char mount_options[MOUNT_OPTIONS_SIZE];
00658 };
00659
00660 struct HalVolume_s {
00661 char *udi;
00662
00663 int device_major;
00664 int device_minor;
00665 char *device_file;
00666 char *volume_label;
00667 dbus_bool_t is_mounted;
00668 char *mount_point;
00669 char *fstype;
00670 char *fsversion;
00671 char *uuid;
00672 char *storage_device;
00673
00674 HalVolumeUsage fsusage;
00675
00676 dbus_bool_t is_partition;
00677 unsigned int partition_number;
00678
00679 int msdos_part_table_type;
00680
00681
00682 dbus_bool_t is_disc;
00683 HalVolumeDiscType disc_type;
00684 dbus_bool_t disc_has_audio;
00685 dbus_bool_t disc_has_data;
00686 dbus_bool_t disc_is_appendable;
00687 dbus_bool_t disc_is_blank;
00688 dbus_bool_t disc_is_rewritable;
00689
00690 unsigned int block_size;
00691 unsigned int num_blocks;
00692
00693 char *desired_mount_point;
00694 char *mount_filesystem;
00695 dbus_bool_t should_mount;
00696
00697 char mount_options[MOUNT_OPTIONS_SIZE];
00698 };
00699
00700 const char *
00701 hal_drive_get_dedicated_icon_drive (HalDrive *drive)
00702 {
00703 return drive->dedicated_icon_drive;
00704 }
00705
00706 const char *
00707 hal_drive_get_dedicated_icon_volume (HalDrive *drive)
00708 {
00709 return drive->dedicated_icon_volume;
00710 }
00711
00716 void
00717 hal_drive_free (HalDrive *drive)
00718 {
00719 if (drive == NULL )
00720 return;
00721
00722 free (drive->udi);
00723 hal_free_string (drive->device_file);
00724 hal_free_string (drive->vendor);
00725 hal_free_string (drive->model);
00726 hal_free_string (drive->type_textual);
00727 hal_free_string (drive->physical_device);
00728 hal_free_string (drive->serial);
00729 hal_free_string (drive->firmware_version);
00730 hal_free_string (drive->desired_mount_point);
00731 hal_free_string (drive->mount_filesystem);
00732 }
00733
00734
00739 void
00740 hal_volume_free (HalVolume *vol)
00741 {
00742 if (vol == NULL )
00743 return;
00744
00745 free (vol->udi);
00746 hal_free_string (vol->device_file);
00747 hal_free_string (vol->volume_label);
00748 hal_free_string (vol->fstype);
00749 hal_free_string (vol->mount_point);
00750 hal_free_string (vol->fsversion);
00751 hal_free_string (vol->uuid);
00752 hal_free_string (vol->desired_mount_point);
00753 hal_free_string (vol->mount_filesystem);
00754 }
00755
00756
00757
00758
00759 #define HAL_PROP_EXTRACT_BEGIN if (FALSE)
00760 #define HAL_PROP_EXTRACT_END ;
00761 #define HAL_PROP_EXTRACT_INT(_property_, _where_) else if (strcmp (key, _property_) == 0 && type == DBUS_TYPE_INT32) _where_ = hal_psi_get_int (&it)
00762 #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
00763 #define HAL_PROP_EXTRACT_BOOL(_property_, _where_) else if (strcmp (key, _property_) == 0 && type == DBUS_TYPE_BOOLEAN) _where_ = hal_psi_get_bool (&it)
00764 #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
00765
00774 HalDrive *
00775 hal_drive_from_udi (LibHalContext *hal_ctx, const char *udi)
00776 {
00777 char *bus_textual;
00778 HalDrive *drive;
00779 LibHalPropertySet *properties;
00780 LibHalPropertySetIterator it;
00781
00782 drive = NULL;
00783 properties = NULL;
00784 bus_textual = NULL;
00785
00786 if (!hal_device_query_capability (hal_ctx, udi, "storage"))
00787 goto error;
00788
00789 drive = malloc (sizeof (HalDrive));
00790 if (drive == NULL)
00791 goto error;
00792 memset (drive, 0x00, sizeof (HalDrive));
00793
00794 drive->hal_ctx = hal_ctx;
00795
00796 drive->udi = strdup (udi);
00797 if (drive->udi == NULL)
00798 goto error;
00799
00800 properties = hal_device_get_all_properties (hal_ctx, udi);
00801 if (properties == NULL)
00802 goto error;
00803
00804
00805 for (hal_psi_init (&it, properties); hal_psi_has_more (&it); hal_psi_next (&it)) {
00806 int type;
00807 char *key;
00808
00809 type = hal_psi_get_type (&it);
00810 key = hal_psi_get_key (&it);
00811
00812 HAL_PROP_EXTRACT_BEGIN;
00813
00814 HAL_PROP_EXTRACT_INT ("block.minor", drive->device_minor);
00815 HAL_PROP_EXTRACT_INT ("block.major", drive->device_major);
00816 HAL_PROP_EXTRACT_STRING ("block.device", drive->device_file);
00817 HAL_PROP_EXTRACT_STRING ("storage.bus", bus_textual);
00818 HAL_PROP_EXTRACT_STRING ("storage.vendor", drive->vendor);
00819 HAL_PROP_EXTRACT_STRING ("storage.model", drive->model);
00820 HAL_PROP_EXTRACT_STRING ("storage.drive_type", drive->type_textual);
00821
00822
00823 HAL_PROP_EXTRACT_STRING ("storage.icon.drive", drive->dedicated_icon_drive);
00824 HAL_PROP_EXTRACT_STRING ("storage.icon.volume", drive->dedicated_icon_volume);
00825
00826 HAL_PROP_EXTRACT_BOOL ("storage.hotpluggable", drive->is_hotpluggable);
00827 HAL_PROP_EXTRACT_BOOL ("storage.removable", drive->is_removable);
00828 HAL_PROP_EXTRACT_BOOL ("storage.requires_eject", drive->requires_eject);
00829
00830 HAL_PROP_EXTRACT_STRING ("storage.physical_device", drive->physical_device);
00831 HAL_PROP_EXTRACT_STRING ("storage.firmware_version", drive->firmware_version);
00832 HAL_PROP_EXTRACT_STRING ("storage.serial", drive->serial);
00833
00834 HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.cdr", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_CDR);
00835 HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.cdrw", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_CDRW);
00836 HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvd", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDROM);
00837 HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdplusr", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDPLUSR);
00838 HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdplusrw", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDPLUSRW);
00839 HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdr", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDR);
00840 HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdrw", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDRW);
00841 HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdram", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDRAM);
00842
00843 HAL_PROP_EXTRACT_BOOL ("storage.policy.should_mount", drive->should_mount);
00844 HAL_PROP_EXTRACT_STRING ("storage.policy.desired_mount_point", drive->desired_mount_point);
00845 HAL_PROP_EXTRACT_STRING ("storage.policy.mount_filesystem", drive->mount_filesystem);
00846
00847 HAL_PROP_EXTRACT_BOOL ("storage.no_partitions_hint", drive->no_partitions_hint);
00848
00849 HAL_PROP_EXTRACT_END;
00850 }
00851
00852 if (drive->type_textual != NULL) {
00853 if (strcmp (drive->type_textual, "cdrom") == 0) {
00854 drive->cdrom_caps |= HAL_DRIVE_CDROM_CAPS_CDROM;
00855 drive->type = HAL_DRIVE_TYPE_CDROM;
00856 } else if (strcmp (drive->type_textual, "floppy") == 0) {
00857 drive->type = HAL_DRIVE_TYPE_FLOPPY;
00858 } else if (strcmp (drive->type_textual, "disk") == 0) {
00859 if (drive->is_removable)
00860 drive->type = HAL_DRIVE_TYPE_REMOVABLE_DISK;
00861 else
00862 drive->type = HAL_DRIVE_TYPE_DISK;
00863 } else if (strcmp (drive->type_textual, "tape") == 0) {
00864 drive->type = HAL_DRIVE_TYPE_TAPE;
00865 } else if (strcmp (drive->type_textual, "compact_flash") == 0) {
00866 drive->type = HAL_DRIVE_TYPE_COMPACT_FLASH;
00867 } else if (strcmp (drive->type_textual, "memory_stick") == 0) {
00868 drive->type = HAL_DRIVE_TYPE_MEMORY_STICK;
00869 } else if (strcmp (drive->type_textual, "smart_media") == 0) {
00870 drive->type = HAL_DRIVE_TYPE_SMART_MEDIA;
00871 } else if (strcmp (drive->type_textual, "sd_mmc") == 0) {
00872 drive->type = HAL_DRIVE_TYPE_SD_MMC;
00873 }
00874 }
00875
00876
00877 if (drive->physical_device != NULL) {
00878 char *category;
00879
00880 category = hal_device_get_property_string (hal_ctx, drive->physical_device, "info.category");
00881 if (category != NULL) {
00882 if (strcmp (category, "portable_audio_player") == 0) {
00883 drive->type = HAL_DRIVE_TYPE_PORTABLE_AUDIO_PLAYER;
00884 } else if (strcmp (category, "camera") == 0) {
00885 drive->type = HAL_DRIVE_TYPE_CAMERA;
00886 }
00887
00888 hal_free_string (category);
00889 }
00890 }
00891
00892 if (bus_textual != NULL) {
00893 if (strcmp (bus_textual, "usb") == 0) {
00894 drive->bus = HAL_DRIVE_BUS_USB;
00895 } else if (strcmp (bus_textual, "ieee1394") == 0) {
00896 drive->bus = HAL_DRIVE_BUS_IEEE1394;
00897 } else if (strcmp (bus_textual, "ide") == 0) {
00898 drive->bus = HAL_DRIVE_BUS_IDE;
00899 } else if (strcmp (bus_textual, "scsi") == 0) {
00900 drive->bus = HAL_DRIVE_BUS_SCSI;
00901 }
00902 }
00903
00904 hal_free_string (bus_textual);
00905 hal_free_property_set (properties);
00906
00907 return drive;
00908
00909 error:
00910 hal_free_string (bus_textual);
00911 hal_free_property_set (properties);
00912 hal_drive_free (drive);
00913 return NULL;
00914 }
00915
00916 const char *
00917 hal_volume_get_storage_device_udi (HalVolume *volume)
00918 {
00919 return volume->storage_device;
00920 }
00921
00922 const char *hal_drive_get_physical_device_udi (HalDrive *drive)
00923 {
00924 return drive->physical_device;
00925 }
00926
00927 dbus_bool_t
00928 hal_drive_requires_eject (HalDrive *drive)
00929 {
00930 return drive->requires_eject;
00931 }
00932
00941 HalVolume *
00942 hal_volume_from_udi (LibHalContext *hal_ctx, const char *udi)
00943 {
00944 char *disc_type_textual;
00945 HalVolume *vol;
00946 LibHalPropertySet *properties;
00947 LibHalPropertySetIterator it;
00948
00949 vol = NULL;
00950 properties = NULL;
00951 disc_type_textual = NULL;
00952
00953 if (!hal_device_query_capability (hal_ctx, udi, "volume"))
00954 goto error;
00955
00956 vol = malloc (sizeof (HalVolume));
00957 if (vol == NULL)
00958 goto error;
00959 memset (vol, 0x00, sizeof (HalVolume));
00960
00961 vol->udi = strdup (udi);
00962
00963 properties = hal_device_get_all_properties (hal_ctx, udi);
00964 if (properties == NULL)
00965 goto error;
00966
00967
00968 for (hal_psi_init (&it, properties); hal_psi_has_more (&it); hal_psi_next (&it)) {
00969 int type;
00970 char *key;
00971
00972 type = hal_psi_get_type (&it);
00973 key = hal_psi_get_key (&it);
00974
00975 HAL_PROP_EXTRACT_BEGIN;
00976
00977 HAL_PROP_EXTRACT_INT ("volume.partition.msdos_part_table_type", vol->msdos_part_table_type);
00978
00979 HAL_PROP_EXTRACT_INT ("block.minor", vol->device_minor);
00980 HAL_PROP_EXTRACT_INT ("block.major", vol->device_major);
00981 HAL_PROP_EXTRACT_STRING ("block.device", vol->device_file);
00982
00983 HAL_PROP_EXTRACT_STRING ("block.storage_device", vol->storage_device);
00984
00985 HAL_PROP_EXTRACT_INT ("volume.block_size", vol->block_size);
00986 HAL_PROP_EXTRACT_INT ("volume.num_blocks", vol->num_blocks);
00987 HAL_PROP_EXTRACT_STRING ("volume.label", vol->volume_label);
00988 HAL_PROP_EXTRACT_STRING ("volume.mount_point", vol->mount_point);
00989 HAL_PROP_EXTRACT_STRING ("volume.fstype", vol->fstype);
00990 HAL_PROP_EXTRACT_BOOL ("volume.is_mounted", vol->is_mounted);
00991
00992 HAL_PROP_EXTRACT_BOOL ("volume.is_disc", vol->is_disc);
00993 HAL_PROP_EXTRACT_STRING ("volume.disc.type", disc_type_textual);
00994 HAL_PROP_EXTRACT_BOOL ("volume.disc.has_audio", vol->disc_has_audio);
00995 HAL_PROP_EXTRACT_BOOL ("volume.disc.has_data", vol->disc_has_data);
00996 HAL_PROP_EXTRACT_BOOL ("volume.disc.is_appendable", vol->disc_is_appendable);
00997 HAL_PROP_EXTRACT_BOOL ("volume.disc.is_blank", vol->disc_is_blank);
00998 HAL_PROP_EXTRACT_BOOL ("volume.disc.is_rewritable", vol->disc_is_rewritable);
00999
01000 HAL_PROP_EXTRACT_BOOL ("volume.policy.should_mount", vol->should_mount);
01001 HAL_PROP_EXTRACT_STRING ("volume.policy.desired_mount_point", vol->desired_mount_point);
01002 HAL_PROP_EXTRACT_STRING ("volume.policy.mount_filesystem", vol->mount_filesystem);
01003
01004 HAL_PROP_EXTRACT_END;
01005 }
01006
01007 if (disc_type_textual != NULL) {
01008 if (strcmp (disc_type_textual, "cd_rom") == 0) {
01009 vol->disc_type = HAL_VOLUME_DISC_TYPE_CDROM;
01010 } else if (strcmp (disc_type_textual, "cd_r") == 0) {
01011 vol->disc_type = HAL_VOLUME_DISC_TYPE_CDR;
01012 } else if (strcmp (disc_type_textual, "cd_rw") == 0) {
01013 vol->disc_type = HAL_VOLUME_DISC_TYPE_CDRW;
01014 } else if (strcmp (disc_type_textual, "dvd_rom") == 0) {
01015 vol->disc_type = HAL_VOLUME_DISC_TYPE_DVDROM;
01016 } else if (strcmp (disc_type_textual, "dvd_ram") == 0) {
01017 vol->disc_type = HAL_VOLUME_DISC_TYPE_DVDRAM;
01018 } else if (strcmp (disc_type_textual, "dvd_r") == 0) {
01019 vol->disc_type = HAL_VOLUME_DISC_TYPE_DVDR;
01020 } else if (strcmp (disc_type_textual, "dvd_rw") == 0) {
01021 vol->disc_type = HAL_VOLUME_DISC_TYPE_DVDRW;
01022 } else if (strcmp (disc_type_textual, "dvd_plusr") == 0) {
01023 vol->disc_type = HAL_VOLUME_DISC_TYPE_DVDPLUSR;
01024 } else if (strcmp (disc_type_textual, "dvd_plusrw") == 0) {
01025 vol->disc_type = HAL_VOLUME_DISC_TYPE_DVDPLUSRW;
01026 }
01027 }
01028
01029 hal_free_string (disc_type_textual);
01030 hal_free_property_set (properties);
01031 return vol;
01032 error:
01033 hal_free_string (disc_type_textual);
01034 hal_free_property_set (properties);
01035 hal_volume_free (vol);
01036 return NULL;
01037 }
01038
01039
01048 int
01049 hal_volume_get_msdos_part_table_type (HalVolume *volume)
01050 {
01051 return volume->msdos_part_table_type;
01052 }
01053
01054
01055
01063 HalDrive *
01064 hal_drive_from_device_file (LibHalContext *hal_ctx, const char *device_file)
01065 {
01066 int i;
01067 char **hal_udis;
01068 int num_hal_udis;
01069 HalDrive *result;
01070 char *found_udi;
01071
01072 result = NULL;
01073 found_udi = NULL;
01074
01075 if ((hal_udis = hal_manager_find_device_string_match (hal_ctx, "block.device",
01076 device_file, &num_hal_udis)) == NULL)
01077 goto out;
01078
01079 for (i = 0; i < num_hal_udis; i++) {
01080 char *udi;
01081 char *storage_udi;
01082 udi = hal_udis[i];
01083 if (hal_device_query_capability (hal_ctx, udi, "volume")) {
01084
01085 storage_udi = hal_device_get_property_string (hal_ctx, udi, "block.storage_device");
01086 if (storage_udi == NULL)
01087 continue;
01088 found_udi = strdup (storage_udi);
01089 hal_free_string (storage_udi);
01090 break;
01091 } else if (hal_device_query_capability (hal_ctx, udi, "storage")) {
01092 found_udi = strdup (udi);
01093 }
01094 }
01095
01096 hal_free_string_array (hal_udis);
01097
01098 if (found_udi != NULL)
01099 result = hal_drive_from_udi (hal_ctx, found_udi);
01100
01101 free (found_udi);
01102 out:
01103 return result;
01104 }
01105
01106
01113 HalVolume *
01114 hal_volume_from_device_file (LibHalContext *hal_ctx, const char *device_file)
01115 {
01116 int i;
01117 char **hal_udis;
01118 int num_hal_udis;
01119 HalVolume *result;
01120 char *found_udi;
01121
01122 result = NULL;
01123 found_udi = NULL;
01124
01125 if ((hal_udis = hal_manager_find_device_string_match (hal_ctx, "block.device",
01126 device_file, &num_hal_udis)) == NULL)
01127 goto out;
01128
01129 for (i = 0; i < num_hal_udis; i++) {
01130 char *udi;
01131 udi = hal_udis[i];
01132 if (hal_device_query_capability (hal_ctx, udi, "volume")) {
01133 found_udi = strdup (udi);
01134 break;
01135 }
01136 }
01137
01138 hal_free_string_array (hal_udis);
01139
01140 if (found_udi != NULL)
01141 result = hal_volume_from_udi (hal_ctx, found_udi);
01142
01143 free (found_udi);
01144 out:
01145 return result;
01146 }
01147
01148 dbus_uint64_t
01149 hal_volume_get_size (HalVolume *volume)
01150 {
01151 return ((dbus_uint64_t)volume->block_size) * ((dbus_uint64_t)volume->num_blocks);
01152 }
01153
01154
01155 dbus_bool_t
01156 hal_drive_is_hotpluggable (HalDrive *drive)
01157 {
01158 return drive->is_hotpluggable;
01159 }
01160
01161 dbus_bool_t
01162 hal_drive_uses_removable_media (HalDrive *drive)
01163 {
01164 return drive->is_removable;
01165 }
01166
01167 HalDriveType
01168 hal_drive_get_type (HalDrive *drive)
01169 {
01170 return drive->type;
01171 }
01172
01173 HalDriveBus
01174 hal_drive_get_bus (HalDrive *drive)
01175 {
01176 return drive->bus;
01177 }
01178
01179 HalDriveCdromCaps
01180 hal_drive_get_cdrom_caps (HalDrive *drive)
01181 {
01182 return drive->cdrom_caps;
01183 }
01184
01185 unsigned int
01186 hal_drive_get_device_major (HalDrive *drive)
01187 {
01188 return drive->device_major;
01189 }
01190
01191 unsigned int
01192 hal_drive_get_device_minor (HalDrive *drive)
01193 {
01194 return drive->device_minor;
01195 }
01196
01197 const char *
01198 hal_drive_get_type_textual (HalDrive *drive)
01199 {
01200 return drive->type_textual;
01201 }
01202
01203 const char *
01204 hal_drive_get_device_file (HalDrive *drive)
01205 {
01206 return drive->device_file;
01207 }
01208
01209 const char *
01210 hal_drive_get_udi (HalDrive *drive)
01211 {
01212 return drive->udi;
01213 }
01214
01215 const char *
01216 hal_drive_get_serial (HalDrive *drive)
01217 {
01218 return drive->serial;
01219 }
01220
01221 const char *
01222 hal_drive_get_firmware_version (HalDrive *drive)
01223 {
01224 return drive->firmware_version;
01225 }
01226
01227 const char *
01228 hal_drive_get_model (HalDrive *drive)
01229 {
01230 return drive->model;
01231 }
01232
01233 const char *
01234 hal_drive_get_vendor (HalDrive *drive)
01235 {
01236 return drive->vendor;
01237 }
01238
01239
01240
01241 const char *
01242 hal_volume_get_udi (HalVolume *volume)
01243 {
01244 return volume->udi;
01245 }
01246
01247 const char *
01248 hal_volume_get_device_file (HalVolume *volume)
01249 {
01250 return volume->device_file;
01251 }
01252
01253 unsigned int hal_volume_get_device_major (HalVolume *volume)
01254 {
01255 return volume->device_major;
01256 }
01257
01258 unsigned int hal_volume_get_device_minor (HalVolume *volume)
01259 {
01260 return volume->device_minor;
01261 }
01262
01263 const char *
01264 hal_volume_get_fstype (HalVolume *volume)
01265 {
01266 return volume->fstype;
01267 }
01268
01269 const char *
01270 hal_volume_get_fsversion (HalVolume *volume)
01271 {
01272 return volume->fsversion;
01273 }
01274
01275 HalVolumeUsage
01276 hal_volume_get_fsusage (HalVolume *volume)
01277 {
01278 return volume->fsusage;
01279 }
01280
01281 dbus_bool_t
01282 hal_volume_is_mounted (HalVolume *volume)
01283 {
01284 return volume->is_mounted;
01285 }
01286
01287 dbus_bool_t
01288 hal_volume_is_partition (HalVolume *volume)
01289 {
01290 return volume->is_partition;
01291 }
01292
01293 dbus_bool_t
01294 hal_volume_is_disc (HalVolume *volume)
01295 {
01296 return volume->is_disc;
01297 }
01298
01299 unsigned int
01300 hal_volume_get_partition_number (HalVolume *volume)
01301 {
01302 return volume->partition_number;
01303 }
01304
01305 const char *
01306 hal_volume_get_label (HalVolume *volume)
01307 {
01308 return volume->volume_label;
01309 }
01310
01311 const char *
01312 hal_volume_get_mount_point (HalVolume *volume)
01313 {
01314 return volume->mount_point;
01315 }
01316
01317 const char *
01318 hal_volume_get_uuid (HalVolume *volume)
01319 {
01320 return volume->uuid;
01321 }
01322
01323 dbus_bool_t
01324 hal_volume_disc_has_audio (HalVolume *volume)
01325 {
01326 return volume->disc_has_audio;
01327 }
01328
01329 dbus_bool_t
01330 hal_volume_disc_has_data (HalVolume *volume)
01331 {
01332 return volume->disc_has_data;
01333 }
01334
01335 dbus_bool_t
01336 hal_volume_disc_is_blank (HalVolume *volume)
01337 {
01338 return volume->disc_is_blank;
01339 }
01340
01341 dbus_bool_t
01342 hal_volume_disc_is_rewritable (HalVolume *volume)
01343 {
01344 return volume->disc_is_rewritable;
01345 }
01346
01347 dbus_bool_t
01348 hal_volume_disc_is_appendable (HalVolume *volume)
01349 {
01350 return volume->disc_is_appendable;
01351 }
01352
01353 HalVolumeDiscType
01354 hal_volume_get_disc_type (HalVolume *volume)
01355 {
01356 return volume->disc_type;
01357 }
01358
01359 char **
01360 hal_drive_find_all_volumes (LibHalContext *hal_ctx, HalDrive *drive, int *num_volumes)
01361 {
01362 int i;
01363 char **udis;
01364 int num_udis;
01365 const char *drive_udi;
01366 char **result;
01367
01368 udis = NULL;
01369 result = NULL;
01370 *num_volumes = 0;
01371
01372 drive_udi = hal_drive_get_udi (drive);
01373 if (drive_udi == NULL)
01374 goto out;
01375
01376
01377 if ((udis = hal_manager_find_device_string_match (hal_ctx, "block.storage_device",
01378 drive_udi, &num_udis)) == NULL)
01379 goto out;
01380
01381 result = malloc (sizeof (char *) * num_udis);
01382 if (result == NULL)
01383 goto out;
01384
01385
01386 for (i = 0; i < num_udis; i++) {
01387 if (strcmp (udis[i], drive_udi) == 0)
01388 continue;
01389 result[*num_volumes] = strdup (udis[i]);
01390 *num_volumes = (*num_volumes) + 1;
01391 }
01392
01393 out:
01394 hal_free_string_array (udis);
01395 return result;
01396 }
01397
01398
01399
01400 char *
01401 hal_drive_policy_default_get_mount_root (LibHalContext *hal_ctx)
01402 {
01403 return hal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer",
01404 "storage.policy.default.mount_root");
01405 }
01406
01407 dbus_bool_t
01408 hal_drive_policy_default_use_managed_keyword (LibHalContext *hal_ctx)
01409 {
01410 return hal_device_get_property_bool (hal_ctx, "/org/freedesktop/Hal/devices/computer",
01411 "storage.policy.default.use_managed_keyword");
01412 }
01413
01414 char *
01415 hal_drive_policy_default_get_managed_keyword_primary (LibHalContext *hal_ctx)
01416 {
01417 return hal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer",
01418 "storage.policy.default.managed_keyword.primary");
01419 }
01420
01421 char *
01422 hal_drive_policy_default_get_managed_keyword_secondary (LibHalContext *hal_ctx)
01423 {
01424 return hal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer",
01425 "storage.policy.default.managed_keyword.secondary");
01426 }
01427
01428
01429
01430 dbus_bool_t
01431 hal_drive_policy_is_mountable (HalDrive *drive, HalStoragePolicy *policy)
01432 {
01433 return drive->should_mount && drive->no_partitions_hint;
01434 }
01435
01436 const char *
01437 hal_drive_policy_get_desired_mount_point (HalDrive *drive, HalStoragePolicy *policy)
01438 {
01439 return drive->desired_mount_point;
01440 }
01441
01442
01443 #define strcat_len(dst, src, dstmaxlen) do { \
01444 dst[dstmaxlen - 1] = '\0'; \
01445 strncat (dst, src, dstmaxlen - strlen (dst) - 1); \
01446 } while(0)
01447
01448
01449 static void
01450 mopts_collect (LibHalContext *hal_ctx, const char *namespace, int namespace_len,
01451 const char *udi, char *options_string, size_t options_max_len, dbus_bool_t only_collect_imply_opts)
01452 {
01453 LibHalPropertySet *properties;
01454 LibHalPropertySetIterator it;
01455
01456
01457 properties = hal_device_get_all_properties (hal_ctx, udi);
01458 if (properties == NULL)
01459 goto error;
01460 for (hal_psi_init (&it, properties); hal_psi_has_more (&it); hal_psi_next (&it)) {
01461 int type;
01462 char *key;
01463
01464 type = hal_psi_get_type (&it);
01465 key = hal_psi_get_key (&it);
01466 if (hal_psi_get_type (&it) == DBUS_TYPE_BOOLEAN && hal_psi_get_bool (&it) &&
01467 strncmp (key, namespace, namespace_len - 1) == 0) {
01468 const char *option = key + namespace_len - 1;
01469 char *location;
01470 dbus_bool_t is_imply_opt;
01471
01472 is_imply_opt = FALSE;
01473 if (strcmp (option, "user") == 0 ||
01474 strcmp (option, "users") == 0 ||
01475 strcmp (option, "defaults") == 0 ||
01476 strcmp (option, "pamconsole"))
01477 is_imply_opt = TRUE;
01478
01479 if (only_collect_imply_opts) {
01480 if (!is_imply_opt)
01481 continue;
01482 } else {
01483 if (is_imply_opt)
01484 continue;
01485 }
01486
01487
01488 location = strstr (options_string, option);
01489 if (location == NULL) {
01490 if (strlen (options_string) > 0)
01491 strcat_len (options_string, ",", options_max_len);
01492 strcat_len (options_string, option, options_max_len);
01493 }
01494 }
01495 }
01496 error:
01497 hal_free_property_set (properties);
01498 }
01499
01500
01501 const char *
01502 hal_drive_policy_get_mount_options (HalDrive *drive, HalStoragePolicy *policy)
01503 {
01504 const char *result;
01505 char stor_mount_option_default_begin[] = "storage.policy.default.mount_option.";
01506 char stor_mount_option_begin[] = "storage.policy.mount_option.";
01507
01508 result = NULL;
01509 drive->mount_options[0] = '\0';
01510
01511
01512 mopts_collect (drive->hal_ctx, stor_mount_option_begin, sizeof (stor_mount_option_begin),
01513 drive->udi, drive->mount_options, MOUNT_OPTIONS_SIZE, FALSE);
01514 mopts_collect (drive->hal_ctx, stor_mount_option_default_begin, sizeof (stor_mount_option_default_begin),
01515 "/org/freedesktop/Hal/devices/computer", drive->mount_options, MOUNT_OPTIONS_SIZE, FALSE);
01516
01517 mopts_collect (drive->hal_ctx, stor_mount_option_begin, sizeof (stor_mount_option_begin),
01518 drive->udi, drive->mount_options, MOUNT_OPTIONS_SIZE, TRUE);
01519 mopts_collect (drive->hal_ctx, stor_mount_option_default_begin, sizeof (stor_mount_option_default_begin),
01520 "/org/freedesktop/Hal/devices/computer", drive->mount_options, MOUNT_OPTIONS_SIZE, TRUE);
01521
01522 result = drive->mount_options;
01523
01524 return result;
01525 }
01526
01527 const char *
01528 hal_drive_policy_get_mount_fs (HalDrive *drive, HalStoragePolicy *policy)
01529 {
01530 return drive->mount_filesystem;
01531 }
01532
01533
01534 dbus_bool_t
01535 hal_volume_policy_is_mountable (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy)
01536 {
01537 return drive->should_mount && volume->should_mount;
01538 }
01539
01540 const char *hal_volume_policy_get_desired_mount_point (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy)
01541 {
01542 return volume->desired_mount_point;
01543 }
01544
01545 const char *hal_volume_policy_get_mount_options (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy)
01546 {
01547 const char *result;
01548 char stor_mount_option_default_begin[] = "storage.policy.default.mount_option.";
01549 char vol_mount_option_begin[] = "volume.policy.mount_option.";
01550
01551 result = NULL;
01552 volume->mount_options[0] = '\0';
01553
01554
01555 mopts_collect (drive->hal_ctx, vol_mount_option_begin, sizeof (vol_mount_option_begin),
01556 volume->udi, volume->mount_options, MOUNT_OPTIONS_SIZE, FALSE);
01557 mopts_collect (drive->hal_ctx, stor_mount_option_default_begin, sizeof (stor_mount_option_default_begin),
01558 "/org/freedesktop/Hal/devices/computer", volume->mount_options, MOUNT_OPTIONS_SIZE, FALSE);
01559
01560 mopts_collect (drive->hal_ctx, vol_mount_option_begin, sizeof (vol_mount_option_begin),
01561 volume->udi, volume->mount_options, MOUNT_OPTIONS_SIZE, TRUE);
01562 mopts_collect (drive->hal_ctx, stor_mount_option_default_begin, sizeof (stor_mount_option_default_begin),
01563 "/org/freedesktop/Hal/devices/computer", volume->mount_options, MOUNT_OPTIONS_SIZE, TRUE);
01564
01565 result = volume->mount_options;
01566
01567 return result;
01568 }
01569
01570 const char *hal_volume_policy_get_mount_fs (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy)
01571 {
01572 return volume->mount_filesystem;
01573 }
01574
01575 dbus_bool_t
01576 hal_drive_no_partitions_hint (HalDrive *drive)
01577 {
01578 return drive->no_partitions_hint;
01579 }
01580