~ubuntu-branches/debian/sid/hal/sid

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2007-10-23 12:33:58 UTC
  • Revision ID: james.westby@ubuntu.com-20071023123358-xaf8mjc5n84d5gtz
Tags: upstream-0.5.10
ImportĀ upstreamĀ versionĀ 0.5.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
118
118
        /* hook in our debug into libvolume_id */
119
119
        volume_id_log_fn = vid_log;
120
120
 
 
121
        fprintf (stderr, "woohoo\n");
 
122
 
121
123
        /* assume failure */
122
124
        ret = 1;
123
125
 
152
154
        HAL_DEBUG (("Doing probe-storage for %s (bus %s) (drive_type %s) (udi=%s) (--only-check-for-fs==%d)", 
153
155
             device_file, bus, drive_type, udi, only_check_for_fs));
154
156
 
155
 
        if (!only_check_for_fs) {
156
 
                /* Get properties for CD-ROM drive */
157
 
                if (strcmp (drive_type, "cdrom") == 0) {
158
 
                        int capabilities;
159
 
                        int read_speed, write_speed;
160
 
                        char *write_speeds;
161
 
                        
162
 
                        HAL_DEBUG (("Doing open (\"%s\", O_RDONLY | O_NONBLOCK)", device_file));
163
 
                        fd = open (device_file, O_RDONLY | O_NONBLOCK);
164
 
                        if (fd < 0) {
165
 
                                HAL_ERROR (("Cannot open %s: %s", device_file, strerror (errno)));
166
 
                                goto out;
167
 
                        }
168
 
                        HAL_DEBUG (("Returned from open(2)"));
 
157
        /* Get properties for CD-ROM drive */
 
158
        if (strcmp (drive_type, "cdrom") == 0) {
 
159
                int capabilities;
 
160
                int read_speed, write_speed;
 
161
                char *write_speeds;
 
162
                
 
163
                HAL_DEBUG (("Doing open (\"%s\", O_RDONLY | O_NONBLOCK)", device_file));
 
164
                fd = open (device_file, O_RDONLY | O_NONBLOCK);
 
165
                if (fd < 0) {
 
166
                        HAL_ERROR (("Cannot open %s: %s", device_file, strerror (errno)));
 
167
                        goto out;
 
168
                }
 
169
                HAL_DEBUG (("Returned from open(2)"));
169
170
 
170
 
                        if (ioctl (fd, CDROM_SET_OPTIONS, CDO_USE_FFLAGS) < 0) {
171
 
                                HAL_ERROR (("Error: CDROM_SET_OPTIONS failed: %s\n", strerror(errno)));
172
 
                                close (fd);
173
 
                                goto out;
174
 
                        }
175
 
                        
 
171
                if (ioctl (fd, CDROM_SET_OPTIONS, CDO_USE_FFLAGS) < 0) {
 
172
                        HAL_ERROR (("Error: CDROM_SET_OPTIONS failed: %s\n", strerror(errno)));
 
173
                        close (fd);
 
174
                        goto out;
 
175
                }
 
176
                
 
177
                if (!only_check_for_fs) {
176
178
                        capabilities = ioctl (fd, CDROM_GET_CAPABILITY, 0);
177
179
                        if (capabilities < 0) {
178
180
                                close (fd);
218
220
                                if (profile & DRIVE_CDROM_CAPS_DVDRW)
219
221
                                        libhal_changeset_set_property_bool (cs, "storage.cdrom.dvdrw", TRUE);
220
222
                                if (profile & DRIVE_CDROM_CAPS_DVDPLUSR)
221
 
                                        libhal_changeset_set_property_bool(cs, "storage.cdrom.dvdplusr", TRUE);
 
223
                                        libhal_changeset_set_property_bool (cs, "storage.cdrom.dvdplusr", TRUE);
222
224
                                if (profile & DRIVE_CDROM_CAPS_DVDPLUSRW)
223
225
                                        libhal_changeset_set_property_bool (cs, "storage.cdrom.dvdplusrw", TRUE);
224
226
                                if (profile & DRIVE_CDROM_CAPS_DVDPLUSRWDL)
225
227
                                        libhal_changeset_set_property_bool (cs, "storage.cdrom.dvdplusrwdl", TRUE);
226
228
                                if (profile & DRIVE_CDROM_CAPS_DVDPLUSRDL)
227
 
                                        libhal_changeset_set_property_bool (cs, "storage.cdrom.dvdplusrdl", TRUE);
 
229
                                        libhal_changeset_set_property_bool (cs, "storage.cdrom.dvdplusrdl", TRUE);
 
230
                                if (profile & DRIVE_CDROM_CAPS_BDROM)
 
231
                                        libhal_changeset_set_property_bool (cs, "storage.cdrom.bd", TRUE);
 
232
                                if (profile & DRIVE_CDROM_CAPS_BDR)
 
233
                                        libhal_changeset_set_property_bool (cs, "storage.cdrom.bdr", TRUE);
 
234
                                if (profile & DRIVE_CDROM_CAPS_BDRE)
 
235
                                        libhal_changeset_set_property_bool (cs, "storage.cdrom.bdre", TRUE);
 
236
                                if (profile & DRIVE_CDROM_CAPS_HDDVDROM)
 
237
                                        libhal_changeset_set_property_bool (cs, "storage.cdrom.hddvd", TRUE);
 
238
                                if (profile & DRIVE_CDROM_CAPS_HDDVDR)
 
239
                                        libhal_changeset_set_property_bool (cs, "storage.cdrom.hddvdr", TRUE);
 
240
                                if (profile & DRIVE_CDROM_CAPS_HDDVDRW)
 
241
                                        libhal_changeset_set_property_bool (cs, "storage.cdrom.hddvdrw", TRUE);
228
242
                        }
229
243
                        if (capabilities & CDC_DVD_R) {
230
244
                                libhal_changeset_set_property_bool (cs, "storage.cdrom.dvdr", TRUE);
253
267
                        } else {
254
268
                                libhal_changeset_set_property_bool (cs, "storage.cdrom.support_multisession", FALSE);
255
269
                        }
256
 
                
257
 
                        if (get_read_write_speed(fd, &read_speed, &write_speed, &write_speeds) >= 0) {
258
 
                                libhal_changeset_set_property_int (cs, "storage.cdrom.read_speed", read_speed);
259
 
                                if (write_speed > 0) {
260
 
                                        libhal_changeset_set_property_int (
261
 
                                                cs, "storage.cdrom.write_speed", write_speed);
262
 
                                        
263
 
                                        if (write_speeds != NULL)
264
 
                                        {
265
 
                                                gchar **wspeeds;
266
 
                                                wspeeds = g_strsplit_set (write_speeds, ",", -1);
267
 
                                                libhal_changeset_set_property_strlist (cs, 
268
 
                                                                                       "storage.cdrom.write_speeds", 
269
 
                                                                                       (const char **) wspeeds);
270
 
                                                g_strfreev (wspeeds);
271
 
                                                free (write_speeds);
272
 
                                        }
273
 
                                } else {
274
 
                                        gchar *wspeeds[1] = {NULL};
275
 
                                        libhal_changeset_set_property_int (cs, "storage.cdrom.write_speed", 0);
 
270
        
 
271
                }
 
272
 
 
273
                if (get_read_write_speed(fd, &read_speed, &write_speed, &write_speeds) >= 0) {
 
274
                        libhal_changeset_set_property_int (cs, "storage.cdrom.read_speed", read_speed);
 
275
 
 
276
                        if (write_speed > 0) {
 
277
                                libhal_changeset_set_property_int (cs, "storage.cdrom.write_speed", write_speed);
 
278
                                
 
279
                                if (write_speeds != NULL)
 
280
                                {
 
281
                                        gchar **wspeeds;
 
282
 
 
283
                                        wspeeds = g_strsplit_set (write_speeds, ",", -1);
276
284
                                        libhal_changeset_set_property_strlist (cs, "storage.cdrom.write_speeds", 
277
285
                                                                               (const char **) wspeeds);
 
286
                                        g_strfreev (wspeeds);
 
287
                                        free (write_speeds);
 
288
                                
278
289
                                }
 
290
                        } else {
 
291
                                gchar *wspeeds[1] = {NULL};
 
292
                                libhal_changeset_set_property_int (cs, "storage.cdrom.write_speed", 0);
 
293
                                libhal_changeset_set_property_strlist (cs, "storage.cdrom.write_speeds", 
 
294
                                                                       (const char **) wspeeds);
279
295
                        }
280
 
                        
281
 
                        close (fd);
282
296
                }
283
297
                
284
 
        } /* !only_check_for_fs */
285
 
 
 
298
                close (fd);
 
299
        }
 
300
                
286
301
        ret = 0;
287
302
 
288
303
        /* Also return 2 if we're a cdrom and we got a disc */
455
470
                vid = volume_id_open_fd (fd);
456
471
                if (vid != NULL) {
457
472
                        if (volume_id_probe_all (vid, 0, size) == 0) {
 
473
                                const char *usage;
458
474
                                /* signal to hald that we've found something and a fakevolume
459
475
                                 * should be added - see hald/linux/blockdev.c:add_blockdev_probing_helper_done()
460
476
                                 * and hald/linux/blockdev.c:block_rescan_storage_done().
461
477
                                 */
462
 
                                if (vid->usage_id == VOLUME_ID_FILESYSTEM ||
463
 
                                    vid->usage_id == VOLUME_ID_RAID ||
464
 
                                    vid->usage_id == VOLUME_ID_OTHER ||
465
 
                                    vid->usage_id == VOLUME_ID_CRYPTO)
 
478
 
 
479
                                if (volume_id_get_usage(vid, &usage) &&
 
480
                                    ( strcmp(usage, "filesystem") == 0 ||
 
481
                                      strcmp(usage, "raid") == 0 ||
 
482
                                      strcmp(usage, "other") == 0 ||
 
483
                                      strcmp(usage, "crypto") == 0))
466
484
                                        ret = 2;
467
485
                        } else {
468
486
                                ;