This file is indexed.

/usr/lib/x86_64-linux-gnu/perl5/5.20/Device/Cdio/Device.pm is in libdevice-cdio-perl 0.3.0-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
package Device::Cdio::Device;
require 5.8.6;
#
#  $Id$
#  See end for copyright and license.

=pod

=head1 NAME

Device::Cdio::Device - Class for disc and device aspects of Cdio.

=head1 SYNOPSIS

    use Device::Cdio::Device;
    $d = Device::Cdio::Device->new(-driver_id=>$perlcdio::DRIVER_DEVICE);
    $drive_name = $d->get_device();
    ($i_read_cap, $i_write_cap, $i_misc_cap) =  $d->get_drive_cap();

    $start_lsn = $d->get_first_track()->get_lsn();
    $end_lsn=$d->get_disc_last_lsn();
    $drc = $d->audio_play_lsn($start_lsn, $end_lsn);
    ($vendor, $model, $release, $drc) = $d->get_hwinfo();

=cut

use warnings;
use strict;
use Exporter;
use perlcdio;
use Device::Cdio::Util qw( _check_arg_count _extra_args _rearrange );
use Device::Cdio qw(convert_drive_cap_read convert_drive_cap_write 
		    convert_drive_cap_misc );
use Device::Cdio::Track;

$Device::Cdio::Device::VERSION   = $Device::Cdio::VERSION;
@Device::Cdio::Device::EXPORT    = qw( new );
@Device::Cdio::Device::EXPORT_OK = qw( close open );

=pod 

=head1 METHODS

=cut

=pod 

=head2 new

  new(source, driver_id, access_mode)->$device_object

Create a new Device object. Either parameter C<source>, C<driver_id>
or C<access_mode> can be C<undef>. In fact it is probably best to not
to give an C<access_mode> unless you know what you are doing.

=cut 
sub new {

  my($class,@p) = @_;

  my($source, $driver_id, $access_mode, @args) = 
      _rearrange(['SOURCE', 'DRIVER_ID', 'ACCESS_MODE'], @p);

  return undef if _extra_args(@args);

  my $self = {};
  $self->{cd} = undef;

  bless ($self, $class);

  $self->open($source, $driver_id,  $access_mode)
      if defined($source) || defined($driver_id);

  return $self;
}

=pod 

=head2 audio_pause

  audio_pause()-> $status

Pause playing CD through analog output.
The device status is returned.

=cut

sub audio_pause {
    my($self,@p) = @_;
    return $perlcdio::BAD_PARAMETER if !_check_arg_count($#_, 0);
    return perlcdio::audio_pause($self->{cd});
}

=pod

=head2 audio_play_lsn

  audio_play_lsn(start_lsn, end_lsn)-> $status
        
Playing CD through analog output at the given lsn to the ending lsn
The device status is returned.

=cut 

sub audio_play_lsn {
    my($self,@p) = @_;
    my($start_lsn, $end_lsn, @args) = 
	_rearrange(['START_LSN', 'END_LSN'], @p);
    return $perlcdio::BAD_PARAMETER if _extra_args(@args);
    return perlcdio::audio_play_lsn($self->{cd}, $start_lsn, $end_lsn);
}

=pod 

=head2 audio_resume

  audio_resume()-> $status

Resume playing an audio CD through the analog interface.
The device status is returned.

=cut

sub audio_resume {
    my($self,@p) = @_;
    return $perlcdio::BAD_PARAMETER if !_check_arg_count($#_, 0);
    return perlcdio::audio_resume($self->{cd});
}

=pod

=head2 audio_stop

  audio_stop()-> $status

Stop playing an audio CD through the analog interface.  The device
status is returned.

=cut

sub audio_stop {
    my($self,@p) = @_;
    return $perlcdio::BAD_PARAMETER if !_check_arg_count($#_, 0);
    return perlcdio::audio_stop($self->{cd});
}

=pod

=head2 close

  close()->bool

Free resources associated with cdio.  Call this when done using using
CD reading/control operations for the current device.

=cut

sub close {
    my($self,@p) = @_;
    return 0 if !_check_arg_count($#_, 0);
    if (defined($self->{cd})) {
	perlcdio::close($self->{cd});
    } else {
	print "***No object to close\n";
        $self->{cd} = undef;
	return 0;
    }
    return 1;
}

=pod

=head2 eject_media

  eject_media()->drc

Eject media in CD drive if there is a routine to do so.
status is returned.

=cut

sub eject_media {
    my($self,@p) = @_;
    return $perlcdio::BAD_PARAMETER if !_check_arg_count($#_, 0);
    my $drc = perlcdio::eject_media($self->{cd});
    $self->{cd} = undef;
    return $drc;
}

=pod

=head2 get_arg

  get_arg(key)->string

=cut

sub  get_arg {
    my($self,@p) = @_;
    my($key, @args) = 	_rearrange(['KEY'], @p);
    return undef if _extra_args(@args);
    return perlcdio::get_arg($self->{cd}, $key);
}

=pod

=head2 get_device

  get_device()->str

Get the default CD device.

If the CD object has an opened CD, return the name of the device used.
(In fact this is the same thing as issuing C<d-E<gt>get_arg("source")>).

If we haven't initialized a specific device driver, then find a
suitable one and return the default device for that.  

In some situations of drivers or OS's we can't find a CD device if
there is no media in it and it is possible for this routine to return
undef even though there may be a hardware CD-ROM.

=cut

sub get_device {
    my($self,@p) = @_;
    return undef if !_check_arg_count($#_, 0);
    return perlcdio::get_arg($self->{cd}, "source")
	if ($self->{cd});
    return perlcdio::get_device($self->{cd});
}

=pod

=head2 get_disc_last_lsn

  get_disc_last_lsn(self)->int

Get the LSN of the end of the CD. C<$perlcdio::INVALID_LSN> is
returned if there was an error.

=cut

sub get_disc_last_lsn {
    my($self,@p) = @_;
    return undef if !_check_arg_count($#_, 0);
    return perlcdio::get_disc_last_lsn($self->{cd});
}

=pod

=head2 get_disc_mode

  get_disc_mode() -> str

Get disc mode - the kind of CD: CD-DA, CD-ROM mode 1, CD-MIXED, etc.
that we've got. The notion of 'CD' is extended a little to include
DVD's.

=cut 

sub get_disc_mode {
    my($self,@p) = @_;
    return perlcdio::get_disc_mode($self->{cd});
}

=pod

=head2 get_drive_cap

  get_drive_cap()->(read_cap, write_cap, misc_cap)

Get drive capabilities of device.

In some situations of drivers or OS's we can't find a CD
device if there is no media in it. In this situation
capabilities will show up as empty even though there is a
hardware CD-ROM.  

=cut

sub get_drive_cap {
    my($self,@p) = @_;
    return (undef, undef, undef) if !_check_arg_count($#_, 0);
    my ($b_read_cap, $b_write_cap, $b_misc_cap) = 
	perlcdio::get_drive_cap($self->{cd});
    return (convert_drive_cap_read($b_read_cap),
	    convert_drive_cap_write($b_write_cap),
	    convert_drive_cap_misc($b_misc_cap));
}

=pod

=head2 get_drive_cap_dev

  get_drive_cap_dev(device=undef)->(read_cap, write_cap, misc_cap)
       
Get drive capabilities of device.
       
In some situations of drivers or OS's we can't find a CD
device if there is no media in it. In this situation
capabilities will show up as empty even though there is a
hardware CD-ROM.

=cut

### FIXME: combine into above by testing on the type of device.
sub get_drive_cap_dev {
    my($self,@p) = @_;
    my($device, @args) = _rearrange(['DEVICE'], @p);
    return (undef, undef, undef) if _extra_args(@args);

    my ($b_read_cap, $b_write_cap, $b_misc_cap) = 
	perlcdio::get_drive_cap_dev($device);
    return (convert_drive_cap_read($b_read_cap),
	    convert_drive_cap_write($b_write_cap),
	    convert_drive_cap_misc($b_misc_cap));
}

=pod

=head2 get_driver_name

  get_driver_name()-> string

return a string containing the name of the driver in use.
C<undef> is returned if there's an error.

=cut

sub get_driver_name {
    my($self,@p) = @_;
    return $perlcdio::BAD_PARAMETER if !_check_arg_count($#_, 0);
    return perlcdio::get_driver_name($self->{cd});
}

=pod

=head2 get_driver_id

  get_driver_id()-> int

=cut

sub get_driver_id {
    my($self, @p) = @_;
    return $perlcdio::BAD_PARAMETER if !_check_arg_count($#_, 0);
    return perlcdio::get_driver_id($self->{cd});
}

=pod

=head2 get_first_track

  get_first_track()->Track

return a Track object of the first track. C<$perlcdio::INVALID_TRACK>
or C<$perlcdio::BAD_PARAMETER> is returned if there was a problem.

Return the driver id of the driver in use.
if object has not been initialized or is None,
return C<$perlcdio::DRIVER_UNKNOWN>.

=cut

sub get_first_track {
    my($self, @p) = @_;
    return $perlcdio::BAD_PARAMETER if !_check_arg_count($#_, 0);
    return Device::Cdio::Track->new(-device=>$self->{cd}, 
				    -track=>perlcdio::get_first_track_num($self->{cd}));
}

=pod

=head2 get_hwinfo

  get_hwinfo()->(vendor, model, release, drc)

Get the CD-ROM hardware info via a SCSI MMC INQUIRY command.
An exception is raised if we had an error. 

=cut

sub get_hwinfo {
    my($self,@p) = @_;
    return $perlcdio::BAD_PARAMETER if !_check_arg_count($#_, 0);
    my ($hwinfo, $drc) = perlcdio::get_hwinfo($self->{cd});
    return (@$hwinfo, $drc);
}

=pod

=head2 audio_get_volume

    my($arr, $rc) = $dev->audio_get_volume;

Returns the volume settings of device's 4 channels and the device return code.
In scalar environmet only the device return code!
See perlcdio::driver_errmsg($rc) if $rc. 

=cut

sub audio_get_volume {
    my($self,@p) = @_;
    my ($vol,$drc) = perlcdio::audio_get_volume_levels($self->{cd});
    return wantarray ? ($vol,$drc) : $drc;
}

=pod

=head2 audio_set_volume

    $drc = $dev->audio_set_volume(lvl1, ...lvl4);

Set the volume levels of the channels 1-4. values from 0-255 are possible.
Use -1 when the value should be kept.
See perlcdio::driver_errmsg($drc) for return values (!= 0).

=cut

sub audio_set_volume {
    my($self,@p) = @_;
    my ($vol, $drc) = perlcdio::audio_get_volume_levels($self->{cd});
    for(my $i =0;$i<4;$i++) {
        if(defined $p[$i]) {
            @$vol[$i] = $p[$i] if $p[$i] > -1;
            @$vol[$i] = 255 if $p[$i] > 255;
        }
    }
    return perlcdio::audio_set_volume_levels($self->{cd}, @$vol[0], @$vol[1], 
        @$vol[2], @$vol[3]);
}

=pod 

=head2 get_disk_cdtext, get_track_cdtext

    $hash = $dev->get_disk_cdtext;
    $hash = $dev->get_track_cdtext(track);

Returns a hash reference hash->{cdtext_field}="text" 
if found any cdtext on disk;

=cut

sub get_disk_cdtext {
    my($self,@p) = @_;
    return perlcdio::get_cdtext($self->{cd},0);
}

sub get_track_cdtext {
    my($self,$t, @p) = @_;
    $t = 1 if !defined $t;
    return perlcdio::get_cdtext($self->{cd},$t);
}

=pod

=head2 get_cddb_discid

    $discid = $dev->get_cddb_discid;

Returns the calculated cddb discid integer. Usually used as hexstring!

=cut

sub get_cddb_discid {
    my($self,@p) = @_;
    return perlcdio::get_cddb_discid($self->{cd});
}

=pod

=head2 audio_get_status

    my($hash, $drc) = $dev->audio_get_status;

Returns a hash reference with the audio-subchannel-mmc status values:

    audio_status : value
    status_text  : audio_status as text
                (INVALID,ERROR,NO_STATUS,UNKNWON,playing,paused,completed)
    track : track number
    index : index in track
    msf time values as ints minutes, seconds,frames :
        abs_m,abs_s,abs_f  : total disk time played
        rel_m,rel_s,el_f   : track time played
    disk_s  : seconds disk played
    track_s : seconds track played
    address
    control

=cut

sub audio_get_status {
    my($self,@p) = @_;
    my ($ptr, $drc) = perlcdio::audio_get_status($self->{cd});
    return $ptr, $drc;
}

=pod

=head2 is_tray_open

    $dev->is_tray_open

returns true if tray seems open, 0 otherwise.

=cut

sub is_tray_open {
    my($self,@p) = @_;
    return perlcdio::get_tray_status($self->{cd});
}


=pod

=head2 get_joliet_level

  get_joliet_level()->int
       
Return the Joliet level recognized for cdio.
This only makes sense for something that has an ISO-9660
filesystem.

=cut

sub get_joliet_level {
    my($self,@p) = @_;
    return $perlcdio::BAD_PARAMETER if !_check_arg_count($#_, 0);
    return perlcdio::get_joliet_level($self->{cd});
}

=pod

=head2 get_last_session

  get_last_session(self) -> (track_lsn, drc)

Get the LSN of the first track of the last session of on the CD.

=cut

sub get_last_session {
    my($self,@p) = @_;
    return $perlcdio::BAD_PARAMETER if !_check_arg_count($#_, 0);
    return perlcdio::get_last_session($self->{cd});
}

=pod

=head2 get_last_track

  get_last_track()->Track

return a Track object of the last track. C<$perlcdio::INVALID_TRACK>
or C<$perlcdio::BAD_PARAMETER> is returned if there was a problem.

=cut

sub get_last_track {
    my($self, @p) = @_;
    return $perlcdio::BAD_PARAMETER if !_check_arg_count($#_, 0);
    return Device::Cdio::Track->new(-device=>$self->{cd},
				    -track=>perlcdio::get_last_track_num($self->{cd}));
}

=pod

=head2 get_mcn

get_mcn()->str
       
Get the media catalog number (MCN) from the CD.

=cut

sub get_mcn {
    my($self,@p) = @_;
    return $perlcdio::BAD_PARAMETER if !_check_arg_count($#_, 0);
    return perlcdio::get_mcn($self->{cd});
}

=pod

=head2 get_media_changed

  get_media_changed() -> int

Find out if media has changed since the last call.
Return 1 if media has changed since last call, 0 if not.
A negative number indicates the driver status error.

=cut

sub get_media_changed {
    my($self,@p) = @_;
    return $perlcdio::BAD_PARAMETER if !_check_arg_count($#_, 0);
    return perlcdio::get_media_changed($self->{cd});
}

=pod

=head2 guess_cd_type

$hash = $dev->guess_cd_type($lsn,$track);

Try to determine what kind of CD-image and/or filesystem we have at 
track $track. First argument is the start lsn of track $track. Returns a 
hash reference with following keys:

    cdio_fs_t     (enum cdio_fs_t from libcdio) FIXME: add text
    cdio_fs_cap_t (enum cdio_fs_cap_t from libcdio) FIXME: add text
    joliet_level  If has Joliet extensions, this is the associated level 
                    number (i.e. 1, 2, or 3). 
    iso_label      32 byte ISO fs label.
    isofs_size     size of ISO fs.
    UDFVerMajor    UDF fs version.
    UDFVerMinor    UDF fs version.

=cut

sub guess_cd_type {
    my($self, $session, $track, @p) = @_;
    return $perlcdio::BAD_PARAMETER if !_check_arg_count($#_, 2);
    return perlcdio::guess_cd_type($self->{cd}, $session, $track);
}

=pod

=head2 get_num_tracks

  get_num_tracks()->int

Return the number of tracks on the CD. 
C<$perlcdio::INVALID_TRACK> is raised on error.

=cut

sub get_num_tracks {
    my($self,@p) = @_;
    return $perlcdio::BAD_PARAMETER if !_check_arg_count($#_, 0);
    return  perlcdio::get_num_tracks($self->{cd});
}

=pod

=head2 get_track

  get_track(track_num)->track

Set a new track object of the current disc for the given track number.

=cut 

sub get_track {
    my($self,@p) = @_;
    my($track_num, @args) = _rearrange(['TRACK'], @p);
    return undef if _extra_args(@args);
    return Device::Cdio::Track->new(-device=>$self->{cd}, -track=>$track_num);
}

=pod

=head2 get_track_for_lsn

  get_track_for_lsn(LSN)->Track

Find the track which contains LSN.  undef is returned if the lsn
outside of the CD or if there was some error.

If the LSN is before the pregap of the first track, A track object
with a 0 track is returned.  Otherwise we return the track that spans
the lsn.

=cut

sub get_track_for_lsn {
    my($self,@p) = @_;
    my($lsn_num, @args) = _rearrange(['LSN'], @p);
    return undef if _extra_args(@args);
    my $track = perlcdio::get_last_track_num($self->{cd});
    return undef if ($track == $perlcdio::INVALID_TRACK);
    return Device::Cdio::Track->new(-device=>$self->{cd}, -track=>$track);
}

=pod

=head2 have_ATAPI

  have_ATAPI()->bool

return 1 if CD-ROM understand ATAPI commands.

=cut

sub have_ATAPI {
    my($self,@p) = @_;
    return $perlcdio::BAD_PARAMETER if !_check_arg_count($#_, 0);
    return perlcdio::have_ATAPI($self->{cd});
}

=pod

=head2 lseek

  lseek(offset, whence)->int

Reposition read offset. Similar to (if not the same as) libc's fseek()

offset is the amount to seek and whence is like corresponding
parameter in libc's lseek, e.g.  it should be SEEK_SET or SEEK_END.

the offset is returned or -1 on error.

=cut

sub lseek {
    my($self,@p) = @_;
    my($offset, $whence, @args) = _rearrange(['OFFSET', 'WHENCE'], @p);
    return -1 if _extra_args(@args);
    return perlcdio::lseek($self->{cd}, $offset, $whence);
}

=pod

=head2 open

  open(source=undef, driver_id=$libcdio::DRIVER_UNKNOWN, 
       access_mode=undef)->$cdio_obj

Sets up to read from place specified by source, driver_id and access
mode. This should be called before using any other routine except
those that act on a CD-ROM drive by name. It is implicitly called when
a new is done specifying a source or driver id.

If C<undef> is given as the source, we'll use the default driver device.
If C<undef> is given as the driver_id, we'll find a suitable device
driver.  Device is opened so that subsequent operations can be
performed. 

=cut

sub open {
    my($self,@p) = @_;
    my($source, $driver_id, $access_mode) = 
	_rearrange(['SOURCE', 'DRIVER_ID', 'ACCESS_MODE'], @p);
    
    $driver_id = $perlcdio::DRIVER_UNKNOWN 
	if !defined($driver_id);
    
    $self->close() if defined($self->{cd});
    $self->{cd} = perlcdio::open_cd($source, $driver_id, $access_mode);
}

=pod

=head2 read

  read(size)->(size, data)

Reads the next size bytes.
Similar to (if not the same as) libc's read()

The number of bytes read and the data is returned. 

=cut 

sub read {

    my($self,@p) = @_;
    my($size) = _rearrange(['SIZE'], @p);
    (my $data, $size) = perlcdio::read_cd($self->{cd}, $size);
    return wantarray ? ($data, $size) : $data;
}
    
=pod

=head2 read_data_blocks

  read_data_blocks(lsn, blocks=1)->($data, $size, $drc)

Reads a number of data sectors (AKA blocks).
        
lsn is sector to read, blocks is the number of bytes.

The size of the data will be a multiple of C<$perlcdio::ISO_BLOCKSIZE>.

The number of data, size of the data, and the return code status is
returned in an array context. In a scalar context just the data is
returned. C<undef> is returned as the data on error.

=cut 

sub read_data_blocks {

    my($self,@p) = @_;
    my($lsn, $read_mode, $blocks) = _rearrange(['LSN', 'BLOCKS'], @p);
    
    $blocks = 1 if !defined($blocks);

    my $size = $perlcdio::ISO_BLOCKSIZE * $blocks;
    (my $data, $size, my $drc) = 
	perlcdio::read_data_bytes($self->{cd}, $lsn, 
				  $perlcdio::ISO_BLOCKSIZE,
				  $size);

    if ($perlcdio::DRIVER_OP_SUCCESS == $drc) {
	return wantarray ? ($data, $size, $drc) : $data;
    } else {
	return wantarray ? (undef, undef, $drc) : undef;
    }

}
    
=pod

=head2 read_sectors

  read_sectors($lsn, $read_mode, $blocks=1)->($data, $size, $drc)
  read_sectors($lsn, $read_mode, $blocks=1)->$data

Reads a number of sectors (AKA blocks).

lsn is sector to read, bytes is the number of bytes.

If read_mode is C<$perlcdio::MODE_AUDIO>, the return data size will be
a multiple of C<$perlcdio::CDIO_FRAMESIZE_RAW> i_blocks bytes.

If read_mode is C<$perlcdio::MODE_DATA>, data will be a multiple of
C<$perlcdio::ISO_BLOCKSIZE>, C<$perlcdio::M1RAW_SECTOR_SIZE> or
C<$perlcdio::M2F2_SECTOR_SIZE> bytes depending on what mode the data is
in.

If read_mode is C<$perlcdio::MODE_M2F1>, data will be a multiple of
C<$perlcdio::M2RAW_SECTOR_SIZE> bytes.

If read_mode is C<$perlcdio::MODE_M2F2>, the return data size will be a
multiple of C<$perlcdio::CD_FRAMESIZE> bytes.

The number of data, size of the data, and the return code status is
returned in an array context. In a scalar context just the data is
returned. undef is returned as the data on error.

=cut

sub read_sectors {

    my($self,@p) = @_;
    my($lsn, $read_mode, $blocks) = 
	_rearrange(['LSN', 'READ_MODE', 'BLOCKS'], @p);
    
    $blocks = 1 if !defined($blocks);
    
    my $size;
    my $blocksize = $Device::Cdio::read_mode2blocksize{$read_mode};
    if (defined($blocksize)) {
	$size = $blocks * $blocksize;
    } else  {
	printf "Bad read mode %s\n", $read_mode;
	return undef;
    }
    (my $data, $size, my $drc) = 
	perlcdio::read_sectors($self->{cd}, $lsn, $read_mode, $size);

    if ($perlcdio::DRIVER_OP_SUCCESS == $drc) {
	$blocks = $size / $blocksize;
	return wantarray ? ($data, $size, $drc) : $data;
    } else {
	return wantarray ? (undef, undef, $drc) : undef;
    }
}

=pod

=head2 set_blocksize

  set_blocksize(blocksize) -> $status

Set the blocksize for subsequent reads.  The operation status code is
returned.

=cut 

sub set_blocksize {
    my($self,@p) = @_;
    my($blocksize, @args) = _rearrange(['BLOCKSIZE'], @p);
    return $perlcdio::BAD_PARAMETER if _extra_args(@args);
    return perlcdio::set_blocksize($self->{cd}, $blocksize);
}

=pod

=head2 set_speed

  set_speed(speed)->drc

The operation status code is returned.

=cut 

sub set_speed {
    my($self,@p) = @_;
    my($speed, @args) =  _rearrange(['SPEED'], @p);
    return $perlcdio::BAD_PARAMETER if _extra_args(@args);
    return perlcdio::set_speed($self->{cd}, $speed);
}

=pod

=head2 read_pvd

$pvd = $dev->read_pvd;

Reads and returns the ISO-9660 Primary Volume Descriptor (PVD) from the disk.
You can use perliso9660::get_pvd_type($pvd) ... methods to get the values.

=cut


sub read_pvd {
    my($self,@p) = @_;
    return  perlcdio::cdio_read_pvd($self->{cd});
}


1; # Magic true value required at the end of a module

__END__

1; # Magic true value required at the end of a module

__END__

=pod

=head1 SEE ALSO

L<Device::Cdio> for the top-level module, L<Device::Cdio::Track> for
track objects, and L<Device::Cdio::ISO9660> for working with ISO9660
filesystems.

L<perlcdio> is the lower-level interface to libcdio.

L<http://www.gnu.org/software/libcdio> has documentation on
libcdio including the a manual and the API via doxygen.

=head1 AUTHORS

Rocky Bernstein C<< <rocky at cpan.org> >>.

=head1 COPYRIGHT

Copyright (C) 2006, 2008 Rocky Bernstein <rocky@cpan.org>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

=cut