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) (String)
00057 # define N_(String) (String)
00058 #endif
00059
00071 typedef struct IconMappingEntry_s {
00072 LibHalStoragePolicyIcon icon;
00073 char *path;
00074 struct IconMappingEntry_s *next;
00075 } IconMappingEntry;
00076
00077 struct LibHalStoragePolicy_s {
00078 IconMappingEntry *icon_mappings;
00079 };
00080
00081 LibHalStoragePolicy *
00082 libhal_storage_policy_new ()
00083 {
00084 LibHalStoragePolicy *p;
00085
00086 p = malloc (sizeof (LibHalStoragePolicy));
00087 if (p == NULL)
00088 goto out;
00089
00090 p->icon_mappings = NULL;
00091 out:
00092 return p;
00093 }
00094
00095 void
00096 libhal_storage_policy_free (LibHalStoragePolicy *policy)
00097 {
00098 IconMappingEntry *i;
00099 IconMappingEntry *j;
00100
00101
00102 for (i = policy->icon_mappings; i != NULL; i = j) {
00103 j = i->next;
00104 free (i->path);
00105 free (i);
00106 }
00107
00108 free (policy);
00109 }
00110
00111 void
00112 libhal_storage_policy_set_icon_path (LibHalStoragePolicy *policy, LibHalStoragePolicyIcon icon, const char *path)
00113 {
00114 IconMappingEntry *i;
00115
00116
00117 for (i = policy->icon_mappings; i != NULL; i = i->next) {
00118 if (i->icon == icon) {
00119 free (i->path);
00120 i->path = strdup (path);
00121 goto out;
00122 }
00123 }
00124
00125 i = malloc (sizeof (IconMappingEntry));
00126 if (i == NULL)
00127 goto out;
00128 i->icon = icon;
00129 i->path = strdup (path);
00130 i->next = policy->icon_mappings;
00131 policy->icon_mappings = i;
00132
00133 out:
00134 return;
00135 }
00136
00137 void
00138 libhal_storage_policy_set_icon_mapping (LibHalStoragePolicy *policy, LibHalStoragePolicyIconPair *pairs)
00139 {
00140 LibHalStoragePolicyIconPair *i;
00141
00142 for (i = pairs; i->icon != 0x00; i++) {
00143 libhal_storage_policy_set_icon_path (policy, i->icon, i->icon_path);
00144 }
00145 }
00146
00147 const char *
00148 libhal_storage_policy_lookup_icon (LibHalStoragePolicy *policy, LibHalStoragePolicyIcon icon)
00149 {
00150 IconMappingEntry *i;
00151 const char *path;
00152
00153 path = NULL;
00154 for (i = policy->icon_mappings; i != NULL; i = i->next) {
00155 if (i->icon == icon) {
00156 path = i->path;
00157 goto out;
00158 }
00159 }
00160 out:
00161 return path;
00162 }
00163
00164
00165 #define MAX_STRING_SZ 256
00166
00167 char *
00168 libhal_volume_policy_compute_size_as_string (LibHalVolume *volume)
00169 {
00170 dbus_uint64_t size;
00171 char *result;
00172 char* sizes_str[] = {"K", "M", "G", "T", NULL};
00173 dbus_uint64_t cur = 1000L;
00174 dbus_uint64_t base = 10L;
00175 dbus_uint64_t step = 10L*10L*10L;
00176 int cur_str = 0;
00177 char buf[MAX_STRING_SZ];
00178
00179 result = NULL;
00180
00181 size = libhal_volume_get_size (volume);
00182
00183 do {
00184 if (sizes_str[cur_str+1] == NULL || size < cur*step) {
00185
00186 if (size < cur*base) {
00187 snprintf (buf, MAX_STRING_SZ, "%.01f%s",
00188 ((double)size)/((double)cur), sizes_str[cur_str]);
00189 result = strdup (buf);
00190 } else {
00191 snprintf (buf, MAX_STRING_SZ, "%lld%s", size / cur, sizes_str[cur_str]);
00192 result = strdup (buf);
00193 }
00194 goto out;
00195 }
00196
00197 cur *= step;
00198 cur_str++;
00199 } while (1);
00200
00201 out:
00202 return result;
00203 }
00204
00205 static void
00206 fixup_string (char *s)
00207 {
00208
00209
00210
00211
00212 }
00213
00214
00215 char *
00216 libhal_drive_policy_compute_display_name (LibHalDrive *drive, LibHalVolume *volume, LibHalStoragePolicy *policy)
00217 {
00218 char *name;
00219 char *size_str;
00220 char *vendormodel_str;
00221 const char *model;
00222 const char *vendor;
00223 LibHalDriveType drive_type;
00224 dbus_bool_t drive_is_hotpluggable;
00225 dbus_bool_t drive_is_removable;
00226 LibHalDriveCdromCaps drive_cdrom_caps;
00227 char buf[MAX_STRING_SZ];
00228
00229 model = libhal_drive_get_model (drive);
00230 vendor = libhal_drive_get_vendor (drive);
00231 drive_type = libhal_drive_get_type (drive);
00232 drive_is_hotpluggable = libhal_drive_is_hotpluggable (drive);
00233 drive_is_removable = libhal_drive_uses_removable_media (drive);
00234 drive_cdrom_caps = libhal_drive_get_cdrom_caps (drive);
00235
00236 if (volume != NULL)
00237 size_str = libhal_volume_policy_compute_size_as_string (volume);
00238 else
00239 size_str = NULL;
00240
00241 if (vendor == NULL || strlen (vendor) == 0) {
00242 if (model == NULL || strlen (model) == 0)
00243 vendormodel_str = strdup ("");
00244 else
00245 vendormodel_str = strdup (model);
00246 } else {
00247 if (model == NULL || strlen (model) == 0)
00248 vendormodel_str = strdup (vendor);
00249 else {
00250 snprintf (buf, MAX_STRING_SZ, "%s %s", vendor, model);
00251 vendormodel_str = strdup (buf);
00252 }
00253 }
00254
00255 fixup_string (vendormodel_str);
00256
00257 if (drive_type==LIBHAL_DRIVE_TYPE_CDROM) {
00258
00259
00260 char *first;
00261 char *second;
00262
00263
00264 first = "CD-ROM";
00265 if (drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_CDR)
00266 first = "CD-R";
00267 if (drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_CDRW)
00268 first = "CD-RW";
00269
00270 second = "";
00271 if (drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_DVDROM)
00272 second = "/DVD-ROM";
00273 if (drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSR)
00274 second = "/DVD+R";
00275 if (drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSRW)
00276 second = "/DVD+RW";
00277 if (drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_DVDR)
00278 second = "/DVD-R";
00279 if (drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_DVDRW)
00280 second = "/DVD-RW";
00281 if (drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_DVDRAM)
00282 second = "/DVD-RAM";
00283 if ((drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_DVDR) &&
00284 (drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSR)) {
00285 if(drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSRDL)
00286 second = "/DVD±R DL";
00287 else
00288 second = "/DVD±R";
00289 }
00290 if ((drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_DVDRW) &&
00291 (drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSRW)) {
00292 if(drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSRDL)
00293 second = "/DVD±RW DL";
00294 else
00295 second = "/DVD±RW";
00296 }
00297 if (drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_BDROM)
00298 second = "/BD-ROM";
00299 if (drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_BDR)
00300 second = "/BD-R";
00301 if (drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_BDRE)
00302 second = "/BD-RE";
00303 if (drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_HDDVDROM)
00304 second = "/HD DVD-ROM";
00305 if (drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_HDDVDR)
00306 second = "/HD DVD-R";
00307 if (drive_cdrom_caps & LIBHAL_DRIVE_CDROM_CAPS_HDDVDRW)
00308 second = "/HD DVD-RW";
00309
00310 if (drive_is_hotpluggable) {
00311 snprintf (buf, MAX_STRING_SZ, _("External %s%s Drive"), first, second);
00312 name = strdup (buf);
00313 } else {
00314 snprintf (buf, MAX_STRING_SZ, _("%s%s Drive"), first, second);
00315 name = strdup (buf);
00316 }
00317
00318 } else if (drive_type==LIBHAL_DRIVE_TYPE_FLOPPY) {
00319
00320
00321
00322 if (drive_is_hotpluggable)
00323 name = strdup (_("External Floppy Drive"));
00324 else
00325 name = strdup (_("Floppy Drive"));
00326 } else if (drive_type==LIBHAL_DRIVE_TYPE_DISK && !drive_is_removable) {
00327
00328
00329
00330 if (size_str != NULL) {
00331 if (drive_is_hotpluggable) {
00332 snprintf (buf, MAX_STRING_SZ, _("%s External Hard Drive"), size_str);
00333 name = strdup (buf);
00334 } else {
00335 snprintf (buf, MAX_STRING_SZ, _("%s Hard Drive"), size_str);
00336 name = strdup (buf);
00337 }
00338 } else {
00339 if (drive_is_hotpluggable)
00340 name = strdup (_("External Hard Drive"));
00341 else
00342 name = strdup (_("Hard Drive"));
00343 }
00344 } else {
00345
00346
00347
00348 if (strlen (vendormodel_str) > 0)
00349 name = strdup (vendormodel_str);
00350 else
00351 name = strdup (_("Drive"));
00352 }
00353
00354 free (vendormodel_str);
00355 free (size_str);
00356
00357 return name;
00358 }
00359
00360 char *
00361 libhal_volume_policy_compute_display_name (LibHalDrive *drive, LibHalVolume *volume, LibHalStoragePolicy *policy)
00362 {
00363 char *name;
00364 char *size_str;
00365 const char *volume_label;
00366 const char *model;
00367 const char *vendor;
00368 LibHalDriveType drive_type;
00369 dbus_bool_t drive_is_hotpluggable;
00370 dbus_bool_t drive_is_removable;
00371 LibHalDriveCdromCaps drive_cdrom_caps;
00372 char buf[MAX_STRING_SZ];
00373
00374 volume_label = libhal_volume_get_label (volume);
00375 model = libhal_drive_get_model (drive);
00376 vendor = libhal_drive_get_vendor (drive);
00377 drive_type = libhal_drive_get_type (drive);
00378 drive_is_hotpluggable = libhal_drive_is_hotpluggable (drive);
00379 drive_is_removable = libhal_drive_uses_removable_media (drive);
00380 drive_cdrom_caps = libhal_drive_get_cdrom_caps (drive);
00381
00382 size_str = libhal_volume_policy_compute_size_as_string (volume);
00383
00384
00385
00386
00387
00388 if (volume_label != NULL) {
00389 name = strdup (volume_label);
00390 goto out;
00391 }
00392
00393
00394 if (drive_type==LIBHAL_DRIVE_TYPE_CDROM) {
00395 switch (libhal_volume_get_disc_type (volume)) {
00396
00397 default:
00398
00399 case LIBHAL_VOLUME_DISC_TYPE_CDROM:
00400 name = strdup (_("CD-ROM "));
00401 break;
00402
00403 case LIBHAL_VOLUME_DISC_TYPE_CDR:
00404 if (libhal_volume_disc_is_blank (volume))
00405 name = strdup (_("Blank CD-R"));
00406 else
00407 name = strdup (_("CD-R"));
00408 break;
00409
00410 case LIBHAL_VOLUME_DISC_TYPE_CDRW:
00411 if (libhal_volume_disc_is_blank (volume))
00412 name = strdup (_("Blank CD-RW"));
00413 else
00414 name = strdup (_("CD-RW"));
00415 break;
00416
00417 case LIBHAL_VOLUME_DISC_TYPE_DVDROM:
00418 name = strdup (_("DVD-ROM"));
00419 break;
00420
00421 case LIBHAL_VOLUME_DISC_TYPE_DVDRAM:
00422 if (libhal_volume_disc_is_blank (volume))
00423 name = strdup (_("Blank DVD-RAM"));
00424 else
00425 name = strdup (_("DVD-RAM"));
00426 break;
00427
00428 case LIBHAL_VOLUME_DISC_TYPE_DVDR:
00429 if (libhal_volume_disc_is_blank (volume))
00430 name = strdup (_("Blank DVD-R"));
00431 else
00432 name = strdup (_("DVD-R"));
00433 break;
00434
00435 case LIBHAL_VOLUME_DISC_TYPE_DVDRW:
00436 if (libhal_volume_disc_is_blank (volume))
00437 name = strdup (_("Blank DVD-RW"));
00438 else
00439 name = strdup (_("DVD-RW"));
00440 break;
00441
00442 case LIBHAL_VOLUME_DISC_TYPE_DVDPLUSR:
00443 if (libhal_volume_disc_is_blank (volume))
00444 name = strdup (_("Blank DVD+R"));
00445 else
00446 name = strdup (_("DVD+R"));
00447 break;
00448
00449 case LIBHAL_VOLUME_DISC_TYPE_DVDPLUSRW:
00450 if (libhal_volume_disc_is_blank (volume))
00451 name = strdup (_("Blank DVD+RW"));
00452 else
00453 name = strdup (_("DVD+RW"));
00454 break;
00455
00456 case LIBHAL_VOLUME_DISC_TYPE_DVDPLUSR_DL:
00457 if (libhal_volume_disc_is_blank (volume))
00458 name = strdup (_("Blank DVD+R Dual-Layer"));
00459 else
00460 name = strdup (_("DVD+R Dual-Layer"));
00461 break;
00462
00463 case LIBHAL_VOLUME_DISC_TYPE_BDROM:
00464 name = strdup (_("BD-ROM"));
00465 break;
00466
00467 case LIBHAL_VOLUME_DISC_TYPE_BDR:
00468 if (libhal_volume_disc_is_blank (volume))
00469 name = strdup (_("Blank BD-R"));
00470 else
00471 name = strdup (_("BD-R"));
00472 break;
00473
00474 case LIBHAL_VOLUME_DISC_TYPE_BDRE:
00475 if (libhal_volume_disc_is_blank (volume))
00476 name = strdup (_("Blank BD-RE"));
00477 else
00478 name = strdup (_("BD-RE"));
00479 break;
00480
00481 case LIBHAL_VOLUME_DISC_TYPE_HDDVDROM:
00482 name = strdup (_("HD DVD-ROM"));
00483 break;
00484
00485 case LIBHAL_VOLUME_DISC_TYPE_HDDVDR:
00486 if (libhal_volume_disc_is_blank (volume))
00487 name = strdup (_("Blank HD DVD-R"));
00488 else
00489 name = strdup (_("HD DVD-R"));
00490 break;
00491
00492 case LIBHAL_VOLUME_DISC_TYPE_HDDVDRW:
00493 if (libhal_volume_disc_is_blank (volume))
00494 name = strdup (_("Blank HD DVD-RW"));
00495 else
00496 name = strdup (_("HD DVD-RW"));
00497 break;
00498
00499 }
00500
00501
00502 if (libhal_volume_disc_has_audio (volume) && !libhal_volume_disc_has_data (volume)) {
00503 free (name);
00504 name = strdup (_("Audio CD"));
00505 }
00506
00507 goto out;
00508 }
00509
00510
00511 if (drive_is_removable) {
00512 snprintf (buf, MAX_STRING_SZ, _("%s Removable Media"), size_str);
00513 name = strdup (buf);
00514 } else {
00515 snprintf (buf, MAX_STRING_SZ, _("%s Media"), size_str);
00516 name = strdup (buf);
00517 }
00518
00519
00520
00521
00522 out:
00523 free (size_str);
00524 return name;
00525 }
00526
00527 char *
00528 libhal_drive_policy_compute_icon_name (LibHalDrive *drive, LibHalVolume *volume, LibHalStoragePolicy *policy)
00529 {
00530 const char *name;
00531 LibHalDriveBus bus;
00532 LibHalDriveType drive_type;
00533
00534 bus = libhal_drive_get_bus (drive);
00535 drive_type = libhal_drive_get_type (drive);
00536
00537
00538
00539 switch (drive_type) {
00540 case LIBHAL_DRIVE_TYPE_REMOVABLE_DISK:
00541 case LIBHAL_DRIVE_TYPE_DISK:
00542 case LIBHAL_DRIVE_TYPE_CDROM:
00543 case LIBHAL_DRIVE_TYPE_FLOPPY:
00544 name = libhal_storage_policy_lookup_icon (policy, 0x10000 + drive_type*0x100 + bus);
00545 break;
00546
00547 default:
00548 name = libhal_storage_policy_lookup_icon (policy, 0x10000 + drive_type*0x100);
00549 }
00550
00551 if (name != NULL)
00552 return strdup (name);
00553 else
00554 return NULL;
00555 }
00556
00557 char *
00558 libhal_volume_policy_compute_icon_name (LibHalDrive *drive, LibHalVolume *volume, LibHalStoragePolicy *policy)
00559 {
00560 const char *name;
00561 LibHalDriveBus bus;
00562 LibHalDriveType drive_type;
00563 LibHalVolumeDiscType disc_type;
00564
00565
00566
00567 if (libhal_volume_is_disc (volume)) {
00568 disc_type = libhal_volume_get_disc_type (volume);
00569 name = libhal_storage_policy_lookup_icon (policy, 0x30000 + disc_type);
00570 goto out;
00571 }
00572
00573 if (drive == NULL) {
00574 name = libhal_storage_policy_lookup_icon (policy, LIBHAL_STORAGE_ICON_VOLUME_REMOVABLE_DISK);
00575 goto out;
00576 }
00577
00578 bus = libhal_drive_get_bus (drive);
00579 drive_type = libhal_drive_get_type (drive);
00580
00581 switch (drive_type) {
00582 case LIBHAL_DRIVE_TYPE_REMOVABLE_DISK:
00583 case LIBHAL_DRIVE_TYPE_DISK:
00584 case LIBHAL_DRIVE_TYPE_CDROM:
00585 case LIBHAL_DRIVE_TYPE_FLOPPY:
00586 name = libhal_storage_policy_lookup_icon (policy, 0x20000 + drive_type*0x100 + bus);
00587 break;
00588
00589 default:
00590 name = libhal_storage_policy_lookup_icon (policy, 0x20000 + drive_type*0x100);
00591 }
00592 out:
00593 if (name != NULL)
00594 return strdup (name);
00595 else
00596 return NULL;
00597 }
00598
00615 dbus_bool_t
00616 libhal_volume_policy_should_be_visible (LibHalDrive *drive, LibHalVolume *volume, LibHalStoragePolicy *policy,
00617 const char *target_mount_point)
00618 {
00619 unsigned int i;
00620 dbus_bool_t is_visible;
00621 const char *label;
00622 const char *mount_point;
00623 const char *fstype;
00624 const char *fhs23_toplevel_mount_points[] = {
00625 "/",
00626 "/bin",
00627 "/boot",
00628 "/dev",
00629 "/etc",
00630 "/home",
00631 "/lib",
00632 "/lib64",
00633 "/media",
00634 "/mnt",
00635 "/opt",
00636 "/root",
00637 "/sbin",
00638 "/srv",
00639 "/tmp",
00640 "/usr",
00641 "/var",
00642 "/proc",
00643 "/sbin",
00644 NULL
00645 };
00646
00647 is_visible = FALSE;
00648
00649
00650 if (libhal_volume_get_fsusage (volume) != LIBHAL_VOLUME_USAGE_MOUNTABLE_FILESYSTEM)
00651 goto out;
00652
00653 label = libhal_volume_get_label (volume);
00654 mount_point = libhal_volume_get_mount_point (volume);
00655 fstype = libhal_volume_get_fstype (volume);
00656
00657
00658 if (mount_point == NULL)
00659 mount_point = target_mount_point;
00660
00661
00662 if (fstype == NULL)
00663 goto out;
00664
00665
00666 if (mount_point != NULL) {
00667 for (i = 0; fhs23_toplevel_mount_points[i] != NULL; i++) {
00668 if (strcmp (mount_point, fhs23_toplevel_mount_points[i]) == 0)
00669 goto out;
00670 }
00671 }
00672
00673
00674 if (label != NULL && strcmp (label, "bootstrap") == 0 && strcmp (fstype, "hfs") == 0)
00675 goto out;
00676
00677
00678 is_visible = TRUE;
00679
00680 out:
00681 return is_visible;
00682 }
00683
00684
00685
00686 #define MOUNT_OPTIONS_SIZE 256
00687
00688 struct LibHalDrive_s {
00689 char *udi;
00690
00691 int device_major;
00692 int device_minor;
00693 char *device_file;
00694
00695 LibHalDriveBus bus;
00696 char *vendor;
00697 char *model;
00698 dbus_bool_t is_hotpluggable;
00699 dbus_bool_t is_removable;
00700 dbus_bool_t requires_eject;
00701
00702 LibHalDriveType type;
00703 char *type_textual;
00704
00705 char *physical_device;
00706
00707
00708 char *dedicated_icon_drive;
00709 char *dedicated_icon_volume;
00710
00711 char *serial;
00712 char *firmware_version;
00713 LibHalDriveCdromCaps cdrom_caps;
00714
00715 char *desired_mount_point;
00716 char *mount_filesystem;
00717 dbus_bool_t should_mount;
00718
00719 dbus_bool_t no_partitions_hint;
00720
00721 LibHalContext *hal_ctx;
00722
00723 char **capabilities;
00724
00725 char mount_options[MOUNT_OPTIONS_SIZE];
00726 };
00727
00728 struct LibHalVolume_s {
00729 char *udi;
00730
00731 int device_major;
00732 int device_minor;
00733 char *device_file;
00734 char *volume_label;
00735 dbus_bool_t is_mounted;
00736 dbus_bool_t is_mounted_read_only;
00737 char *mount_point;
00738 char *fstype;
00739 char *fsversion;
00740 char *uuid;
00741 char *storage_device;
00742
00743 LibHalVolumeUsage fsusage;
00744
00745 dbus_bool_t is_partition;
00746 unsigned int partition_number;
00747
00748 int msdos_part_table_type;
00749
00750
00751 dbus_bool_t is_disc;
00752 LibHalVolumeDiscType disc_type;
00753 dbus_bool_t disc_has_audio;
00754 dbus_bool_t disc_has_data;
00755 dbus_bool_t disc_is_appendable;
00756 dbus_bool_t disc_is_blank;
00757 dbus_bool_t disc_is_rewritable;
00758
00759 unsigned int block_size;
00760 unsigned int num_blocks;
00761
00762 char *desired_mount_point;
00763 char *mount_filesystem;
00764 dbus_bool_t should_mount;
00765
00766 dbus_bool_t ignore_volume;
00767
00768 char *crypto_backing_volume;
00769
00770 char mount_options[MOUNT_OPTIONS_SIZE];
00771 };
00772
00773 const char *
00774 libhal_drive_get_dedicated_icon_drive (LibHalDrive *drive)
00775 {
00776 return drive->dedicated_icon_drive;
00777 }
00778
00779 const char *
00780 libhal_drive_get_dedicated_icon_volume (LibHalDrive *drive)
00781 {
00782 return drive->dedicated_icon_volume;
00783 }
00784
00789 void
00790 libhal_drive_free (LibHalDrive *drive)
00791 {
00792 if (drive == NULL )
00793 return;
00794
00795 free (drive->udi);
00796 libhal_free_string (drive->device_file);
00797 libhal_free_string (drive->vendor);
00798 libhal_free_string (drive->model);
00799 libhal_free_string (drive->type_textual);
00800 libhal_free_string (drive->physical_device);
00801 libhal_free_string (drive->serial);
00802 libhal_free_string (drive->firmware_version);
00803 libhal_free_string (drive->desired_mount_point);
00804 libhal_free_string (drive->mount_filesystem);
00805 libhal_free_string_array (drive->capabilities);
00806
00807 free (drive);
00808 }
00809
00810
00815 void
00816 libhal_volume_free (LibHalVolume *vol)
00817 {
00818 if (vol == NULL )
00819 return;
00820
00821 free (vol->udi);
00822 libhal_free_string (vol->device_file);
00823 libhal_free_string (vol->volume_label);
00824 libhal_free_string (vol->fstype);
00825 libhal_free_string (vol->mount_point);
00826 libhal_free_string (vol->fsversion);
00827 libhal_free_string (vol->uuid);
00828 libhal_free_string (vol->desired_mount_point);
00829 libhal_free_string (vol->mount_filesystem);
00830 libhal_free_string (vol->crypto_backing_volume);
00831
00832 free (vol);
00833 }
00834
00835
00836 static char **
00837 my_strvdup (char **strv)
00838 {
00839 unsigned int num_elems;
00840 unsigned int i;
00841 char **res;
00842
00843 for (num_elems = 0; strv[num_elems] != NULL; num_elems++)
00844 ;
00845
00846 res = calloc (num_elems + 1, sizeof (char*));
00847 if (res == NULL)
00848 goto out;
00849
00850 for (i = 0; i < num_elems; i++)
00851 res[i] = strdup (strv[i]);
00852 res[i] = NULL;
00853
00854 out:
00855 return res;
00856 }
00857
00858
00859
00860 #define LIBHAL_PROP_EXTRACT_BEGIN if (FALSE)
00861 #define LIBHAL_PROP_EXTRACT_END ;
00862 #define LIBHAL_PROP_EXTRACT_INT(_property_, _where_) else if (strcmp (key, _property_) == 0 && type == LIBHAL_PROPERTY_TYPE_INT32) _where_ = libhal_psi_get_int (&it)
00863 #define LIBHAL_PROP_EXTRACT_STRING(_property_, _where_) else if (strcmp (key, _property_) == 0 && type == LIBHAL_PROPERTY_TYPE_STRING) _where_ = (libhal_psi_get_string (&it) != NULL && strlen (libhal_psi_get_string (&it)) > 0) ? strdup (libhal_psi_get_string (&it)) : NULL
00864 #define LIBHAL_PROP_EXTRACT_BOOL(_property_, _where_) else if (strcmp (key, _property_) == 0 && type == LIBHAL_PROPERTY_TYPE_BOOLEAN) _where_ = libhal_psi_get_bool (&it)
00865 #define LIBHAL_PROP_EXTRACT_BOOL_BITFIELD(_property_, _where_, _field_) else if (strcmp (key, _property_) == 0 && type == LIBHAL_PROPERTY_TYPE_BOOLEAN) _where_ |= libhal_psi_get_bool (&it) ? _field_ : 0
00866 #define LIBHAL_PROP_EXTRACT_STRLIST(_property_, _where_) else if (strcmp (key, _property_) == 0 && type == LIBHAL_PROPERTY_TYPE_STRLIST) _where_ = my_strvdup (libhal_psi_get_strlist (&it))
00867
00876 LibHalDrive *
00877 libhal_drive_from_udi (LibHalContext *hal_ctx, const char *udi)
00878 {
00879 char *bus_textual;
00880 LibHalDrive *drive;
00881 LibHalPropertySet *properties;
00882 LibHalPropertySetIterator it;
00883 DBusError error;
00884 unsigned int i;
00885
00886 LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL);
00887
00888 drive = NULL;
00889 properties = NULL;
00890 bus_textual = NULL;
00891
00892 dbus_error_init (&error);
00893 if (!libhal_device_query_capability (hal_ctx, udi, "storage", &error))
00894 goto error;
00895
00896 drive = malloc (sizeof (LibHalDrive));
00897 if (drive == NULL)
00898 goto error;
00899 memset (drive, 0x00, sizeof (LibHalDrive));
00900
00901 drive->hal_ctx = hal_ctx;
00902
00903 drive->udi = strdup (udi);
00904 if (drive->udi == NULL)
00905 goto error;
00906
00907 properties = libhal_device_get_all_properties (hal_ctx, udi, &error);
00908 if (properties == NULL)
00909 goto error;
00910
00911
00912 for (libhal_psi_init (&it, properties); libhal_psi_has_more (&it); libhal_psi_next (&it)) {
00913 int type;
00914 char *key;
00915
00916 type = libhal_psi_get_type (&it);
00917 key = libhal_psi_get_key (&it);
00918
00919 LIBHAL_PROP_EXTRACT_BEGIN;
00920
00921 LIBHAL_PROP_EXTRACT_INT ("block.minor", drive->device_minor);
00922 LIBHAL_PROP_EXTRACT_INT ("block.major", drive->device_major);
00923 LIBHAL_PROP_EXTRACT_STRING ("block.device", drive->device_file);
00924 LIBHAL_PROP_EXTRACT_STRING ("storage.bus", bus_textual);
00925 LIBHAL_PROP_EXTRACT_STRING ("storage.vendor", drive->vendor);
00926 LIBHAL_PROP_EXTRACT_STRING ("storage.model", drive->model);
00927 LIBHAL_PROP_EXTRACT_STRING ("storage.drive_type", drive->type_textual);
00928
00929
00930 LIBHAL_PROP_EXTRACT_STRING ("storage.icon.drive", drive->dedicated_icon_drive);
00931 LIBHAL_PROP_EXTRACT_STRING ("storage.icon.volume", drive->dedicated_icon_volume);
00932
00933 LIBHAL_PROP_EXTRACT_BOOL ("storage.hotpluggable", drive->is_hotpluggable);
00934 LIBHAL_PROP_EXTRACT_BOOL ("storage.removable", drive->is_removable);
00935 LIBHAL_PROP_EXTRACT_BOOL ("storage.requires_eject", drive->requires_eject);
00936
00937 LIBHAL_PROP_EXTRACT_STRING ("storage.physical_device", drive->physical_device);
00938 LIBHAL_PROP_EXTRACT_STRING ("storage.firmware_version", drive->firmware_version);
00939 LIBHAL_PROP_EXTRACT_STRING ("storage.serial", drive->serial);
00940
00941 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.cdr", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_CDR);
00942 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.cdrw", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_CDRW);
00943 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvd", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_DVDROM);
00944 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdplusr", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSR);
00945 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdplusrw", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSRW);
00946 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdplusrdl", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSRDL);
00947 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdr", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_DVDR);
00948 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdrw", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_DVDRW);
00949 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdram", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_DVDRAM);
00950 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.bd", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_BDROM);
00951 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.bdr", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_BDR);
00952 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.bdre", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_BDRE);
00953 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.hddvd", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_HDDVDROM);
00954 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.hddvdr", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_HDDVDR);
00955 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.hddvdrw", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_HDDVDRW);
00956
00957 LIBHAL_PROP_EXTRACT_BOOL ("storage.policy.should_mount", drive->should_mount);
00958 LIBHAL_PROP_EXTRACT_STRING ("storage.policy.desired_mount_point", drive->desired_mount_point);
00959 LIBHAL_PROP_EXTRACT_STRING ("storage.policy.mount_filesystem", drive->mount_filesystem);
00960
00961 LIBHAL_PROP_EXTRACT_BOOL ("storage.no_partitions_hint", drive->no_partitions_hint);
00962
00963 LIBHAL_PROP_EXTRACT_STRLIST ("info.capabilities", drive->capabilities);
00964
00965 LIBHAL_PROP_EXTRACT_END;
00966 }
00967
00968 if (drive->type_textual != NULL) {
00969 if (strcmp (drive->type_textual, "cdrom") == 0) {
00970 drive->cdrom_caps |= LIBHAL_DRIVE_CDROM_CAPS_CDROM;
00971 drive->type = LIBHAL_DRIVE_TYPE_CDROM;
00972 } else if (strcmp (drive->type_textual, "floppy") == 0) {
00973 drive->type = LIBHAL_DRIVE_TYPE_FLOPPY;
00974 } else if (strcmp (drive->type_textual, "disk") == 0) {
00975 if (drive->is_removable)
00976 drive->type = LIBHAL_DRIVE_TYPE_REMOVABLE_DISK;
00977 else
00978 drive->type = LIBHAL_DRIVE_TYPE_DISK;
00979 } else if (strcmp (drive->type_textual, "tape") == 0) {
00980 drive->type = LIBHAL_DRIVE_TYPE_TAPE;
00981 } else if (strcmp (drive->type_textual, "compact_flash") == 0) {
00982 drive->type = LIBHAL_DRIVE_TYPE_COMPACT_FLASH;
00983 } else if (strcmp (drive->type_textual, "memory_stick") == 0) {
00984 drive->type = LIBHAL_DRIVE_TYPE_MEMORY_STICK;
00985 } else if (strcmp (drive->type_textual, "smart_media") == 0) {
00986 drive->type = LIBHAL_DRIVE_TYPE_SMART_MEDIA;
00987 } else if (strcmp (drive->type_textual, "sd_mmc") == 0) {
00988 drive->type = LIBHAL_DRIVE_TYPE_SD_MMC;
00989 } else if (strcmp (drive->type_textual, "zip") == 0) {
00990 drive->type = LIBHAL_DRIVE_TYPE_ZIP;
00991 } else if (strcmp (drive->type_textual, "jaz") == 0) {
00992 drive->type = LIBHAL_DRIVE_TYPE_JAZ;
00993 } else if (strcmp (drive->type_textual, "flashkey") == 0) {
00994 drive->type = LIBHAL_DRIVE_TYPE_FLASHKEY;
00995 } else {
00996 drive->type = LIBHAL_DRIVE_TYPE_DISK;
00997 }
00998
00999 }
01000
01001 if (drive->capabilities != NULL) {
01002 for (i = 0; drive->capabilities[i] != NULL; i++) {
01003 if (strcmp (drive->capabilities[i], "portable_audio_player") == 0) {
01004 drive->type = LIBHAL_DRIVE_TYPE_PORTABLE_AUDIO_PLAYER;
01005 break;
01006 } else if (strcmp (drive->capabilities[i], "camera") == 0) {
01007 drive->type = LIBHAL_DRIVE_TYPE_CAMERA;
01008 break;
01009 }
01010 }
01011 }
01012
01013 if (bus_textual != NULL) {
01014 if (strcmp (bus_textual, "usb") == 0) {
01015 drive->bus = LIBHAL_DRIVE_BUS_USB;
01016 } else if (strcmp (bus_textual, "ieee1394") == 0) {
01017 drive->bus = LIBHAL_DRIVE_BUS_IEEE1394;
01018 } else if (strcmp (bus_textual, "ide") == 0) {
01019 drive->bus = LIBHAL_DRIVE_BUS_IDE;
01020 } else if (strcmp (bus_textual, "scsi") == 0) {
01021 drive->bus = LIBHAL_DRIVE_BUS_SCSI;
01022 } else if (strcmp (bus_textual, "ccw") == 0) {
01023 drive->bus = LIBHAL_DRIVE_BUS_CCW;
01024 }
01025 }
01026
01027 libhal_free_string (bus_textual);
01028 libhal_free_property_set (properties);
01029
01030 return drive;
01031
01032 error:
01033 libhal_free_string (bus_textual);
01034 libhal_free_property_set (properties);
01035 libhal_drive_free (drive);
01036 return NULL;
01037 }
01038
01039 const char *
01040 libhal_volume_get_storage_device_udi (LibHalVolume *volume)
01041 {
01042 return volume->storage_device;
01043 }
01044
01045 const char *libhal_drive_get_physical_device_udi (LibHalDrive *drive)
01046 {
01047 return drive->physical_device;
01048 }
01049
01050 dbus_bool_t
01051 libhal_drive_requires_eject (LibHalDrive *drive)
01052 {
01053 return drive->requires_eject;
01054 }
01055
01064 LibHalVolume *
01065 libhal_volume_from_udi (LibHalContext *hal_ctx, const char *udi)
01066 {
01067 char *disc_type_textual;
01068 char *vol_fsusage_textual;
01069 LibHalVolume *vol;
01070 LibHalPropertySet *properties;
01071 LibHalPropertySetIterator it;
01072 DBusError error;
01073
01074 LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL);
01075
01076 vol = NULL;
01077 properties = NULL;
01078 disc_type_textual = NULL;
01079 vol_fsusage_textual = NULL;
01080
01081 dbus_error_init (&error);
01082 if (!libhal_device_query_capability (hal_ctx, udi, "volume", &error))
01083 goto error;
01084
01085 vol = malloc (sizeof (LibHalVolume));
01086 if (vol == NULL)
01087 goto error;
01088 memset (vol, 0x00, sizeof (LibHalVolume));
01089
01090 vol->udi = strdup (udi);
01091
01092 properties = libhal_device_get_all_properties (hal_ctx, udi, &error);
01093 if (properties == NULL)
01094 goto error;
01095
01096
01097 for (libhal_psi_init (&it, properties); libhal_psi_has_more (&it); libhal_psi_next (&it)) {
01098 int type;
01099 char *key;
01100
01101 type = libhal_psi_get_type (&it);
01102 key = libhal_psi_get_key (&it);
01103
01104 LIBHAL_PROP_EXTRACT_BEGIN;
01105
01106 LIBHAL_PROP_EXTRACT_INT ("volume.partition.msdos_part_table_type", vol->msdos_part_table_type);
01107
01108 LIBHAL_PROP_EXTRACT_INT ("block.minor", vol->device_minor);
01109 LIBHAL_PROP_EXTRACT_INT ("block.major", vol->device_major);
01110 LIBHAL_PROP_EXTRACT_STRING ("block.device", vol->device_file);
01111
01112 LIBHAL_PROP_EXTRACT_STRING ("block.storage_device", vol->storage_device);
01113
01114 LIBHAL_PROP_EXTRACT_STRING ("volume.crypto_luks.clear.backing_volume", vol->crypto_backing_volume);
01115
01116 LIBHAL_PROP_EXTRACT_INT ("volume.block_size", vol->block_size);
01117 LIBHAL_PROP_EXTRACT_INT ("volume.num_blocks", vol->num_blocks);
01118 LIBHAL_PROP_EXTRACT_STRING ("volume.label", vol->volume_label);
01119 LIBHAL_PROP_EXTRACT_STRING ("volume.mount_point", vol->mount_point);
01120 LIBHAL_PROP_EXTRACT_STRING ("volume.fstype", vol->fstype);
01121 LIBHAL_PROP_EXTRACT_STRING ("volume.fsversion", vol->fsversion);
01122 LIBHAL_PROP_EXTRACT_BOOL ("volume.is_mounted", vol->is_mounted);
01123 LIBHAL_PROP_EXTRACT_BOOL ("volume.is_mounted_read_only", vol->is_mounted_read_only);
01124 LIBHAL_PROP_EXTRACT_STRING ("volume.fsusage", vol_fsusage_textual);
01125 LIBHAL_PROP_EXTRACT_STRING ("volume.uuid", vol->uuid);
01126
01127 LIBHAL_PROP_EXTRACT_BOOL ("volume.ignore", vol->ignore_volume);
01128
01129 LIBHAL_PROP_EXTRACT_BOOL ("volume.is_disc", vol->is_disc);
01130 LIBHAL_PROP_EXTRACT_STRING ("volume.disc.type", disc_type_textual);
01131 LIBHAL_PROP_EXTRACT_BOOL ("volume.disc.has_audio", vol->disc_has_audio);
01132 LIBHAL_PROP_EXTRACT_BOOL ("volume.disc.has_data", vol->disc_has_data);
01133 LIBHAL_PROP_EXTRACT_BOOL ("volume.disc.is_appendable", vol->disc_is_appendable);
01134 LIBHAL_PROP_EXTRACT_BOOL ("volume.disc.is_blank", vol->disc_is_blank);
01135 LIBHAL_PROP_EXTRACT_BOOL ("volume.disc.is_rewritable", vol->disc_is_rewritable);
01136
01137 LIBHAL_PROP_EXTRACT_BOOL ("volume.policy.should_mount", vol->should_mount);
01138 LIBHAL_PROP_EXTRACT_STRING ("volume.policy.desired_mount_point", vol->desired_mount_point);
01139 LIBHAL_PROP_EXTRACT_STRING ("volume.policy.mount_filesystem", vol->mount_filesystem);
01140
01141 LIBHAL_PROP_EXTRACT_END;
01142 }
01143
01144 if (disc_type_textual != NULL) {
01145 if (strcmp (disc_type_textual, "cd_rom") == 0) {
01146 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_CDROM;
01147 } else if (strcmp (disc_type_textual, "cd_r") == 0) {
01148 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_CDR;
01149 } else if (strcmp (disc_type_textual, "cd_rw") == 0) {
01150 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_CDRW;
01151 } else if (strcmp (disc_type_textual, "dvd_rom") == 0) {
01152 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_DVDROM;
01153 } else if (strcmp (disc_type_textual, "dvd_ram") == 0) {
01154 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_DVDRAM;
01155 } else if (strcmp (disc_type_textual, "dvd_r") == 0) {
01156 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_DVDR;
01157 } else if (strcmp (disc_type_textual, "dvd_rw") == 0) {
01158 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_DVDRW;
01159 } else if (strcmp (disc_type_textual, "dvd_plus_r") == 0) {
01160 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_DVDPLUSR;
01161 } else if (strcmp (disc_type_textual, "dvd_plus_rw") == 0) {
01162 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_DVDPLUSRW;
01163 } else if (strcmp (disc_type_textual, "dvd_plus_r_dl") == 0) {
01164 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_DVDPLUSR_DL;
01165 } else if (strcmp (disc_type_textual, "bd_rom") == 0) {
01166 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_BDROM;
01167 } else if (strcmp (disc_type_textual, "bd_r") == 0) {
01168 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_BDR;
01169 } else if (strcmp (disc_type_textual, "bd_re") == 0) {
01170 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_BDRE;
01171 } else if (strcmp (disc_type_textual, "hddvd_rom") == 0) {
01172 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_HDDVDROM;
01173 } else if (strcmp (disc_type_textual, "hddvd_r") == 0) {
01174 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_HDDVDR;
01175 } else if (strcmp (disc_type_textual, "hddvd_rw") == 0) {
01176 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_HDDVDRW;
01177 }
01178 }
01179
01180 vol->fsusage = LIBHAL_VOLUME_USAGE_UNKNOWN;
01181 if (vol_fsusage_textual != NULL) {
01182 if (strcmp (vol_fsusage_textual, "filesystem") == 0) {
01183 vol->fsusage = LIBHAL_VOLUME_USAGE_MOUNTABLE_FILESYSTEM;
01184 } else if (strcmp (vol_fsusage_textual, "partitiontable") == 0) {
01185 vol->fsusage = LIBHAL_VOLUME_USAGE_PARTITION_TABLE;
01186 } else if (strcmp (vol_fsusage_textual, "raid") == 0) {
01187 vol->fsusage = LIBHAL_VOLUME_USAGE_RAID_MEMBER;
01188 } else if (strcmp (vol_fsusage_textual, "crypto") == 0) {
01189 vol->fsusage = LIBHAL_VOLUME_USAGE_CRYPTO;
01190 } else {
01191 vol->fsusage = LIBHAL_VOLUME_USAGE_UNKNOWN;
01192 }
01193 }
01194
01195 libhal_free_string (vol_fsusage_textual);
01196 libhal_free_string (disc_type_textual);
01197 libhal_free_property_set (properties);
01198 return vol;
01199 error:
01200 libhal_free_string (vol_fsusage_textual);
01201 libhal_free_string (disc_type_textual);
01202 libhal_free_property_set (properties);
01203 libhal_volume_free (vol);
01204 return NULL;
01205 }
01206
01207
01216 int
01217 libhal_volume_get_msdos_part_table_type (LibHalVolume *volume)
01218 {
01219 return volume->msdos_part_table_type;
01220 }
01221
01222
01223
01231 LibHalDrive *
01232 libhal_drive_from_device_file (LibHalContext *hal_ctx, const char *device_file)
01233 {
01234 int i;
01235 char **hal_udis;
01236 int num_hal_udis;
01237 LibHalDrive *result;
01238 char *found_udi;
01239 DBusError error;
01240
01241 LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL);
01242
01243 result = NULL;
01244 found_udi = NULL;
01245
01246 dbus_error_init (&error);
01247 if ((hal_udis = libhal_manager_find_device_string_match (hal_ctx, "block.device",
01248 device_file, &num_hal_udis, &error)) == NULL)
01249 goto out;
01250
01251 for (i = 0; i < num_hal_udis; i++) {
01252 char *udi;
01253 char *storage_udi;
01254 DBusError err1;
01255 DBusError err2;
01256 udi = hal_udis[i];
01257
01258 dbus_error_init (&err1);
01259 dbus_error_init (&err2);
01260 if (libhal_device_query_capability (hal_ctx, udi, "volume", &err1)) {
01261
01262 storage_udi = libhal_device_get_property_string (hal_ctx, udi, "block.storage_device", &err1);
01263 if (storage_udi == NULL)
01264 continue;
01265 found_udi = strdup (storage_udi);
01266 libhal_free_string (storage_udi);
01267 break;
01268 } else if (libhal_device_query_capability (hal_ctx, udi, "storage", &err2)) {
01269 found_udi = strdup (udi);
01270 }
01271 }
01272
01273 libhal_free_string_array (hal_udis);
01274
01275 if (found_udi != NULL)
01276 result = libhal_drive_from_udi (hal_ctx, found_udi);
01277
01278 free (found_udi);
01279 out:
01280 return result;
01281 }
01282
01283
01290 LibHalVolume *
01291 libhal_volume_from_device_file (LibHalContext *hal_ctx, const char *device_file)
01292 {
01293 int i;
01294 char **hal_udis;
01295 int num_hal_udis;
01296 LibHalVolume *result;
01297 char *found_udi;
01298 DBusError error;
01299
01300 LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL);
01301
01302 result = NULL;
01303 found_udi = NULL;
01304
01305 dbus_error_init (&error);
01306 if ((hal_udis = libhal_manager_find_device_string_match (hal_ctx, "block.device",
01307 device_file, &num_hal_udis, &error)) == NULL)
01308 goto out;
01309
01310 for (i = 0; i < num_hal_udis; i++) {
01311 char *udi;
01312 udi = hal_udis[i];
01313 if (libhal_device_query_capability (hal_ctx, udi, "volume", &error)) {
01314 found_udi = strdup (udi);
01315 break;
01316 }
01317 }
01318
01319 libhal_free_string_array (hal_udis);
01320
01321 if (found_udi != NULL)
01322 result = libhal_volume_from_udi (hal_ctx, found_udi);
01323
01324 free (found_udi);
01325 out:
01326 return result;
01327 }
01328
01329 dbus_uint64_t
01330 libhal_volume_get_size (LibHalVolume *volume)
01331 {
01332 return ((dbus_uint64_t)volume->block_size) * ((dbus_uint64_t)volume->num_blocks);
01333 }
01334
01335
01336 dbus_bool_t
01337 libhal_drive_is_hotpluggable (LibHalDrive *drive)
01338 {
01339 return drive->is_hotpluggable;
01340 }
01341
01342 dbus_bool_t
01343 libhal_drive_uses_removable_media (LibHalDrive *drive)
01344 {
01345 return drive->is_removable;
01346 }
01347
01348 LibHalDriveType
01349 libhal_drive_get_type (LibHalDrive *drive)
01350 {
01351 return drive->type;
01352 }
01353
01354 LibHalDriveBus
01355 libhal_drive_get_bus (LibHalDrive *drive)
01356 {
01357 return drive->bus;
01358 }
01359
01360 LibHalDriveCdromCaps
01361 libhal_drive_get_cdrom_caps (LibHalDrive *drive)
01362 {
01363 return drive->cdrom_caps;
01364 }
01365
01366 unsigned int
01367 libhal_drive_get_device_major (LibHalDrive *drive)
01368 {
01369 return drive->device_major;
01370 }
01371
01372 unsigned int
01373 libhal_drive_get_device_minor (LibHalDrive *drive)
01374 {
01375 return drive->device_minor;
01376 }
01377
01378 const char *
01379 libhal_drive_get_type_textual (LibHalDrive *drive)
01380 {
01381 return drive->type_textual;
01382 }
01383
01384 const char *
01385 libhal_drive_get_device_file (LibHalDrive *drive)
01386 {
01387 return drive->device_file;
01388 }
01389
01390 const char *
01391 libhal_drive_get_udi (LibHalDrive *drive)
01392 {
01393 return drive->udi;
01394 }
01395
01396 const char *
01397 libhal_drive_get_serial (LibHalDrive *drive)
01398 {
01399 return drive->serial;
01400 }
01401
01402 const char *
01403 libhal_drive_get_firmware_version (LibHalDrive *drive)
01404 {
01405 return drive->firmware_version;
01406 }
01407
01408 const char *
01409 libhal_drive_get_model (LibHalDrive *drive)
01410 {
01411 return drive->model;
01412 }
01413
01414 const char *
01415 libhal_drive_get_vendor (LibHalDrive *drive)
01416 {
01417 return drive->vendor;
01418 }
01419
01420
01421
01422 const char *
01423 libhal_volume_get_udi (LibHalVolume *volume)
01424 {
01425 return volume->udi;
01426 }
01427
01428 const char *
01429 libhal_volume_get_device_file (LibHalVolume *volume)
01430 {
01431 return volume->device_file;
01432 }
01433
01434 unsigned int libhal_volume_get_device_major (LibHalVolume *volume)
01435 {
01436 return volume->device_major;
01437 }
01438
01439 unsigned int libhal_volume_get_device_minor (LibHalVolume *volume)
01440 {
01441 return volume->device_minor;
01442 }
01443
01444 const char *
01445 libhal_volume_get_fstype (LibHalVolume *volume)
01446 {
01447 return volume->fstype;
01448 }
01449
01450 const char *
01451 libhal_volume_get_fsversion (LibHalVolume *volume)
01452 {
01453 return volume->fsversion;
01454 }
01455
01456 LibHalVolumeUsage
01457 libhal_volume_get_fsusage (LibHalVolume *volume)
01458 {
01459 return volume->fsusage;
01460 }
01461
01462 dbus_bool_t
01463 libhal_volume_is_mounted (LibHalVolume *volume)
01464 {
01465 return volume->is_mounted;
01466 }
01467
01468 dbus_bool_t
01469 libhal_volume_is_mounted_read_only (LibHalVolume *volume)
01470 {
01471 return volume->is_mounted_read_only;
01472 }
01473
01474 dbus_bool_t
01475 libhal_volume_is_partition (LibHalVolume *volume)
01476 {
01477 return volume->is_partition;
01478 }
01479
01480 dbus_bool_t
01481 libhal_volume_is_disc (LibHalVolume *volume)
01482 {
01483 return volume->is_disc;
01484 }
01485
01486 unsigned int
01487 libhal_volume_get_partition_number (LibHalVolume *volume)
01488 {
01489 return volume->partition_number;
01490 }
01491
01492 const char *
01493 libhal_volume_get_label (LibHalVolume *volume)
01494 {
01495 return volume->volume_label;
01496 }
01497
01498 const char *
01499 libhal_volume_get_mount_point (LibHalVolume *volume)
01500 {
01501 return volume->mount_point;
01502 }
01503
01504 const char *
01505 libhal_volume_get_uuid (LibHalVolume *volume)
01506 {
01507 return volume->uuid;
01508 }
01509
01510 dbus_bool_t
01511 libhal_volume_disc_has_audio (LibHalVolume *volume)
01512 {
01513 return volume->disc_has_audio;
01514 }
01515
01516 dbus_bool_t
01517 libhal_volume_disc_has_data (LibHalVolume *volume)
01518 {
01519 return volume->disc_has_data;
01520 }
01521
01522 dbus_bool_t
01523 libhal_volume_disc_is_blank (LibHalVolume *volume)
01524 {
01525 return volume->disc_is_blank;
01526 }
01527
01528 dbus_bool_t
01529 libhal_volume_disc_is_rewritable (LibHalVolume *volume)
01530 {
01531 return volume->disc_is_rewritable;
01532 }
01533
01534 dbus_bool_t
01535 libhal_volume_disc_is_appendable (LibHalVolume *volume)
01536 {
01537 return volume->disc_is_appendable;
01538 }
01539
01540 LibHalVolumeDiscType
01541 libhal_volume_get_disc_type (LibHalVolume *volume)
01542 {
01543 return volume->disc_type;
01544 }
01545
01546 dbus_bool_t
01547 libhal_volume_should_ignore (LibHalVolume *volume)
01548 {
01549 return volume->ignore_volume;
01550 }
01551
01552 char **
01553 libhal_drive_find_all_volumes (LibHalContext *hal_ctx, LibHalDrive *drive, int *num_volumes)
01554 {
01555 int i;
01556 char **udis;
01557 int num_udis;
01558 const char *drive_udi;
01559 char **result;
01560 DBusError error;
01561
01562 LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL);
01563
01564 udis = NULL;
01565 result = NULL;
01566 *num_volumes = 0;
01567
01568 drive_udi = libhal_drive_get_udi (drive);
01569 if (drive_udi == NULL)
01570 goto out;
01571
01572
01573 dbus_error_init (&error);
01574 if ((udis = libhal_manager_find_device_string_match (hal_ctx, "block.storage_device",
01575 drive_udi, &num_udis, &error)) == NULL)
01576 goto out;
01577
01578 result = malloc (sizeof (char *) * num_udis);
01579 if (result == NULL)
01580 goto out;
01581
01582
01583 for (i = 0; i < num_udis; i++) {
01584 if (strcmp (udis[i], drive_udi) == 0)
01585 continue;
01586 result[*num_volumes] = strdup (udis[i]);
01587 *num_volumes = (*num_volumes) + 1;
01588 }
01589
01590 result[*num_volumes] = NULL;
01591
01592 out:
01593 libhal_free_string_array (udis);
01594 return result;
01595 }
01596
01597 const char *
01598 libhal_volume_crypto_get_backing_volume_udi (LibHalVolume *volume)
01599 {
01600 return volume->crypto_backing_volume;
01601 }
01602
01603 char *
01604 libhal_volume_crypto_get_clear_volume_udi (LibHalContext *hal_ctx, LibHalVolume *volume)
01605 {
01606 DBusError error;
01607 char **clear_devices;
01608 int num_clear_devices;
01609 char *result;
01610
01611 result = NULL;
01612
01613 LIBHAL_CHECK_LIBHALCONTEXT (hal_ctx, NULL);
01614
01615 dbus_error_init (&error);
01616 clear_devices = libhal_manager_find_device_string_match (hal_ctx,
01617 "volume.crypto_luks.clear.backing_volume",
01618 volume->udi,
01619 &num_clear_devices,
01620 &error);
01621 if (clear_devices != NULL) {
01622
01623 if (num_clear_devices >= 1) {
01624 result = strdup (clear_devices[0]);
01625 }
01626 libhal_free_string_array (clear_devices);
01627 }
01628
01629 return result;
01630 }
01631
01632
01633
01634
01635 char *
01636 libhal_drive_policy_default_get_mount_root (LibHalContext *hal_ctx)
01637 {
01638 DBusError error;
01639
01640 LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL);
01641
01642 dbus_error_init (&error);
01643 return libhal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer",
01644 "storage.policy.default.mount_root", &error);
01645 }
01646
01647 dbus_bool_t
01648 libhal_drive_policy_default_use_managed_keyword (LibHalContext *hal_ctx)
01649 {
01650 DBusError error;
01651
01652 LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, FALSE);
01653
01654 dbus_error_init (&error);
01655 return libhal_device_get_property_bool (hal_ctx, "/org/freedesktop/Hal/devices/computer",
01656 "storage.policy.default.use_managed_keyword", &error);
01657 }
01658
01659 char *
01660 libhal_drive_policy_default_get_managed_keyword_primary (LibHalContext *hal_ctx)
01661 {
01662 DBusError error;
01663
01664 LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL);
01665
01666 dbus_error_init (&error);
01667 return libhal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer",
01668 "storage.policy.default.managed_keyword.primary", &error);
01669 }
01670
01671 char *
01672 libhal_drive_policy_default_get_managed_keyword_secondary (LibHalContext *hal_ctx)
01673 {
01674 DBusError error;
01675
01676 LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL);
01677
01678 dbus_error_init (&error);
01679 return libhal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer",
01680 "storage.policy.default.managed_keyword.secondary", &error);
01681 }
01682
01683
01684
01685 dbus_bool_t
01686 libhal_drive_policy_is_mountable (LibHalDrive *drive, LibHalStoragePolicy *policy)
01687 {
01688 printf ("should_mount=%d, no_partitions_hint=%d\n", drive->should_mount, drive->no_partitions_hint);
01689
01690 return drive->should_mount && drive->no_partitions_hint;
01691 }
01692
01693 const char *
01694 libhal_drive_policy_get_desired_mount_point (LibHalDrive *drive, LibHalStoragePolicy *policy)
01695 {
01696 return drive->desired_mount_point;
01697 }
01698
01699
01700 #define strcat_len(dst, src, dstmaxlen) do { \
01701 dst[dstmaxlen - 1] = '\0'; \
01702 strncat (dst, src, dstmaxlen - strlen (dst) - 1); \
01703 } while(0)
01704
01705
01706 static void
01707 mopts_collect (LibHalContext *hal_ctx, const char *namespace, int namespace_len,
01708 const char *udi, char *options_string, size_t options_max_len, dbus_bool_t only_collect_imply_opts)
01709 {
01710 LibHalPropertySet *properties;
01711 LibHalPropertySetIterator it;
01712 DBusError error;
01713
01714 if(hal_ctx == 0) {
01715 fprintf (stderr,"%s %d : LibHalContext *ctx is NULL\n",__FILE__, __LINE__);
01716 return;
01717 }
01718
01719 dbus_error_init (&error);
01720
01721
01722 properties = libhal_device_get_all_properties (hal_ctx, udi, &error);
01723 if (properties == NULL)
01724 goto error;
01725 for (libhal_psi_init (&it, properties); libhal_psi_has_more (&it); libhal_psi_next (&it)) {
01726 int type;
01727 char *key;
01728
01729 type = libhal_psi_get_type (&it);
01730 key = libhal_psi_get_key (&it);
01731 if (libhal_psi_get_type (&it) == LIBHAL_PROPERTY_TYPE_BOOLEAN &&
01732 strncmp (key, namespace, namespace_len - 1) == 0) {
01733 const char *option = key + namespace_len - 1;
01734 char *location;
01735 dbus_bool_t is_imply_opt;
01736
01737 is_imply_opt = FALSE;
01738 if (strcmp (option, "user") == 0 ||
01739 strcmp (option, "users") == 0 ||
01740 strcmp (option, "defaults") == 0 ||
01741 strcmp (option, "pamconsole") == 0)
01742 is_imply_opt = TRUE;
01743
01744
01745 if (only_collect_imply_opts) {
01746 if (!is_imply_opt)
01747 continue;
01748 } else {
01749 if (is_imply_opt)
01750 continue;
01751 }
01752
01753 if (libhal_psi_get_bool (&it)) {
01754
01755 location = strstr (options_string, option);
01756 if (location == NULL) {
01757 if (strlen (options_string) > 0)
01758 strcat_len (options_string, ",", options_max_len);
01759 strcat_len (options_string, option, options_max_len);
01760 }
01761 } else {
01762
01763 location = strstr (options_string, option);
01764 if (location != NULL) {
01765 char *end;
01766
01767 end = strchr (location, ',');
01768 if (end == NULL) {
01769 location[0] = '\0';
01770 } else {
01771 strcpy (location, end + 1);
01772 }
01773 }
01774
01775 }
01776 }
01777 }
01778 error:
01779 libhal_free_property_set (properties);
01780 }
01781
01782
01783 const char *
01784 libhal_drive_policy_get_mount_options (LibHalDrive *drive, LibHalStoragePolicy *policy)
01785 {
01786 const char *result;
01787 char stor_mount_option_default_begin[] = "storage.policy.default.mount_option.";
01788 char stor_mount_option_begin[] = "storage.policy.mount_option.";
01789
01790 result = NULL;
01791 drive->mount_options[0] = '\0';
01792
01793
01794 mopts_collect (drive->hal_ctx, stor_mount_option_default_begin, sizeof (stor_mount_option_default_begin),
01795 "/org/freedesktop/Hal/devices/computer", drive->mount_options, MOUNT_OPTIONS_SIZE, TRUE);
01796 mopts_collect (drive->hal_ctx, stor_mount_option_begin, sizeof (stor_mount_option_begin),
01797 drive->udi, drive->mount_options, MOUNT_OPTIONS_SIZE, TRUE);
01798
01799 mopts_collect (drive->hal_ctx, stor_mount_option_default_begin, sizeof (stor_mount_option_default_begin),
01800 "/org/freedesktop/Hal/devices/computer", drive->mount_options, MOUNT_OPTIONS_SIZE, FALSE);
01801 mopts_collect (drive->hal_ctx, stor_mount_option_begin, sizeof (stor_mount_option_begin),
01802 drive->udi, drive->mount_options, MOUNT_OPTIONS_SIZE, FALSE);
01803
01804 result = drive->mount_options;
01805
01806 return result;
01807 }
01808
01809 const char *
01810 libhal_drive_policy_get_mount_fs (LibHalDrive *drive, LibHalStoragePolicy *policy)
01811 {
01812 return drive->mount_filesystem;
01813 }
01814
01815
01816 dbus_bool_t
01817 libhal_volume_policy_is_mountable (LibHalDrive *drive, LibHalVolume *volume, LibHalStoragePolicy *policy)
01818 {
01819 return drive->should_mount && volume->should_mount;
01820 }
01821
01822 const char *libhal_volume_policy_get_desired_mount_point (LibHalDrive *drive, LibHalVolume *volume, LibHalStoragePolicy *policy)
01823 {
01824 return volume->desired_mount_point;
01825 }
01826
01827 const char *libhal_volume_policy_get_mount_options (LibHalDrive *drive, LibHalVolume *volume, LibHalStoragePolicy *policy)
01828 {
01829 const char *result;
01830 char stor_mount_option_default_begin[] = "storage.policy.default.mount_option.";
01831 char vol_mount_option_begin[] = "volume.policy.mount_option.";
01832
01833 result = NULL;
01834 volume->mount_options[0] = '\0';
01835
01836
01837 mopts_collect (drive->hal_ctx, stor_mount_option_default_begin, sizeof (stor_mount_option_default_begin),
01838 "/org/freedesktop/Hal/devices/computer", volume->mount_options, MOUNT_OPTIONS_SIZE, TRUE);
01839 mopts_collect (drive->hal_ctx, vol_mount_option_begin, sizeof (vol_mount_option_begin),
01840 volume->udi, volume->mount_options, MOUNT_OPTIONS_SIZE, TRUE);
01841
01842 mopts_collect (drive->hal_ctx, stor_mount_option_default_begin, sizeof (stor_mount_option_default_begin),
01843 "/org/freedesktop/Hal/devices/computer", volume->mount_options, MOUNT_OPTIONS_SIZE, FALSE);
01844 mopts_collect (drive->hal_ctx, vol_mount_option_begin, sizeof (vol_mount_option_begin),
01845 volume->udi, volume->mount_options, MOUNT_OPTIONS_SIZE, FALSE);
01846
01847 result = volume->mount_options;
01848
01849 return result;
01850 }
01851
01852 const char *libhal_volume_policy_get_mount_fs (LibHalDrive *drive, LibHalVolume *volume, LibHalStoragePolicy *policy)
01853 {
01854 return volume->mount_filesystem;
01855 }
01856
01857 dbus_bool_t
01858 libhal_drive_no_partitions_hint (LibHalDrive *drive)
01859 {
01860 return drive->no_partitions_hint;
01861 }
01862