~ubuntu-branches/ubuntu/wily/hal/wily

« back to all changes in this revision

Viewing changes to .pc/53-kfreebsd-blkid.patch/hald/freebsd/probing/probe-storage.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2010-10-12 16:50:48 UTC
  • mfrom: (1.1.20 sid)
  • Revision ID: james.westby@ubuntu.com-20101012165048-fm9vz0n87zpoovcm
Tags: 0.5.14-3ubuntu1
* Merge with Debian unstable; remaining Ubuntu changes:
 - Add support for smartdimmer backlight control for GeForce 7/8/9 based
   Sony laptops.
   + Add 04_nvidia_brightness.patch.
   + Add smartdimmer recommends.
 - debian/hal.postinst: Do not create plugdev and powerdev groups.
 - Change startup from init/upstart to D-Bus activation. This allows us
   having installed programs which still need hal without the need to start
   hal on boot:
   + Remove debian/hal.{init,default}.
   + Add D-Bus activation service file debian/org.freedesktop.Hal.service and
     install it in debian/hal.install.
   + debian/hal.postinst: When triggering an .fdi file update, just stop
     hald; it will be reactivated when needed.
 - Add 02_libhal_dont_check_running.patch, 00git_bigger_path_size.patch, see
   their patch headers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 * CVSID: $Id$
 
3
 *
 
4
 * probe-storage.c : storage prober
 
5
 *
 
6
 * Copyright (C) 2006 Jean-Yves Lefort <jylefort@FreeBSD.org>
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2 of the License, or
 
11
 * (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License
 
19
 * along with this program; if not, write to the Free Software
 
20
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
21
 *
 
22
 **************************************************************************/
 
23
 
 
24
#ifdef HAVE_CONFIG_H
 
25
#  include <config.h>
 
26
#endif
 
27
 
 
28
#include <fcntl.h>
 
29
#include <string.h>
 
30
#include <stdlib.h>
 
31
#include <unistd.h>
 
32
#include <errno.h>
 
33
#include <sys/types.h>
 
34
#include <sys/ioctl.h>
 
35
#include <sys/disk.h>
 
36
#include <netinet/in.h>
 
37
#include <glib.h>
 
38
#include <libvolume_id.h>
 
39
 
 
40
#include "libhal/libhal.h"
 
41
 
 
42
#include "../libprobe/hfp.h"
 
43
#include "../libprobe/hfp-cdrom.h"
 
44
 
 
45
#include "freebsd_dvd_rw_utils.h"
 
46
 
 
47
static void
 
48
hf_probe_storage_get_cdrom_capabilities (const char *device_file,
 
49
                                         const char *parent)
 
50
{
 
51
  HFPCDROM *cdrom;
 
52
  HFPCDROMCapabilities caps;
 
53
  gboolean status = FALSE;
 
54
  int i;
 
55
  int read_speed;
 
56
  int write_speed;
 
57
  char *write_speeds;
 
58
 
 
59
  g_return_if_fail(device_file != NULL);
 
60
  g_return_if_fail(parent != NULL);
 
61
 
 
62
  cdrom = hfp_cdrom_new(device_file, parent);
 
63
  if (! cdrom)
 
64
    {
 
65
      hfp_warning("unable to open CD-ROM device %s", device_file);
 
66
      return;
 
67
    }
 
68
 
 
69
  /* according to sys/dev/ata/atapi-cd.c some buggy drives need this loop */
 
70
  for (i = 0; i < 5; i++)
 
71
    {
 
72
      static char ccb[16] = { HFP_CDROM_MODE_SENSE_BIG, 0, HFP_CDROM_CAP_PAGE, 0, 0, 0, 0, sizeof(caps) >> 8, sizeof(caps) };
 
73
      char *err = NULL;
 
74
 
 
75
      if (! hfp_cdrom_send_ccb(cdrom, ccb, 10, HFP_CDROM_DIRECTION_IN, &caps, sizeof(caps), &err))
 
76
        {
 
77
          hfp_warning("%s: unable to get capabilities: %s", device_file, err);
 
78
          hfp_free(err);
 
79
          continue;
 
80
        }
 
81
      if (caps.page_code != HFP_CDROM_CAP_PAGE)
 
82
        {
 
83
          hfp_warning("%s: bad page code %i", device_file, caps.page_code);
 
84
          continue;
 
85
        }
 
86
 
 
87
      status = TRUE;
 
88
    }
 
89
 
 
90
  if (! status)
 
91
    goto end;
 
92
 
 
93
  if ((caps.media & HFP_CDROM_MST_WRITE_CDR) != 0)
 
94
    libhal_device_set_property_bool(hfp_ctx, hfp_udi, "storage.cdrom.cdr", TRUE, &hfp_error);
 
95
  if ((caps.media & HFP_CDROM_MST_WRITE_CDRW) != 0)
 
96
    libhal_device_set_property_bool(hfp_ctx, hfp_udi, "storage.cdrom.cdrw", TRUE, &hfp_error);
 
97
  if ((caps.media & HFP_CDROM_MST_READ_DVDROM) != 0)
 
98
    {
 
99
      int profile;
 
100
      gboolean r;
 
101
      gboolean rw;
 
102
      gboolean rdl;
 
103
      gboolean rwdl;
 
104
      gboolean bd;
 
105
      gboolean bdr;
 
106
      gboolean bdre;
 
107
      gboolean hddvd;
 
108
      gboolean hddvdr;
 
109
      gboolean hddvdrw;
 
110
 
 
111
      libhal_device_set_property_bool(hfp_ctx, hfp_udi, "storage.cdrom.dvd", TRUE, &hfp_error);
 
112
 
 
113
      profile = get_dvd_r_rw_profile(cdrom);
 
114
      r = (profile & DRIVE_CDROM_CAPS_DVDPLUSR) != 0;
 
115
      rw = (profile & DRIVE_CDROM_CAPS_DVDRW) != 0;
 
116
      rdl = (profile & DRIVE_CDROM_CAPS_DVDPLUSRDL) != 0;
 
117
      rwdl = (profile & DRIVE_CDROM_CAPS_DVDPLUSRWDL) != 0;
 
118
      bd = (profile & DRIVE_CDROM_CAPS_BDROM) != 0;
 
119
      bdr = (profile & DRIVE_CDROM_CAPS_BDR) != 0;
 
120
      bdre = (profile & DRIVE_CDROM_CAPS_BDRE) != 0;
 
121
      hddvd = (profile & DRIVE_CDROM_CAPS_HDDVDROM) != 0;
 
122
      hddvdr = (profile & DRIVE_CDROM_CAPS_HDDVDR) != 0;
 
123
      hddvdrw = (profile & DRIVE_CDROM_CAPS_HDDVDRW) != 0;
 
124
 
 
125
      libhal_device_set_property_bool(hfp_ctx, hfp_udi, "storage.cdrom.dvdplusr", r, &hfp_error);
 
126
      libhal_device_set_property_bool(hfp_ctx, hfp_udi, "storage.cdrom.dvdplusrw", rw, &hfp_error);
 
127
      libhal_device_set_property_bool(hfp_ctx, hfp_udi, "storage.cdrom.dvdplusrdl", rdl, &hfp_error);
 
128
      libhal_device_set_property_bool(hfp_ctx, hfp_udi, "storage.cdrom.dvdplusrwdl", rwdl, &hfp_error);
 
129
      libhal_device_set_property_bool(hfp_ctx, hfp_udi, "storage.cdrom.bd", bd, &hfp_error);
 
130
      libhal_device_set_property_bool(hfp_ctx, hfp_udi, "storage.cdrom.bdr", bdr, &hfp_error);
 
131
      libhal_device_set_property_bool(hfp_ctx, hfp_udi, "storage.cdrom.bdre", bdre, &hfp_error);
 
132
      libhal_device_set_property_bool(hfp_ctx, hfp_udi, "storage.cdrom.hddvd", hddvd, &hfp_error);
 
133
      libhal_device_set_property_bool(hfp_ctx, hfp_udi, "storage.cdrom.hddvdr", hddvdr, &hfp_error);
 
134
      libhal_device_set_property_bool(hfp_ctx, hfp_udi, "storage.cdrom.hddvdrw", hddvdrw, &hfp_error);
 
135
    }
 
136
  if ((caps.media & HFP_CDROM_MST_WRITE_DVDR) != 0)
 
137
    libhal_device_set_property_bool(hfp_ctx, hfp_udi, "storage.cdrom.dvdr", TRUE, &hfp_error);
 
138
  if ((caps.media & HFP_CDROM_MST_WRITE_DVDRAM) != 0)
 
139
    libhal_device_set_property_bool(hfp_ctx, hfp_udi, "storage.cdrom.dvdram", TRUE, &hfp_error);
 
140
 
 
141
  if (get_read_write_speed(cdrom, &read_speed, &write_speed, &write_speeds) >= 0)
 
142
    {
 
143
      libhal_device_set_property_int(hfp_ctx, hfp_udi, "storage.cdrom.read_speed", read_speed, &hfp_error);
 
144
      if (write_speed > 0)
 
145
        {
 
146
          libhal_device_set_property_int(hfp_ctx, hfp_udi, "storage.cdrom.write_speed", write_speed, &hfp_error);
 
147
 
 
148
          if (write_speeds != NULL)
 
149
            {
 
150
              char **speedv;
 
151
              int i;
 
152
 
 
153
              speedv = g_strsplit_set(write_speeds, ",", 0);
 
154
              free(write_speeds);
 
155
 
 
156
              for (i = 0; speedv[i] != NULL; i++)
 
157
                if (*(speedv[i]))
 
158
                  libhal_device_property_strlist_append(hfp_ctx, hfp_udi, "storage.cdrom.write_speeds", speedv[i], &hfp_error);
 
159
 
 
160
              g_strfreev(speedv);
 
161
            }
 
162
        }
 
163
    }
 
164
 
 
165
 end:
 
166
  if (cdrom)
 
167
    hfp_cdrom_free(cdrom);
 
168
}
 
169
 
 
170
int
 
171
main (int argc, char **argv)
 
172
{
 
173
  char *device_file;
 
174
  char *drive_type;
 
175
  char *parent;
 
176
  int ret = 0;                  /* no media/filesystem */
 
177
  gboolean has_children;
 
178
  gboolean only_check_for_media;
 
179
  gboolean is_cdrom;
 
180
 
 
181
  if (! hfp_init(argc, argv))
 
182
    goto end;
 
183
 
 
184
  device_file = getenv("HAL_PROP_BLOCK_DEVICE");
 
185
  if (! device_file)
 
186
    goto end;
 
187
 
 
188
  drive_type = getenv("HAL_PROP_STORAGE_DRIVE_TYPE");
 
189
  if (! drive_type)
 
190
    goto end;
 
191
 
 
192
  parent = getenv("HAL_PROP_INFO_PARENT");
 
193
  if (! parent)
 
194
    goto end;
 
195
 
 
196
#ifndef __GLIBC__
 
197
  /* give a meaningful process title for ps(1) */
 
198
  setproctitle("%s", device_file);
 
199
#endif
 
200
 
 
201
  has_children = hfp_getenv_bool("HF_HAS_CHILDREN");
 
202
  only_check_for_media = hfp_getenv_bool("HF_ONLY_CHECK_FOR_MEDIA");
 
203
 
 
204
  is_cdrom = ! strcmp(drive_type, "cdrom");
 
205
 
 
206
  if (! only_check_for_media && is_cdrom)
 
207
    hf_probe_storage_get_cdrom_capabilities(device_file, parent);
 
208
 
 
209
  if (is_cdrom)
 
210
    {
 
211
      HFPCDROM *cdrom;
 
212
 
 
213
      cdrom = hfp_cdrom_new(device_file, parent);
 
214
      if (! cdrom)
 
215
        goto end;
 
216
 
 
217
      if (hfp_cdrom_test_unit_ready(cdrom))
 
218
        {
 
219
          int fd;
 
220
          off_t size;
 
221
 
 
222
          libhal_device_set_property_bool(hfp_ctx, hfp_udi, "storage.removable.media_available", TRUE, &hfp_error);
 
223
          fd = open(device_file, O_RDONLY | O_NONBLOCK);
 
224
          if (fd > -1)
 
225
            {
 
226
              if (ioctl (fd, DIOCGMEDIASIZE, &size) == 0)
 
227
                {
 
228
                  libhal_device_set_property_uint64(hfp_ctx, hfp_udi, "storage.removable.media_size", size, &hfp_error);
 
229
                }
 
230
              close(fd);
 
231
            }
 
232
          ret = 2;              /* has media */
 
233
        }
 
234
      else
 
235
        {
 
236
          libhal_device_set_property_bool(hfp_ctx, hfp_udi, "storage.removable.media_available", FALSE, &hfp_error);
 
237
        }
 
238
 
 
239
      hfp_cdrom_free(cdrom);
 
240
    }
 
241
  else if (! has_children) /* by definition, if it has children it has no fs */
 
242
    {
 
243
      struct volume_id *vid;
 
244
 
 
245
      vid = volume_id_open_node(device_file);
 
246
      if (! vid)
 
247
        goto end;
 
248
 
 
249
      if (volume_id_probe_all(vid, 0, 0) == 0 && vid->usage_id == VOLUME_ID_FILESYSTEM)
 
250
        ret = 2;                /* has a filesystem */
 
251
 
 
252
      volume_id_close(vid);
 
253
    }
 
254
 
 
255
 end:
 
256
  return ret;
 
257
}