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 char *mount_point;
00737 char *fstype;
00738 char *fsversion;
00739 char *uuid;
00740 char *storage_device;
00741
00742 LibHalVolumeUsage fsusage;
00743
00744 dbus_bool_t is_partition;
00745 unsigned int partition_number;
00746
00747 int msdos_part_table_type;
00748
00749 dbus_bool_t is_disc;
00750 LibHalVolumeDiscType disc_type;
00751 dbus_bool_t disc_has_audio;
00752 dbus_bool_t disc_has_data;
00753 dbus_bool_t disc_is_appendable;
00754 dbus_bool_t disc_is_blank;
00755 dbus_bool_t disc_is_rewritable;
00756
00757 unsigned int block_size;
00758 unsigned int num_blocks;
00759
00760 char *desired_mount_point;
00761 char *mount_filesystem;
00762 dbus_bool_t should_mount;
00763
00764 dbus_bool_t ignore_volume;
00765
00766 char *crypto_backing_volume;
00767
00768 char mount_options[MOUNT_OPTIONS_SIZE];
00769
00770 dbus_uint64_t volume_size;
00771 dbus_uint64_t disc_capacity;
00772 };
00773
00774 const char *
00775 libhal_drive_get_dedicated_icon_drive (LibHalDrive *drive)
00776 {
00777 return drive->dedicated_icon_drive;
00778 }
00779
00780 const char *
00781 libhal_drive_get_dedicated_icon_volume (LibHalDrive *drive)
00782 {
00783 return drive->dedicated_icon_volume;
00784 }
00785
00790 void
00791 libhal_drive_free (LibHalDrive *drive)
00792 {
00793 if (drive == NULL )
00794 return;
00795
00796 free (drive->udi);
00797 libhal_free_string (drive->device_file);
00798 libhal_free_string (drive->vendor);
00799 libhal_free_string (drive->model);
00800 libhal_free_string (drive->type_textual);
00801 libhal_free_string (drive->physical_device);
00802 libhal_free_string (drive->serial);
00803 libhal_free_string (drive->firmware_version);
00804 libhal_free_string (drive->desired_mount_point);
00805 libhal_free_string (drive->mount_filesystem);
00806 libhal_free_string_array (drive->capabilities);
00807
00808 free (drive);
00809 }
00810
00811
00816 void
00817 libhal_volume_free (LibHalVolume *vol)
00818 {
00819 if (vol == NULL )
00820 return;
00821
00822 free (vol->udi);
00823 libhal_free_string (vol->device_file);
00824 libhal_free_string (vol->volume_label);
00825 libhal_free_string (vol->fstype);
00826 libhal_free_string (vol->mount_point);
00827 libhal_free_string (vol->fsversion);
00828 libhal_free_string (vol->uuid);
00829 libhal_free_string (vol->desired_mount_point);
00830 libhal_free_string (vol->mount_filesystem);
00831 libhal_free_string (vol->crypto_backing_volume);
00832
00833 free (vol);
00834 }
00835
00836
00837 static char **
00838 my_strvdup (char **strv)
00839 {
00840 unsigned int num_elems;
00841 unsigned int i;
00842 char **res;
00843
00844 for (num_elems = 0; strv[num_elems] != NULL; num_elems++)
00845 ;
00846
00847 res = calloc (num_elems + 1, sizeof (char*));
00848 if (res == NULL)
00849 goto out;
00850
00851 for (i = 0; i < num_elems; i++)
00852 res[i] = strdup (strv[i]);
00853 res[i] = NULL;
00854
00855 out:
00856 return res;
00857 }
00858
00859
00860
00861 #define LIBHAL_PROP_EXTRACT_BEGIN if (FALSE)
00862 #define LIBHAL_PROP_EXTRACT_END ;
00863 #define LIBHAL_PROP_EXTRACT_INT(_property_, _where_) else if (strcmp (key, _property_) == 0 && type == LIBHAL_PROPERTY_TYPE_INT32) _where_ = libhal_psi_get_int (&it)
00864 #define LIBHAL_PROP_EXTRACT_UINT64(_property_, _where_) else if (strcmp (key, _property_) == 0 && type == LIBHAL_PROPERTY_TYPE_UINT64) _where_ = libhal_psi_get_uint64 (&it)
00865 #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
00866 #define LIBHAL_PROP_EXTRACT_BOOL(_property_, _where_) else if (strcmp (key, _property_) == 0 && type == LIBHAL_PROPERTY_TYPE_BOOLEAN) _where_ = libhal_psi_get_bool (&it)
00867 #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
00868 #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))
00869
00878 LibHalDrive *
00879 libhal_drive_from_udi (LibHalContext *hal_ctx, const char *udi)
00880 {
00881 char *bus_textual;
00882 LibHalDrive *drive;
00883 LibHalPropertySet *properties;
00884 LibHalPropertySetIterator it;
00885 DBusError error;
00886 unsigned int i;
00887
00888 LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL);
00889
00890 drive = NULL;
00891 properties = NULL;
00892 bus_textual = NULL;
00893
00894 dbus_error_init (&error);
00895 if (!libhal_device_query_capability (hal_ctx, udi, "storage", &error))
00896 goto error;
00897
00898 drive = malloc (sizeof (LibHalDrive));
00899 if (drive == NULL)
00900 goto error;
00901 memset (drive, 0x00, sizeof (LibHalDrive));
00902
00903 drive->hal_ctx = hal_ctx;
00904
00905 drive->udi = strdup (udi);
00906 if (drive->udi == NULL)
00907 goto error;
00908
00909 properties = libhal_device_get_all_properties (hal_ctx, udi, &error);
00910 if (properties == NULL)
00911 goto error;
00912
00913
00914 for (libhal_psi_init (&it, properties); libhal_psi_has_more (&it); libhal_psi_next (&it)) {
00915 int type;
00916 char *key;
00917
00918 type = libhal_psi_get_type (&it);
00919 key = libhal_psi_get_key (&it);
00920
00921 LIBHAL_PROP_EXTRACT_BEGIN;
00922
00923 LIBHAL_PROP_EXTRACT_INT ("block.minor", drive->device_minor);
00924 LIBHAL_PROP_EXTRACT_INT ("block.major", drive->device_major);
00925 LIBHAL_PROP_EXTRACT_STRING ("block.device", drive->device_file);
00926 LIBHAL_PROP_EXTRACT_STRING ("storage.bus", bus_textual);
00927 LIBHAL_PROP_EXTRACT_STRING ("storage.vendor", drive->vendor);
00928 LIBHAL_PROP_EXTRACT_STRING ("storage.model", drive->model);
00929 LIBHAL_PROP_EXTRACT_STRING ("storage.drive_type", drive->type_textual);
00930
00931
00932 LIBHAL_PROP_EXTRACT_STRING ("storage.icon.drive", drive->dedicated_icon_drive);
00933 LIBHAL_PROP_EXTRACT_STRING ("storage.icon.volume", drive->dedicated_icon_volume);
00934
00935 LIBHAL_PROP_EXTRACT_BOOL ("storage.hotpluggable", drive->is_hotpluggable);
00936 LIBHAL_PROP_EXTRACT_BOOL ("storage.removable", drive->is_removable);
00937 LIBHAL_PROP_EXTRACT_BOOL ("storage.requires_eject", drive->requires_eject);
00938
00939 LIBHAL_PROP_EXTRACT_STRING ("storage.physical_device", drive->physical_device);
00940 LIBHAL_PROP_EXTRACT_STRING ("storage.firmware_version", drive->firmware_version);
00941 LIBHAL_PROP_EXTRACT_STRING ("storage.serial", drive->serial);
00942
00943 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.cdr", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_CDR);
00944 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.cdrw", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_CDRW);
00945 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvd", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_DVDROM);
00946 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdplusr", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSR);
00947 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdplusrw", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSRW);
00948 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdplusrdl", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_DVDPLUSRDL);
00949 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdr", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_DVDR);
00950 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdrw", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_DVDRW);
00951 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdram", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_DVDRAM);
00952 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.bd", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_BDROM);
00953 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.bdr", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_BDR);
00954 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.bdre", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_BDRE);
00955 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.hddvd", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_HDDVDROM);
00956 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.hddvdr", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_HDDVDR);
00957 LIBHAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.hddvdrw", drive->cdrom_caps, LIBHAL_DRIVE_CDROM_CAPS_HDDVDRW);
00958
00959 LIBHAL_PROP_EXTRACT_BOOL ("storage.policy.should_mount", drive->should_mount);
00960 LIBHAL_PROP_EXTRACT_STRING ("storage.policy.desired_mount_point", drive->desired_mount_point);
00961 LIBHAL_PROP_EXTRACT_STRING ("storage.policy.mount_filesystem", drive->mount_filesystem);
00962
00963 LIBHAL_PROP_EXTRACT_BOOL ("storage.no_partitions_hint", drive->no_partitions_hint);
00964
00965 LIBHAL_PROP_EXTRACT_STRLIST ("info.capabilities", drive->capabilities);
00966
00967 LIBHAL_PROP_EXTRACT_END;
00968 }
00969
00970 if (drive->type_textual != NULL) {
00971 if (strcmp (drive->type_textual, "cdrom") == 0) {
00972 drive->cdrom_caps |= LIBHAL_DRIVE_CDROM_CAPS_CDROM;
00973 drive->type = LIBHAL_DRIVE_TYPE_CDROM;
00974 } else if (strcmp (drive->type_textual, "floppy") == 0) {
00975 drive->type = LIBHAL_DRIVE_TYPE_FLOPPY;
00976 } else if (strcmp (drive->type_textual, "disk") == 0) {
00977 if (drive->is_removable)
00978 drive->type = LIBHAL_DRIVE_TYPE_REMOVABLE_DISK;
00979 else
00980 drive->type = LIBHAL_DRIVE_TYPE_DISK;
00981 } else if (strcmp (drive->type_textual, "tape") == 0) {
00982 drive->type = LIBHAL_DRIVE_TYPE_TAPE;
00983 } else if (strcmp (drive->type_textual, "compact_flash") == 0) {
00984 drive->type = LIBHAL_DRIVE_TYPE_COMPACT_FLASH;
00985 } else if (strcmp (drive->type_textual, "memory_stick") == 0) {
00986 drive->type = LIBHAL_DRIVE_TYPE_MEMORY_STICK;
00987 } else if (strcmp (drive->type_textual, "smart_media") == 0) {
00988 drive->type = LIBHAL_DRIVE_TYPE_SMART_MEDIA;
00989 } else if (strcmp (drive->type_textual, "sd_mmc") == 0) {
00990 drive->type = LIBHAL_DRIVE_TYPE_SD_MMC;
00991 } else if (strcmp (drive->type_textual, "zip") == 0) {
00992 drive->type = LIBHAL_DRIVE_TYPE_ZIP;
00993 } else if (strcmp (drive->type_textual, "jaz") == 0) {
00994 drive->type = LIBHAL_DRIVE_TYPE_JAZ;
00995 } else if (strcmp (drive->type_textual, "flashkey") == 0) {
00996 drive->type = LIBHAL_DRIVE_TYPE_FLASHKEY;
00997 } else {
00998 drive->type = LIBHAL_DRIVE_TYPE_DISK;
00999 }
01000
01001 }
01002
01003 if (drive->capabilities != NULL) {
01004 for (i = 0; drive->capabilities[i] != NULL; i++) {
01005 if (strcmp (drive->capabilities[i], "portable_audio_player") == 0) {
01006 drive->type = LIBHAL_DRIVE_TYPE_PORTABLE_AUDIO_PLAYER;
01007 break;
01008 } else if (strcmp (drive->capabilities[i], "camera") == 0) {
01009 drive->type = LIBHAL_DRIVE_TYPE_CAMERA;
01010 break;
01011 }
01012 }
01013 }
01014
01015 if (bus_textual != NULL) {
01016 if (strcmp (bus_textual, "usb") == 0) {
01017 drive->bus = LIBHAL_DRIVE_BUS_USB;
01018 } else if (strcmp (bus_textual, "ieee1394") == 0) {
01019 drive->bus = LIBHAL_DRIVE_BUS_IEEE1394;
01020 } else if (strcmp (bus_textual, "ide") == 0) {
01021 drive->bus = LIBHAL_DRIVE_BUS_IDE;
01022 } else if (strcmp (bus_textual, "scsi") == 0) {
01023 drive->bus = LIBHAL_DRIVE_BUS_SCSI;
01024 } else if (strcmp (bus_textual, "ccw") == 0) {
01025 drive->bus = LIBHAL_DRIVE_BUS_CCW;
01026 }
01027 }
01028
01029 libhal_free_string (bus_textual);
01030 libhal_free_property_set (properties);
01031
01032 return drive;
01033
01034 error:
01035 libhal_free_string (bus_textual);
01036 libhal_free_property_set (properties);
01037 libhal_drive_free (drive);
01038 return NULL;
01039 }
01040
01041 const char *
01042 libhal_volume_get_storage_device_udi (LibHalVolume *volume)
01043 {
01044 return volume->storage_device;
01045 }
01046
01047 const char *libhal_drive_get_physical_device_udi (LibHalDrive *drive)
01048 {
01049 return drive->physical_device;
01050 }
01051
01052 dbus_bool_t
01053 libhal_drive_requires_eject (LibHalDrive *drive)
01054 {
01055 return drive->requires_eject;
01056 }
01057
01066 LibHalVolume *
01067 libhal_volume_from_udi (LibHalContext *hal_ctx, const char *udi)
01068 {
01069 char *disc_type_textual;
01070 char *vol_fsusage_textual;
01071 LibHalVolume *vol;
01072 LibHalPropertySet *properties;
01073 LibHalPropertySetIterator it;
01074 DBusError error;
01075
01076 LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL);
01077
01078 vol = NULL;
01079 properties = NULL;
01080 disc_type_textual = NULL;
01081 vol_fsusage_textual = NULL;
01082
01083 dbus_error_init (&error);
01084 if (!libhal_device_query_capability (hal_ctx, udi, "volume", &error))
01085 goto error;
01086
01087 vol = malloc (sizeof (LibHalVolume));
01088 if (vol == NULL)
01089 goto error;
01090 memset (vol, 0x00, sizeof (LibHalVolume));
01091
01092 vol->udi = strdup (udi);
01093
01094 properties = libhal_device_get_all_properties (hal_ctx, udi, &error);
01095 if (properties == NULL)
01096 goto error;
01097
01098
01099 for (libhal_psi_init (&it, properties); libhal_psi_has_more (&it); libhal_psi_next (&it)) {
01100 int type;
01101 char *key;
01102
01103 type = libhal_psi_get_type (&it);
01104 key = libhal_psi_get_key (&it);
01105
01106 LIBHAL_PROP_EXTRACT_BEGIN;
01107
01108 LIBHAL_PROP_EXTRACT_INT ("volume.partition.msdos_part_table_type", vol->msdos_part_table_type);
01109
01110 LIBHAL_PROP_EXTRACT_INT ("block.minor", vol->device_minor);
01111 LIBHAL_PROP_EXTRACT_INT ("block.major", vol->device_major);
01112 LIBHAL_PROP_EXTRACT_STRING ("block.device", vol->device_file);
01113
01114 LIBHAL_PROP_EXTRACT_STRING ("block.storage_device", vol->storage_device);
01115
01116 LIBHAL_PROP_EXTRACT_STRING ("volume.crypto_luks.clear.backing_volume", vol->crypto_backing_volume);
01117
01118 LIBHAL_PROP_EXTRACT_INT ("volume.block_size", vol->block_size);
01119 LIBHAL_PROP_EXTRACT_INT ("volume.num_blocks", vol->num_blocks);
01120 LIBHAL_PROP_EXTRACT_UINT64 ("volume.size", vol->volume_size);
01121 LIBHAL_PROP_EXTRACT_STRING ("volume.label", vol->volume_label);
01122 LIBHAL_PROP_EXTRACT_STRING ("volume.mount_point", vol->mount_point);
01123 LIBHAL_PROP_EXTRACT_STRING ("volume.fstype", vol->fstype);
01124 LIBHAL_PROP_EXTRACT_STRING ("volume.fsversion", vol->fsversion);
01125 LIBHAL_PROP_EXTRACT_BOOL ("volume.is_mounted", vol->is_mounted);
01126 LIBHAL_PROP_EXTRACT_STRING ("volume.fsusage", vol_fsusage_textual);
01127 LIBHAL_PROP_EXTRACT_STRING ("volume.uuid", vol->uuid);
01128
01129 LIBHAL_PROP_EXTRACT_BOOL ("volume.ignore", vol->ignore_volume);
01130
01131 LIBHAL_PROP_EXTRACT_BOOL ("volume.is_disc", vol->is_disc);
01132 LIBHAL_PROP_EXTRACT_STRING ("volume.disc.type", disc_type_textual);
01133 LIBHAL_PROP_EXTRACT_BOOL ("volume.disc.has_audio", vol->disc_has_audio);
01134 LIBHAL_PROP_EXTRACT_BOOL ("volume.disc.has_data", vol->disc_has_data);
01135 LIBHAL_PROP_EXTRACT_BOOL ("volume.disc.is_appendable", vol->disc_is_appendable);
01136 LIBHAL_PROP_EXTRACT_BOOL ("volume.disc.is_blank", vol->disc_is_blank);
01137 LIBHAL_PROP_EXTRACT_BOOL ("volume.disc.is_rewritable", vol->disc_is_rewritable);
01138 LIBHAL_PROP_EXTRACT_UINT64 ("volume.disc.capacity", vol->disc_capacity);
01139
01140 LIBHAL_PROP_EXTRACT_BOOL ("volume.policy.should_mount", vol->should_mount);
01141 LIBHAL_PROP_EXTRACT_STRING ("volume.policy.desired_mount_point", vol->desired_mount_point);
01142 LIBHAL_PROP_EXTRACT_STRING ("volume.policy.mount_filesystem", vol->mount_filesystem);
01143
01144 LIBHAL_PROP_EXTRACT_END;
01145 }
01146
01147 if (disc_type_textual != NULL) {
01148 if (strcmp (disc_type_textual, "cd_rom") == 0) {
01149 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_CDROM;
01150 } else if (strcmp (disc_type_textual, "cd_r") == 0) {
01151 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_CDR;
01152 } else if (strcmp (disc_type_textual, "cd_rw") == 0) {
01153 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_CDRW;
01154 } else if (strcmp (disc_type_textual, "dvd_rom") == 0) {
01155 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_DVDROM;
01156 } else if (strcmp (disc_type_textual, "dvd_ram") == 0) {
01157 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_DVDRAM;
01158 } else if (strcmp (disc_type_textual, "dvd_r") == 0) {
01159 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_DVDR;
01160 } else if (strcmp (disc_type_textual, "dvd_rw") == 0) {
01161 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_DVDRW;
01162 } else if (strcmp (disc_type_textual, "dvd_plus_r") == 0) {
01163 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_DVDPLUSR;
01164 } else if (strcmp (disc_type_textual, "dvd_plus_rw") == 0) {
01165 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_DVDPLUSRW;
01166 } else if (strcmp (disc_type_textual, "dvd_plus_r_dl") == 0) {
01167 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_DVDPLUSR_DL;
01168 } else if (strcmp (disc_type_textual, "bd_rom") == 0) {
01169 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_BDROM;
01170 } else if (strcmp (disc_type_textual, "bd_r") == 0) {
01171 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_BDR;
01172 } else if (strcmp (disc_type_textual, "bd_re") == 0) {
01173 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_BDRE;
01174 } else if (strcmp (disc_type_textual, "hddvd_rom") == 0) {
01175 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_HDDVDROM;
01176 } else if (strcmp (disc_type_textual, "hddvd_r") == 0) {
01177 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_HDDVDR;
01178 } else if (strcmp (disc_type_textual, "hddvd_rw") == 0) {
01179 vol->disc_type = LIBHAL_VOLUME_DISC_TYPE_HDDVDRW;
01180 }
01181 }
01182
01183 vol->fsusage = LIBHAL_VOLUME_USAGE_UNKNOWN;
01184 if (vol_fsusage_textual != NULL) {
01185 if (strcmp (vol_fsusage_textual, "filesystem") == 0) {
01186 vol->fsusage = LIBHAL_VOLUME_USAGE_MOUNTABLE_FILESYSTEM;
01187 } else if (strcmp (vol_fsusage_textual, "partitiontable") == 0) {
01188 vol->fsusage = LIBHAL_VOLUME_USAGE_PARTITION_TABLE;
01189 } else if (strcmp (vol_fsusage_textual, "raid") == 0) {
01190 vol->fsusage = LIBHAL_VOLUME_USAGE_RAID_MEMBER;
01191 } else if (strcmp (vol_fsusage_textual, "crypto") == 0) {
01192 vol->fsusage = LIBHAL_VOLUME_USAGE_CRYPTO;
01193 } else {
01194 vol->fsusage = LIBHAL_VOLUME_USAGE_UNKNOWN;
01195 }
01196 }
01197
01198 libhal_free_string (vol_fsusage_textual);
01199 libhal_free_string (disc_type_textual);
01200 libhal_free_property_set (properties);
01201 return vol;
01202 error:
01203 libhal_free_string (vol_fsusage_textual);
01204 libhal_free_string (disc_type_textual);
01205 libhal_free_property_set (properties);
01206 libhal_volume_free (vol);
01207 return NULL;
01208 }
01209
01210
01219 int
01220 libhal_volume_get_msdos_part_table_type (LibHalVolume *volume)
01221 {
01222 return volume->msdos_part_table_type;
01223 }
01224
01225
01226
01234 LibHalDrive *
01235 libhal_drive_from_device_file (LibHalContext *hal_ctx, const char *device_file)
01236 {
01237 int i;
01238 char **hal_udis;
01239 int num_hal_udis;
01240 LibHalDrive *result;
01241 char *found_udi;
01242 DBusError error;
01243
01244 LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL);
01245
01246 result = NULL;
01247 found_udi = NULL;
01248
01249 dbus_error_init (&error);
01250 if ((hal_udis = libhal_manager_find_device_string_match (hal_ctx, "block.device",
01251 device_file, &num_hal_udis, &error)) == NULL)
01252 goto out;
01253
01254 for (i = 0; i < num_hal_udis; i++) {
01255 char *udi;
01256 char *storage_udi;
01257 DBusError err1;
01258 DBusError err2;
01259 udi = hal_udis[i];
01260
01261 dbus_error_init (&err1);
01262 dbus_error_init (&err2);
01263 if (libhal_device_query_capability (hal_ctx, udi, "volume", &err1)) {
01264
01265 storage_udi = libhal_device_get_property_string (hal_ctx, udi, "block.storage_device", &err1);
01266 if (storage_udi == NULL)
01267 continue;
01268 found_udi = strdup (storage_udi);
01269 libhal_free_string (storage_udi);
01270 break;
01271 } else if (libhal_device_query_capability (hal_ctx, udi, "storage", &err2)) {
01272 found_udi = strdup (udi);
01273 }
01274 }
01275
01276 libhal_free_string_array (hal_udis);
01277
01278 if (found_udi != NULL)
01279 result = libhal_drive_from_udi (hal_ctx, found_udi);
01280
01281 free (found_udi);
01282 out:
01283 return result;
01284 }
01285
01286
01293 LibHalVolume *
01294 libhal_volume_from_device_file (LibHalContext *hal_ctx, const char *device_file)
01295 {
01296 int i;
01297 char **hal_udis;
01298 int num_hal_udis;
01299 LibHalVolume *result;
01300 char *found_udi;
01301 DBusError error;
01302
01303 LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL);
01304
01305 result = NULL;
01306 found_udi = NULL;
01307
01308 dbus_error_init (&error);
01309 if ((hal_udis = libhal_manager_find_device_string_match (hal_ctx, "block.device",
01310 device_file, &num_hal_udis, &error)) == NULL)
01311 goto out;
01312
01313 for (i = 0; i < num_hal_udis; i++) {
01314 char *udi;
01315 udi = hal_udis[i];
01316 if (libhal_device_query_capability (hal_ctx, udi, "volume", &error)) {
01317 found_udi = strdup (udi);
01318 break;
01319 }
01320 }
01321
01322 libhal_free_string_array (hal_udis);
01323
01324 if (found_udi != NULL)
01325 result = libhal_volume_from_udi (hal_ctx, found_udi);
01326
01327 free (found_udi);
01328 out:
01329 return result;
01330 }
01331
01332 dbus_uint64_t
01333 libhal_volume_get_size (LibHalVolume *volume)
01334 {
01335 if (volume->volume_size > 0)
01336 return volume->volume_size;
01337 else
01338 return ((dbus_uint64_t)volume->block_size) * ((dbus_uint64_t)volume->num_blocks);
01339 }
01340
01341 dbus_uint64_t
01342 libhal_volume_get_disc_capacity (LibHalVolume *volume)
01343 {
01344 return volume->disc_capacity;
01345 }
01346
01347
01348 dbus_bool_t
01349 libhal_drive_is_hotpluggable (LibHalDrive *drive)
01350 {
01351 return drive->is_hotpluggable;
01352 }
01353
01354 dbus_bool_t
01355 libhal_drive_uses_removable_media (LibHalDrive *drive)
01356 {
01357 return drive->is_removable;
01358 }
01359
01360 LibHalDriveType
01361 libhal_drive_get_type (LibHalDrive *drive)
01362 {
01363 return drive->type;
01364 }
01365
01366 LibHalDriveBus
01367 libhal_drive_get_bus (LibHalDrive *drive)
01368 {
01369 return drive->bus;
01370 }
01371
01372 LibHalDriveCdromCaps
01373 libhal_drive_get_cdrom_caps (LibHalDrive *drive)
01374 {
01375 return drive->cdrom_caps;
01376 }
01377
01378 unsigned int
01379 libhal_drive_get_device_major (LibHalDrive *drive)
01380 {
01381 return drive->device_major;
01382 }
01383
01384 unsigned int
01385 libhal_drive_get_device_minor (LibHalDrive *drive)
01386 {
01387 return drive->device_minor;
01388 }
01389
01390 const char *
01391 libhal_drive_get_type_textual (LibHalDrive *drive)
01392 {
01393 return drive->type_textual;
01394 }
01395
01396 const char *
01397 libhal_drive_get_device_file (LibHalDrive *drive)
01398 {
01399 return drive->device_file;
01400 }
01401
01402 const char *
01403 libhal_drive_get_udi (LibHalDrive *drive)
01404 {
01405 return drive->udi;
01406 }
01407
01408 const char *
01409 libhal_drive_get_serial (LibHalDrive *drive)
01410 {
01411 return drive->serial;
01412 }
01413
01414 const char *
01415 libhal_drive_get_firmware_version (LibHalDrive *drive)
01416 {
01417 return drive->firmware_version;
01418 }
01419
01420 const char *
01421 libhal_drive_get_model (LibHalDrive *drive)
01422 {
01423 return drive->model;
01424 }
01425
01426 const char *
01427 libhal_drive_get_vendor (LibHalDrive *drive)
01428 {
01429 return drive->vendor;
01430 }
01431
01432
01433
01434 const char *
01435 libhal_volume_get_udi (LibHalVolume *volume)
01436 {
01437 return volume->udi;
01438 }
01439
01440 const char *
01441 libhal_volume_get_device_file (LibHalVolume *volume)
01442 {
01443 return volume->device_file;
01444 }
01445
01446 unsigned int libhal_volume_get_device_major (LibHalVolume *volume)
01447 {
01448 return volume->device_major;
01449 }
01450
01451 unsigned int libhal_volume_get_device_minor (LibHalVolume *volume)
01452 {
01453 return volume->device_minor;
01454 }
01455
01456 const char *
01457 libhal_volume_get_fstype (LibHalVolume *volume)
01458 {
01459 return volume->fstype;
01460 }
01461
01462 const char *
01463 libhal_volume_get_fsversion (LibHalVolume *volume)
01464 {
01465 return volume->fsversion;
01466 }
01467
01468 LibHalVolumeUsage
01469 libhal_volume_get_fsusage (LibHalVolume *volume)
01470 {
01471 return volume->fsusage;
01472 }
01473
01474 dbus_bool_t
01475 libhal_volume_is_mounted (LibHalVolume *volume)
01476 {
01477 return volume->is_mounted;
01478 }
01479
01480 dbus_bool_t
01481 libhal_volume_is_partition (LibHalVolume *volume)
01482 {
01483 return volume->is_partition;
01484 }
01485
01486 dbus_bool_t
01487 libhal_volume_is_disc (LibHalVolume *volume)
01488 {
01489 return volume->is_disc;
01490 }
01491
01492 unsigned int
01493 libhal_volume_get_partition_number (LibHalVolume *volume)
01494 {
01495 return volume->partition_number;
01496 }
01497
01498 const char *
01499 libhal_volume_get_label (LibHalVolume *volume)
01500 {
01501 return volume->volume_label;
01502 }
01503
01504 const char *
01505 libhal_volume_get_mount_point (LibHalVolume *volume)
01506 {
01507 return volume->mount_point;
01508 }
01509
01510 const char *
01511 libhal_volume_get_uuid (LibHalVolume *volume)
01512 {
01513 return volume->uuid;
01514 }
01515
01516 dbus_bool_t
01517 libhal_volume_disc_has_audio (LibHalVolume *volume)
01518 {
01519 return volume->disc_has_audio;
01520 }
01521
01522 dbus_bool_t
01523 libhal_volume_disc_has_data (LibHalVolume *volume)
01524 {
01525 return volume->disc_has_data;
01526 }
01527
01528 dbus_bool_t
01529 libhal_volume_disc_is_blank (LibHalVolume *volume)
01530 {
01531 return volume->disc_is_blank;
01532 }
01533
01534 dbus_bool_t
01535 libhal_volume_disc_is_rewritable (LibHalVolume *volume)
01536 {
01537 return volume->disc_is_rewritable;
01538 }
01539
01540 dbus_bool_t
01541 libhal_volume_disc_is_appendable (LibHalVolume *volume)
01542 {
01543 return volume->disc_is_appendable;
01544 }
01545
01546 LibHalVolumeDiscType
01547 libhal_volume_get_disc_type (LibHalVolume *volume)
01548 {
01549 return volume->disc_type;
01550 }
01551
01552 dbus_bool_t
01553 libhal_volume_should_ignore (LibHalVolume *volume)
01554 {
01555 return volume->ignore_volume;
01556 }
01557
01558 char **
01559 libhal_drive_find_all_volumes (LibHalContext *hal_ctx, LibHalDrive *drive, int *num_volumes)
01560 {
01561 int i;
01562 char **udis;
01563 int num_udis;
01564 const char *drive_udi;
01565 char **result;
01566 DBusError error;
01567
01568 LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL);
01569
01570 udis = NULL;
01571 result = NULL;
01572 *num_volumes = 0;
01573
01574 drive_udi = libhal_drive_get_udi (drive);
01575 if (drive_udi == NULL)
01576 goto out;
01577
01578
01579 dbus_error_init (&error);
01580 if ((udis = libhal_manager_find_device_string_match (hal_ctx, "block.storage_device",
01581 drive_udi, &num_udis, &error)) == NULL)
01582 goto out;
01583
01584 result = malloc (sizeof (char *) * num_udis);
01585 if (result == NULL)
01586 goto out;
01587
01588
01589 for (i = 0; i < num_udis; i++) {
01590 if (strcmp (udis[i], drive_udi) == 0)
01591 continue;
01592 result[*num_volumes] = strdup (udis[i]);
01593 *num_volumes = (*num_volumes) + 1;
01594 }
01595
01596 result[*num_volumes] = NULL;
01597
01598 out:
01599 libhal_free_string_array (udis);
01600 return result;
01601 }
01602
01603 const char *
01604 libhal_volume_crypto_get_backing_volume_udi (LibHalVolume *volume)
01605 {
01606 return volume->crypto_backing_volume;
01607 }
01608
01609 char *
01610 libhal_volume_crypto_get_clear_volume_udi (LibHalContext *hal_ctx, LibHalVolume *volume)
01611 {
01612 DBusError error;
01613 char **clear_devices;
01614 int num_clear_devices;
01615 char *result;
01616
01617 result = NULL;
01618
01619 LIBHAL_CHECK_LIBHALCONTEXT (hal_ctx, NULL);
01620
01621 dbus_error_init (&error);
01622 clear_devices = libhal_manager_find_device_string_match (hal_ctx,
01623 "volume.crypto_luks.clear.backing_volume",
01624 volume->udi,
01625 &num_clear_devices,
01626 &error);
01627 if (clear_devices != NULL) {
01628
01629 if (num_clear_devices >= 1) {
01630 result = strdup (clear_devices[0]);
01631 }
01632 libhal_free_string_array (clear_devices);
01633 }
01634
01635 return result;
01636 }
01637
01638
01639
01640
01641 char *
01642 libhal_drive_policy_default_get_mount_root (LibHalContext *hal_ctx)
01643 {
01644 DBusError error;
01645
01646 LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL);
01647
01648 dbus_error_init (&error);
01649 return libhal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer",
01650 "storage.policy.default.mount_root", &error);
01651 }
01652
01653 dbus_bool_t
01654 libhal_drive_policy_default_use_managed_keyword (LibHalContext *hal_ctx)
01655 {
01656 DBusError error;
01657
01658 LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, FALSE);
01659
01660 dbus_error_init (&error);
01661 return libhal_device_get_property_bool (hal_ctx, "/org/freedesktop/Hal/devices/computer",
01662 "storage.policy.default.use_managed_keyword", &error);
01663 }
01664
01665 char *
01666 libhal_drive_policy_default_get_managed_keyword_primary (LibHalContext *hal_ctx)
01667 {
01668 DBusError error;
01669
01670 LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL);
01671
01672 dbus_error_init (&error);
01673 return libhal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer",
01674 "storage.policy.default.managed_keyword.primary", &error);
01675 }
01676
01677 char *
01678 libhal_drive_policy_default_get_managed_keyword_secondary (LibHalContext *hal_ctx)
01679 {
01680 DBusError error;
01681
01682 LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL);
01683
01684 dbus_error_init (&error);
01685 return libhal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer",
01686 "storage.policy.default.managed_keyword.secondary", &error);
01687 }
01688
01689
01690
01691 dbus_bool_t
01692 libhal_drive_policy_is_mountable (LibHalDrive *drive, LibHalStoragePolicy *policy)
01693 {
01694 printf ("should_mount=%d, no_partitions_hint=%d\n", drive->should_mount, drive->no_partitions_hint);
01695
01696 return drive->should_mount && drive->no_partitions_hint;
01697 }
01698
01699 const char *
01700 libhal_drive_policy_get_desired_mount_point (LibHalDrive *drive, LibHalStoragePolicy *policy)
01701 {
01702 return drive->desired_mount_point;
01703 }
01704
01705
01706 #define strcat_len(dst, src, dstmaxlen) do { \
01707 dst[dstmaxlen - 1] = '\0'; \
01708 strncat (dst, src, dstmaxlen - strlen (dst) - 1); \
01709 } while(0)
01710
01711
01712 static void
01713 mopts_collect (LibHalContext *hal_ctx, const char *namespace, int namespace_len,
01714 const char *udi, char *options_string, size_t options_max_len, dbus_bool_t only_collect_imply_opts)
01715 {
01716 LibHalPropertySet *properties;
01717 LibHalPropertySetIterator it;
01718 DBusError error;
01719
01720 if(hal_ctx == 0) {
01721 fprintf (stderr,"%s %d : LibHalContext *ctx is NULL\n",__FILE__, __LINE__);
01722 return;
01723 }
01724
01725 dbus_error_init (&error);
01726
01727
01728 properties = libhal_device_get_all_properties (hal_ctx, udi, &error);
01729 if (properties == NULL)
01730 goto error;
01731 for (libhal_psi_init (&it, properties); libhal_psi_has_more (&it); libhal_psi_next (&it)) {
01732 int type;
01733 char *key;
01734
01735 type = libhal_psi_get_type (&it);
01736 key = libhal_psi_get_key (&it);
01737 if (libhal_psi_get_type (&it) == LIBHAL_PROPERTY_TYPE_BOOLEAN &&
01738 strncmp (key, namespace, namespace_len - 1) == 0) {
01739 const char *option = key + namespace_len - 1;
01740 char *location;
01741 dbus_bool_t is_imply_opt;
01742
01743 is_imply_opt = FALSE;
01744 if (strcmp (option, "user") == 0 ||
01745 strcmp (option, "users") == 0 ||
01746 strcmp (option, "defaults") == 0 ||
01747 strcmp (option, "pamconsole") == 0)
01748 is_imply_opt = TRUE;
01749
01750
01751 if (only_collect_imply_opts) {
01752 if (!is_imply_opt)
01753 continue;
01754 } else {
01755 if (is_imply_opt)
01756 continue;
01757 }
01758
01759 if (libhal_psi_get_bool (&it)) {
01760
01761 location = strstr (options_string, option);
01762 if (location == NULL) {
01763 if (strlen (options_string) > 0)
01764 strcat_len (options_string, ",", options_max_len);
01765 strcat_len (options_string, option, options_max_len);
01766 }
01767 } else {
01768
01769 location = strstr (options_string, option);
01770 if (location != NULL) {
01771 char *end;
01772
01773 end = strchr (location, ',');
01774 if (end == NULL) {
01775 location[0] = '\0';
01776 } else {
01777 strcpy (location, end + 1);
01778 }
01779 }
01780
01781 }
01782 }
01783 }
01784 error:
01785 libhal_free_property_set (properties);
01786 }
01787
01788
01789 const char *
01790 libhal_drive_policy_get_mount_options (LibHalDrive *drive, LibHalStoragePolicy *policy)
01791 {
01792 const char *result;
01793 char stor_mount_option_default_begin[] = "storage.policy.default.mount_option.";
01794 char stor_mount_option_begin[] = "storage.policy.mount_option.";
01795
01796 result = NULL;
01797 drive->mount_options[0] = '\0';
01798
01799
01800 mopts_collect (drive->hal_ctx, stor_mount_option_default_begin, sizeof (stor_mount_option_default_begin),
01801 "/org/freedesktop/Hal/devices/computer", drive->mount_options, MOUNT_OPTIONS_SIZE, TRUE);
01802 mopts_collect (drive->hal_ctx, stor_mount_option_begin, sizeof (stor_mount_option_begin),
01803 drive->udi, drive->mount_options, MOUNT_OPTIONS_SIZE, TRUE);
01804
01805 mopts_collect (drive->hal_ctx, stor_mount_option_default_begin, sizeof (stor_mount_option_default_begin),
01806 "/org/freedesktop/Hal/devices/computer", drive->mount_options, MOUNT_OPTIONS_SIZE, FALSE);
01807 mopts_collect (drive->hal_ctx, stor_mount_option_begin, sizeof (stor_mount_option_begin),
01808 drive->udi, drive->mount_options, MOUNT_OPTIONS_SIZE, FALSE);
01809
01810 result = drive->mount_options;
01811
01812 return result;
01813 }
01814
01815 const char *
01816 libhal_drive_policy_get_mount_fs (LibHalDrive *drive, LibHalStoragePolicy *policy)
01817 {
01818 return drive->mount_filesystem;
01819 }
01820
01821
01822 dbus_bool_t
01823 libhal_volume_policy_is_mountable (LibHalDrive *drive, LibHalVolume *volume, LibHalStoragePolicy *policy)
01824 {
01825 return drive->should_mount && volume->should_mount;
01826 }
01827
01828 const char *libhal_volume_policy_get_desired_mount_point (LibHalDrive *drive, LibHalVolume *volume, LibHalStoragePolicy *policy)
01829 {
01830 return volume->desired_mount_point;
01831 }
01832
01833 const char *libhal_volume_policy_get_mount_options (LibHalDrive *drive, LibHalVolume *volume, LibHalStoragePolicy *policy)
01834 {
01835 const char *result;
01836 char stor_mount_option_default_begin[] = "storage.policy.default.mount_option.";
01837 char vol_mount_option_begin[] = "volume.policy.mount_option.";
01838
01839 result = NULL;
01840 volume->mount_options[0] = '\0';
01841
01842
01843 mopts_collect (drive->hal_ctx, stor_mount_option_default_begin, sizeof (stor_mount_option_default_begin),
01844 "/org/freedesktop/Hal/devices/computer", volume->mount_options, MOUNT_OPTIONS_SIZE, TRUE);
01845 mopts_collect (drive->hal_ctx, vol_mount_option_begin, sizeof (vol_mount_option_begin),
01846 volume->udi, volume->mount_options, MOUNT_OPTIONS_SIZE, TRUE);
01847
01848 mopts_collect (drive->hal_ctx, stor_mount_option_default_begin, sizeof (stor_mount_option_default_begin),
01849 "/org/freedesktop/Hal/devices/computer", volume->mount_options, MOUNT_OPTIONS_SIZE, FALSE);
01850 mopts_collect (drive->hal_ctx, vol_mount_option_begin, sizeof (vol_mount_option_begin),
01851 volume->udi, volume->mount_options, MOUNT_OPTIONS_SIZE, FALSE);
01852
01853 result = volume->mount_options;
01854
01855 return result;
01856 }
01857
01858 const char *libhal_volume_policy_get_mount_fs (LibHalDrive *drive, LibHalVolume *volume, LibHalStoragePolicy *policy)
01859 {
01860 return volume->mount_filesystem;
01861 }
01862
01863 dbus_bool_t
01864 libhal_drive_no_partitions_hint (LibHalDrive *drive)
01865 {
01866 return drive->no_partitions_hint;
01867 }
01868