1 /* Copyright 2007-2012 Fredrik Wikstrom. All rights reserved.
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
14 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 ** POSSIBILITY OF SUCH DAMAGE.
28 ** This plugin handles 2352 bytes per block .iso files as Generic plugin is no
29 ** longer able to handle these
33 #define __EXEC_NOLIBBASE__
34 #define __DOS_NOLIBBASE__
37 #define USED_PLUGIN_API_VERSION 8
38 #include <devices/diskimage.h>
39 #include <proto/exec.h>
40 #include <proto/dos.h>
42 #include "device_locale.h"
43 #include <SDI_compiler.h>
44 #include "rev/diskimage.device_rev.h"
48 extern struct DiskImagePlugin iso_plugin
;
50 PLUGIN_TABLE(&iso_plugin
)
58 ULONG header_part
, ecc_part
;
61 BOOL
ISO_Init (struct DiskImagePlugin
*Self
, const struct PluginData
*data
);
62 BOOL
ISO_CheckImage (struct DiskImagePlugin
*Self
, BPTR file
, CONST_STRPTR name
, QUAD file_size
,
63 const UBYTE
*test
, LONG testsize
);
64 APTR
ISO_OpenImage (struct DiskImagePlugin
*Self
, APTR unit
, BPTR file
, CONST_STRPTR name
);
65 void Generic_CloseImage (struct DiskImagePlugin
*Self
, APTR image_ptr
);
66 LONG
Generic_Geometry (struct DiskImagePlugin
*Self
, APTR image_ptr
, struct DriveGeometry
*dg
);
67 LONG
ISO_Read (struct DiskImagePlugin
*Self
, APTR image_ptr
, struct IOStdReq
*io
);
69 struct DiskImagePlugin iso_plugin
= {
70 PLUGIN_NODE(-125, "ISO"),
89 static struct Library
*SysBase
;
90 static struct Library
*DOSBase
;
91 static struct DIPluginIFace
*IPlugin
;
93 BOOL
ISO_Init (struct DiskImagePlugin
*Self
, const struct PluginData
*data
) {
94 SysBase
= data
->SysBase
;
95 DOSBase
= data
->DOSBase
;
96 IPlugin
= data
->IPlugin
;
100 static const UBYTE sync_header
[16] = {
101 0x00, 0xFF, 0xFF, 0xFF,
102 0xFF, 0xFF, 0xFF, 0xFF,
103 0xFF, 0xFF, 0xFF, 0x00,
104 0x00, 0x02, 0x00, 0x01
107 BOOL
ISO_CheckImage (struct DiskImagePlugin
*Self
, BPTR file
, CONST_STRPTR name
, QUAD file_size
,
108 const UBYTE
*test
, LONG testsize
)
110 return testsize
>= 16 && !memcmp(test
, sync_header
, 16);
113 APTR
ISO_OpenImage (struct DiskImagePlugin
*Self
, APTR unit
, BPTR file
, CONST_STRPTR name
) {
115 LONG error
= NO_ERROR
;
117 struct ISOImage
*image
= NULL
;
119 file_size
= GetFileSize(file
);
120 if (file_size
== -1) {
125 image
= AllocVec(sizeof(*image
), MEMF_CLEAR
);
127 error
= ERROR_NO_FREE_STORE
;
131 image
->total_bytes
= file_size
;
133 image
->block_size
= 2048;
134 image
->sector_size
= 2352;
135 image
->header_part
= 16;
136 image
->ecc_part
= image
->sector_size
- image
->header_part
- image
->block_size
;
137 image
->total_blocks
= image
->total_bytes
/ image
->sector_size
;
144 Plugin_CloseImage(Self
, image
);
149 IPlugin_SetDiskImageError(unit
, error
, 0);
154 LONG
ISO_Read (struct DiskImagePlugin
*Self
, APTR image_ptr
, struct IOStdReq
*io
) {
155 struct ISOImage
*image
= image_ptr
;
156 BPTR file
= image
->file
;
159 LONG size
, read_size
;
163 offset
= ((UQUAD
)io
->io_Offset
)|((UQUAD
)io
->io_Actual
<< 32);
164 buffer
= io
->io_Data
;
165 size
= io
->io_Length
;
168 if (offset
& 0x7ff) return IOERR_BADADDRESS
;
169 if (size
& 0x7ff) return IOERR_BADLENGTH
;
171 start_blk
= offset
>> 11;
172 num_blks
= size
>> 11;
174 if (!ChangeFilePosition(file
, start_blk
*image
->sector_size
+ image
->header_part
, OFFSET_BEGINNING
)) {
175 return TDERR_SeekError
;
181 read_size
= FRead(file
, buffer
, 1, size
);
182 if (read_size
== 0) {
183 return IOERR_BADLENGTH
;
184 } else if (read_size
== -1) {
185 return IPlugin_DOS2IOErr(IoErr());
189 io
->io_Actual
+= read_size
;
191 if (num_blks
&& !ChangeFilePosition(file
, image
->ecc_part
+ image
->header_part
, OFFSET_CURRENT
)) {
192 return TDERR_SeekError
;
195 return IOERR_SUCCESS
;