~ubuntu-branches/ubuntu/oneiric/hal/oneiric

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-02-14 11:45:59 UTC
  • Revision ID: james.westby@ubuntu.com-20110214114559-g5ti3fxottbysekt
Tags: 0.5.14-5+svn1
Upload current Debian svn head to fix FTBFS.

* Add 00upstream_video4linux_check.patch: Do not build
  hald-probe-video4linux if v4l1 is not available. (LP: #721399)
* Refresh 99-autoreconf.patch for above.
* 45-fix-libusb-detection.patch: Unfuzz.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
#include <sys/param.h>
39
39
#include <sys/mount.h>
40
40
#include <sys/types.h>
 
41
#ifdef HAVE_LIBUFS
41
42
#include <ufs/ufs/ufsmount.h>
42
43
#include <ufs/ufs/dinode.h>
43
44
#include <ufs/ffs/fs.h>
44
45
#include <libufs.h>
 
46
#endif /* HAVE_LIBUFS */
45
47
#include <isofs/cd9660/iso.h>
46
48
#include <glib.h>
47
 
#include <libvolume_id.h>
 
49
#include <blkid.h>
48
50
 
49
51
#include "libhal/libhal.h"
50
52
 
103
105
}
104
106
 
105
107
static char *
106
 
hf_probe_volume_get_label (const struct volume_id *vid)
 
108
hf_probe_volume_get_label (const blkid_probe pr)
107
109
{
108
 
  char *label = NULL;
 
110
  const char *label;
 
111
  char *volume_label = NULL;
109
112
 
110
 
  if (vid && *vid->label)
 
113
  if (blkid_probe_lookup_value(pr, "LABEL", &label, NULL) == 0)
111
114
    {
112
 
      if (g_utf8_validate(vid->label, -1, NULL))
113
 
        label = g_strdup(vid->label);
 
115
      if (g_utf8_validate(label, -1, NULL))
 
116
        volume_label = g_strdup(label);
114
117
      else                              /* assume ISO8859-1 */
115
 
        label = g_convert(vid->label, -1, "UTF-8", "ISO8859-1", NULL, NULL, NULL);
 
118
        volume_label = g_convert(label, -1, "UTF-8", "ISO8859-1", NULL, NULL, NULL);
116
119
    }
117
120
 
118
 
  return label;
 
121
  return volume_label;
119
122
}
120
123
 
121
124
static void
321
324
  char *grandparent_udi;
322
325
  char *parent_drive_type;
323
326
  int fd = -1;
324
 
  struct volume_id *vid = NULL;
 
327
  blkid_probe pr;
325
328
  int ret = 1;
326
329
  gboolean has_children;
327
330
  gboolean is_swap;
331
334
  gboolean has_data = FALSE;
332
335
  gboolean is_blank = FALSE;
333
336
  const char *usage;
334
 
  char *label;
 
337
  const char *type;
 
338
  const char *type_version;
 
339
  const char *label;
 
340
  const char *uuid;
335
341
  unsigned int sector_size = 0;
336
342
  off_t media_size = 0;
337
343
 
347
353
    goto end;
348
354
 
349
355
  /* give a meaningful process title for ps(1) */
 
356
#ifndef __GLIBC__
350
357
  setproctitle("%s", device_file);
 
358
#endif
351
359
 
352
360
  has_children = hfp_getenv_bool("HF_HAS_CHILDREN");
353
361
  is_swap = hfp_getenv_bool("HF_IS_SWAP");
384
392
   */
385
393
  if (! has_children && ! (is_cdrom && ! has_data))
386
394
    {
387
 
      vid = volume_id_open_fd(fd);
388
 
      if (vid)
389
 
        {
390
 
          if (volume_id_probe_all(vid, 0, media_size) == 0)
391
 
            has_data = TRUE;
392
 
          else
393
 
            {
394
 
              volume_id_close(vid);
395
 
              vid = NULL;
396
 
            }
397
 
        }
 
395
      pr = blkid_new_probe ();
 
396
      if (pr != NULL)
 
397
        {
 
398
          int bid_ret;
 
399
 
 
400
          blkid_probe_set_request (pr, BLKID_PROBREQ_LABEL | BLKID_PROBREQ_UUID |
 
401
                                       BLKID_PROBREQ_TYPE | BLKID_PROBREQ_SECTYPE |
 
402
                                       BLKID_PROBREQ_USAGE | BLKID_PROBREQ_VERSION);
 
403
 
 
404
          bid_ret = blkid_probe_set_device (pr, fd, 0, media_size);
 
405
          if (bid_ret == 0)
 
406
            {
 
407
              bid_ret = blkid_do_safeprobe (pr);
 
408
              hfp_warning ("blkid_do_safeprobe returned an error");
 
409
            }
 
410
          if (bid_ret == 0)
 
411
            has_data = TRUE;
 
412
        }
398
413
    }
399
414
 
400
415
  if (! has_children && ! is_swap && ! has_audio && ! has_data && ! is_blank)
401
 
    goto end;
 
416
    goto end_free;
402
417
 
403
418
  libhal_device_add_capability(hfp_ctx, hfp_udi, "volume", &hfp_error);
404
419
  if (is_cdrom)
507
522
          hfp_cdrom_free(cdrom);
508
523
        }
509
524
 
510
 
      if (has_data && vid && (! strcmp(vid->type, "iso9660") ||
511
 
          ! strcmp(vid->type, "udf")))
512
 
        hf_probe_volume_advanced_disc_detect(fd);
 
525
      if (has_data && pr) {
 
526
        const char *cdrom_fstype;
 
527
        if (! blkid_probe_lookup_value(pr, "TYPE", &cdrom_fstype, NULL) &&
 
528
            (! strcmp(cdrom_fstype, "iso9660") || ! strcmp(cdrom_fstype, "udf"))) {
 
529
          hf_probe_volume_advanced_disc_detect(fd);
 
530
        }
 
531
      }
 
532
 
513
533
    }
514
534
  else
515
535
    {
561
581
 
562
582
  libhal_device_set_property_bool(hfp_ctx, hfp_udi, "volume.ignore", has_children || is_swap, &hfp_error);
563
583
 
 
584
#ifdef HAVE_LIBUFS
564
585
  if (vid && ! strcmp (vid->type, "ufs"))
565
586
    {
566
587
      struct uufsd ufsdisk;
600
621
          ufs_disk_close(&ufsdisk);
601
622
        }
602
623
    }
 
624
#endif /* HAVE_LIBUFS */
603
625
 
604
626
  if (has_children)
605
627
    usage = "partitiontable";
606
628
  else if (is_swap)
607
629
    usage = "other";
608
 
  else
609
 
    switch (vid ? vid->usage_id : (enum volume_id_usage) -1)
610
 
      {
611
 
      case VOLUME_ID_FILESYSTEM:        usage = "filesystem"; break;
612
 
      case VOLUME_ID_DISKLABEL:         usage = "disklabel"; break;
613
 
      case VOLUME_ID_OTHER:             usage = "other"; break;
614
 
      case VOLUME_ID_RAID:              usage = "raid"; break;
615
 
      case VOLUME_ID_CRYPTO:            usage = "crypto"; break;
616
 
      case VOLUME_ID_UNUSED:            usage = "unused"; break;
617
 
      default:                          usage = "unknown"; break;
618
 
      }
619
 
 
 
630
  else if (blkid_probe_lookup_value(pr, "USAGE", &usage, NULL))
 
631
    usage = "";
620
632
  libhal_device_set_property_string(hfp_ctx, hfp_udi, "volume.fsusage", usage, &hfp_error);
621
 
  libhal_device_set_property_string(hfp_ctx, hfp_udi, "volume.fstype", vid ? vid->type: "", &hfp_error);
622
 
  if (vid && *vid->type_version)
623
 
    libhal_device_set_property_string(hfp_ctx, hfp_udi, "volume.fsversion", vid->type_version, &hfp_error);
624
 
 
625
 
  label = hf_probe_volume_get_label(vid);
 
633
 
 
634
  if (blkid_probe_lookup_value(pr, "TYPE", &type, NULL))
 
635
    type = "";
 
636
  libhal_device_set_property_string(hfp_ctx, hfp_udi, "volume.fstype", type, &hfp_error);
 
637
  if (blkid_probe_lookup_value(pr, "VERSION", &type, NULL))
 
638
    type_version = "";
 
639
  libhal_device_set_property_string(hfp_ctx, hfp_udi, "volume.fsversion", type_version, &hfp_error);
 
640
 
 
641
  label = hf_probe_volume_get_label(pr);
626
642
  libhal_device_set_property_string(hfp_ctx, hfp_udi, "volume.label", label ? label : "", &hfp_error);
627
643
  g_free(label);
628
644
 
629
 
  libhal_device_set_property_string(hfp_ctx, hfp_udi, "volume.uuid", vid ? vid->uuid : "", &hfp_error);
 
645
  if (blkid_probe_lookup_value(pr, "UUID", &uuid, NULL))
 
646
    uuid = "";
 
647
  libhal_device_set_property_string(hfp_ctx, hfp_udi, "volume.uuid", uuid, &hfp_error);
630
648
 
631
649
  ioctl(fd, DIOCGSECTORSIZE, &sector_size);
632
650
 
639
657
 
640
658
  ret = 0;                      /* is a volume */
641
659
 
 
660
 end_free:
 
661
  blkid_free_probe (pr);
 
662
 
642
663
 end:
643
664
  return ret;
644
665
}