~ubuntu-branches/ubuntu/maverick/hal/maverick

« back to all changes in this revision

Viewing changes to hald/linux/probing/probe-volume.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-05-11 11:23:03 UTC
  • mto: (1.5.1 sid)
  • mto: This revision was merged to the branch mainline in revision 148.
  • Revision ID: james.westby@ubuntu.com-20090511112303-sfphxadhb10x4vdb
Tags: upstream-0.5.12~rc1+git20090510
ImportĀ upstreamĀ versionĀ 0.5.12~rc1+git20090510

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#include <signal.h>
43
43
 
44
44
#include <glib.h>
45
 
#include <libvolume_id.h>
 
45
#include <blkid.h>
46
46
 
47
47
#include "libhal/libhal.h"
48
48
#include "partutil/partutil.h"
49
49
#include "linux_dvd_rw_utils.h"
50
50
#include "../../logger.h"
51
51
 
52
 
static void vid_log(int priority, const char *file, int line, const char *format, ...)
53
 
{
54
 
        char log_str[1024];
55
 
        va_list args;
56
 
 
57
 
        va_start(args, format);
58
 
        vsnprintf(log_str, sizeof(log_str), format, args);
59
 
        logger_forward_debug("%s:%i %s\n", file, line, log_str);
60
 
        va_end(args);
61
 
}
62
 
 
63
52
static gchar *
64
53
strdup_valid_utf8 (const char *str)
65
54
{
89
78
 
90
79
 
91
80
static void
92
 
set_volume_id_values (LibHalChangeSet *cs, struct volume_id *vid)
 
81
set_blkid_values (LibHalChangeSet *cs, blkid_probe pr)
93
82
{
94
83
        char buf[256];
95
84
        const char *usage;
101
90
 
102
91
        dbus_error_init (&error);
103
92
 
104
 
        if (!volume_id_get_usage(vid, &usage))
 
93
        if (blkid_probe_lookup_value(pr, "USAGE", &usage, NULL))
105
94
                usage = "";
106
95
        libhal_changeset_set_property_string (cs, "volume.fsusage", usage);
107
96
        HAL_DEBUG (("volume.fsusage = '%s'", usage));
108
97
 
109
 
        if (!volume_id_get_type(vid, &type))
 
98
        if (blkid_probe_lookup_value(pr, "TYPE", &type, NULL))
110
99
                type = "";
111
 
        if (!libhal_changeset_set_property_string (cs, "volume.fstype", type))
 
100
        if (libhal_changeset_set_property_string (cs, "volume.fstype", type))
112
101
                libhal_changeset_set_property_string (cs, "volume.fstype", "");
113
102
        HAL_DEBUG(("volume.fstype = '%s'", type));
114
103
 
115
 
        if (!volume_id_get_type_version(vid, &type_version))
 
104
        if (blkid_probe_lookup_value(pr, "VERSION", &type_version, NULL))
116
105
                type_version = "";
117
106
        libhal_changeset_set_property_string (cs, "volume.fsversion", type_version);
118
107
        HAL_DEBUG(("volume.fsversion = '%s'", type_version));
119
108
 
120
 
        if (!volume_id_get_uuid(vid, &uuid))
 
109
        if (blkid_probe_lookup_value(pr, "UUID", &uuid, NULL))
121
110
                uuid = "";
122
111
        libhal_changeset_set_property_string (cs, "volume.uuid", uuid);
123
112
        HAL_DEBUG(("volume.uuid = '%s'", uuid));
124
113
 
125
 
        if (!volume_id_get_label(vid, &label))
 
114
        if (blkid_probe_lookup_value(pr, "LABEL", &label, NULL))
126
115
                label = "";
127
116
 
128
117
        if (label[0] != '\0') {
311
300
        LibHalContext *ctx = NULL;
312
301
        DBusError error;
313
302
        char *parent_udi;
314
 
        struct volume_id *vid;
 
303
        blkid_probe pr;
315
304
        char *stordev_dev_file;
316
305
        char *partition_number_str;
317
306
        char *partition_start_str;
331
320
        cs = NULL;
332
321
        disc_may_have_data = FALSE;
333
322
 
334
 
        /* hook in our debug into libvolume_id */
335
 
        volume_id_log_fn = vid_log;
336
 
 
337
323
        setup_logger ();
338
324
 
339
325
        /* assume failure */
631
617
                }
632
618
 
633
619
                /* probe for file system */
634
 
                vid = volume_id_open_fd (fd);
635
 
                if (vid != NULL) {
636
 
                        int vid_ret;
637
 
                        HAL_INFO (("invoking volume_id_probe_all, offset=%d, size=%d", vol_probe_offset, vol_size));
638
 
                        vid_ret = volume_id_probe_all (vid, vol_probe_offset, vol_size);
639
 
                        HAL_INFO (("volume_id_probe_all returned %d", vid_ret));
640
 
 
641
 
                        if (vid_ret != 0 && is_disc && vol_probe_offset != 0) {
 
620
                pr = blkid_new_probe ();
 
621
                if (pr != NULL) {
 
622
                        int bid_ret;
 
623
 
 
624
                        blkid_probe_set_request (pr, BLKID_PROBREQ_LABEL | BLKID_PROBREQ_UUID |
 
625
                                                 BLKID_PROBREQ_TYPE | BLKID_PROBREQ_SECTYPE |
 
626
                                                 BLKID_PROBREQ_USAGE | BLKID_PROBREQ_VERSION);
 
627
 
 
628
                        HAL_INFO (("invoking blkid_do_safeprobe, offset=%d, size=%d", vol_probe_offset, vol_size));
 
629
                        bid_ret = blkid_probe_set_device (pr, fd, vol_probe_offset, vol_size);
 
630
                        if (bid_ret == 0) {
 
631
                                bid_ret = blkid_do_safeprobe (pr);
 
632
                                HAL_INFO (("blkid_do_safeprobe returned %d", bid_ret));
 
633
                        }
 
634
 
 
635
                        if (bid_ret != 0 && is_disc && vol_probe_offset != 0) {
642
636
                                /* Some cd-rom drives report the offset of the session in the cd's TOC
643
637
                                 * wrong.  Fallback to probing at offset 0, just to be sure */
644
 
                                HAL_INFO (("invoking volume_id_probe_all, offset=0, size=%d", vol_size));
645
 
                                vid_ret = volume_id_probe_all (vid, 0 , vol_size);
646
 
                                HAL_INFO (("volume_id_probe_all returned %d", vid_ret));
 
638
                                HAL_INFO (("invoking blkid_do_safeprobe, offset=0, size=%d", vol_size));
 
639
                                bid_ret = blkid_probe_set_device (pr, fd, 0, vol_size);
 
640
                                if (bid_ret == 0)
 
641
                                        bid_ret = blkid_do_safeprobe (pr);
 
642
                                HAL_INFO (("blkid_do_safeprobe returned %d", bid_ret));
647
643
                        }
648
644
 
649
 
                        if (vid_ret == 0) {
650
 
                                set_volume_id_values(cs, vid);
 
645
                        if (bid_ret == 0) {
 
646
                                set_blkid_values(cs, pr);
651
647
                                if (disc_may_have_data) {
652
648
                                        libhal_changeset_set_property_bool (cs, "volume.disc.is_blank", FALSE);
653
649
                                        libhal_changeset_set_property_bool (cs, "volume.disc.has_data", TRUE);
663
659
                         *  this is good enough for now... the only discs I know of that does this
664
660
                         *  is in fact Apple's install disc.)
665
661
                         */
666
 
                        if (vid_ret != 0 && is_disc) {
 
662
                        if (bid_ret != 0 && is_disc) {
667
663
                                PartitionTable *p;
668
664
                                p = part_table_load_from_disk (stordev_dev_file);
669
665
                                if (p != NULL) {
681
677
                                                        guint64 part_offset;
682
678
 
683
679
                                                        part_offset = part_table_entry_get_offset (p, i);
684
 
                                                        if (volume_id_probe_all (
685
 
                                                                    vid, vol_probe_offset + part_offset, 0) == 0) {
686
 
 
687
 
                                                                set_volume_id_values(cs, vid);
688
 
                                                        }
 
680
                                                        if (blkid_probe_set_device (pr, fd,
 
681
                                                                vol_probe_offset + part_offset, 0) == 0 &&
 
682
                                                            blkid_do_safeprobe (pr) == 0)
 
683
                                                                set_blkid_values(cs, pr);
689
684
 
690
685
                                                        /* and we're done */
691
686
                                                        break;
699
694
                                }
700
695
                        }
701
696
 
702
 
                        volume_id_close(vid);
 
697
                        blkid_free_probe (pr);
703
698
                }
704
699
 
705
700
                /* get partition type number, if we find a msdos partition table */