1 2 /*************************************************************************** 3 * __ __ _ ___________ * 4 * \ \ / /| |____ ____| * 5 * \ \ / / | | | | * 6 * \ \ /\ / / | | | | * 7 * \ \/ \/ / | | | | * 8 * \ /\ / | | | | * 9 * \/ \/ |_| |_| * 10 * * 11 * Wiimms ISO Tools * 12 * http://wit.wiimm.de/ * 13 * * 14 *************************************************************************** 15 * * 16 * This file is part of the WIT project. * 17 * Visit http://wit.wiimm.de/ for project details and sources. * 18 * * 19 * Copyright (c) 2009-2013 by Dirk Clemens <wiimm@wiimm.de> * 20 * * 21 *************************************************************************** 22 * * 23 * This program is free software; you can redistribute it and/or modify * 24 * it under the terms of the GNU General Public License as published by * 25 * the Free Software Foundation; either version 2 of the License, or * 26 * (at your option) any later version. * 27 * * 28 * This program is distributed in the hope that it will be useful, * 29 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 31 * GNU General Public License for more details. * 32 * * 33 * See file gpl-2.0.txt or http://www.gnu.org/licenses/gpl-2.0.txt * 34 * * 35 ***************************************************************************/ 36 37 #ifndef WIT_LIB_CISO_H 38 #define WIT_LIB_CISO_H 1 39 40 #include "types.h" 41 #include "libwbfs.h" 42 #include "lib-std.h" 43 44 // 45 /////////////////////////////////////////////////////////////////////////////// 46 /////////////// CISO options /////////////// 47 /////////////////////////////////////////////////////////////////////////////// 48 49 typedef enum enumChunkMode 50 { 51 CHUNK_MODE_ANY, // allow any values 52 CHUNK_MODE_32KIB, // force multiple of 32KiB 53 CHUNK_MODE_POW2, // force multiple of 32KiB and power of 2 54 CHUNK_MODE_ISO, // force values good for iso images and loaders 55 56 } enumChunkMode; 57 58 extern enumChunkMode opt_chunk_mode; 59 extern u32 opt_chunk_size; 60 extern bool force_chunk_size; 61 extern u32 opt_max_chunks; 62 63 // returns '1' on error, '0' else 64 int ScanChunkMode ( ccp source ); 65 int ScanMaxChunks ( ccp source ); 66 int ScanChunkSize ( ccp source ); 67 68 u32 CalcBlockSizeCISO ( u32 * result_n_blocks, off_t file_size ); 69 70 // 71 /////////////////////////////////////////////////////////////////////////////// 72 /////////////// CISO support /////////////// 73 /////////////////////////////////////////////////////////////////////////////// 74 75 enum // some constants 76 { 77 CISO_HEAD_SIZE = 0x8000, // total header size 78 CISO_MAP_SIZE = CISO_HEAD_SIZE - 8, // map size 79 CISO_MIN_BLOCK_SIZE = WII_SECTOR_SIZE, // minimal allowed block size 80 CISO_MAX_BLOCK_SIZE = 0x80000000, // maximal allowed block size 81 82 CISO_WR_MIN_BLOCK_SIZE = 1*MiB, // minimal block size if writing 83 CISO_WR_MAX_BLOCK = 0x2000, // maximal blocks if writing 84 CISO_WR_MIN_HOLE_SIZE = 0x1000, // min hole size for sparse cheking 85 }; 86 87 typedef u16 CISO_Map_t; 88 #define CISO_UNUSED_BLOCK ((CISO_Map_t)~0) 89 90 //----------------------------------------------------------------------------- 91 92 typedef struct CISO_Head_t 93 { 94 u8 magic[4]; // "CISO" 95 u32 block_size; // stored as litte endian (not network byte order) 96 u8 map[CISO_MAP_SIZE]; // 0=unused, 1=used 97 98 } __attribute__ ((packed)) CISO_Head_t; 99 100 //----------------------------------------------------------------------------- 101 102 typedef struct CISO_Info_t 103 { 104 u32 block_size; // the block size 105 u32 used_blocks; // number of used blocks 106 u32 needed_blocks; // number of needed blocks 107 u32 map_size; // number of alloced elements for 'map' 108 CISO_Map_t * map; // NULL or map with 'map_size' elements 109 off_t max_file_off; // maximal file offset 110 off_t max_virt_off; // maximal virtiual iso offset 111 112 } CISO_Info_t; 113 114 // 115 /////////////////////////////////////////////////////////////////////////////// 116 /////////////// interface for CISO files /////////////// 117 /////////////////////////////////////////////////////////////////////////////// 118 119 // Initialize CISO_Info_t, copy and validate data from CISO_Head_t if not NULL 120 enumError InitializeCISO ( CISO_Info_t * ci, CISO_Head_t * ch ); 121 122 // Setup CISO_Info_t, copy and validate data from CISO_Head_t if not NULL 123 enumError SetupCISO ( CISO_Info_t * ci, CISO_Head_t * ch ); 124 125 // free all dynamic data and Clear data 126 void ResetCISO ( CISO_Info_t * ci ); 127 128 //----------------------------------------------------------------------------- 129 130 #undef SUPERFILE 131 #define SUPERFILE struct SuperFile_t 132 SUPERFILE; 133 134 // CISO reading support 135 enumError SetupReadCISO ( SUPERFILE * sf ); 136 enumError ReadCISO ( SUPERFILE * sf, off_t off, void * buf, size_t size ); 137 off_t DataBlockCISO ( SUPERFILE * sf, off_t off, size_t hint_align, off_t * block_size ); 138 139 // CISO writing support 140 enumError SetupWriteCISO ( SUPERFILE * sf ); 141 enumError TermWriteCISO ( SUPERFILE * sf ); 142 enumError WriteCISO ( SUPERFILE * sf, off_t off, const void * buf, size_t size ); 143 enumError WriteSparseCISO( SUPERFILE * sf, off_t off, const void * buf, size_t size ); 144 enumError WriteZeroCISO ( SUPERFILE * sf, off_t off, size_t size ); 145 146 #undef SUPERFILE 147 148 // 149 /////////////////////////////////////////////////////////////////////////////// 150 /////////////// END /////////////// 151 /////////////////////////////////////////////////////////////////////////////// 152 153 #endif // WIT_LIB_CISO_H 154 155