1 /*
2     Copyright (C) 2005, 2006, 2008 Rocky Bernstein <rocky@gnu.org>
3 
4     This program is free software: you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation, either version 3 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 /** \file read.hpp
19  *
20  *  \brief methods relating to reading blocks of Compact Discs. This file
21  *  should not be #included directly.
22  */
23 
24 /*!
25   Reposition read offset
26   Similar to (if not the same as) libc's lseek()
27 
28   @param offset amount to seek
29   @param whence  like corresponding parameter in libc's lseek, e.g.
30   SEEK_SET or SEEK_END.
31   @return (off_t) -1 on error.
32 */
33 
lseek(off_t offset,int whence)34 off_t lseek(off_t offset, int whence)
35 {
36   return cdio_lseek(p_cdio, offset, whence);
37 }
38 
39 /*!
40   Reads into buf the next size bytes.
41   Similar to (if not the same as) libc's read()
42 
43   @param p_buf place to read data into. The caller should make sure
44   this location can store at least i_size bytes.
45   @param i_size number of bytes to read
46 
47   @return (ssize_t) -1 on error.
48 */
read(void * p_buf,size_t i_size)49 ssize_t read(void *p_buf, size_t i_size)
50 {
51   return cdio_read(p_cdio, p_buf, i_size);
52 }
53 
54 /*!
55   Reads a number of sectors (AKA blocks).
56 
57   @param p_buf place to read data into. The caller should make sure
58   this location is large enough. See below for size information.
59   @param read_mode the kind of "mode" to use in reading.
60   @param i_lsn sector to read
61   @param i_blocks number of sectors to read
62 
63   If read_mode is CDIO_MODE_AUDIO,
64     *p_buf should hold at least CDIO_FRAMESIZE_RAW * i_blocks bytes.
65 
66   If read_mode is CDIO_MODE_DATA,
67     *p_buf should hold at least i_blocks times either ISO_BLOCKSIZE,
68     M1RAW_SECTOR_SIZE or M2F2_SECTOR_SIZE depending on the kind of
69     sector getting read. If you don't know whether you have a Mode 1/2,
70     Form 1/ Form 2/Formless sector best to reserve space for the maximum
71     which is M2RAW_SECTOR_SIZE.
72 
73   If read_mode is CDIO_MODE_M2F1,
74     *p_buf should hold at least M2RAW_SECTOR_SIZE * i_blocks bytes.
75 
76   If read_mode is CDIO_MODE_M2F2,
77     *p_buf should hold at least CDIO_CD_FRAMESIZE * i_blocks bytes.
78 
79   A DriverOpException is raised on error.
80 */
81 
readSectors(void * p_buf,lsn_t i_lsn,cdio_read_mode_t read_mode,uint32_t i_blocks=1)82 void readSectors(void *p_buf, lsn_t i_lsn, cdio_read_mode_t read_mode,
83 		 uint32_t i_blocks=1)
84 {
85   driver_return_code_t drc = cdio_read_sectors(p_cdio, p_buf, i_lsn, read_mode,
86 					       i_blocks);
87   possible_throw_device_exception(drc);
88 }
89 
90 /*!
91   Reads a number of data sectors (AKA blocks).
92 
93   @param p_buf place to read data into. The caller should make sure
94   this location is large enough. See below for size information.
95 
96   *p_buf should hold at least i_blocks times either ISO_BLOCKSIZE,
97   M1RAW_SECTOR_SIZE or M2F2_SECTOR_SIZE depending on the kind of
98   sector getting read. If you don't know whether you have a Mode 1/2,
99   Form 1/ Form 2/Formless sector best to reserve space for the maximum
100   which is M2RAW_SECTOR_SIZE.
101 
102   @param i_lsn sector to read
103 
104   @param i_blocksize size of block. Should be either CDIO_CD_FRAMESIZE,
105   M2RAW_SECTOR_SIZE, or M2F2_SECTOR_SIZE. See comment above under p_buf.
106 
107   @param i_blocks number of sectors to read
108 
109   A DriverOpException is raised on error.
110 
111 */
112 
readDataBlocks(void * p_buf,lsn_t i_lsn,uint16_t i_blocksize,uint32_t i_blocks=1)113 void readDataBlocks(void *p_buf, lsn_t i_lsn, uint16_t i_blocksize,
114 		    uint32_t i_blocks=1)
115 {
116   driver_return_code_t drc = cdio_read_data_sectors (p_cdio, p_buf, i_lsn,
117 						     i_blocksize, i_blocks);
118   possible_throw_device_exception(drc);
119 }
120