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_WDF_H 38 #define WIT_LIB_WDF_H 1 39 40 #include "types.h" 41 #include "lib-std.h" 42 43 // 44 /////////////////////////////////////////////////////////////////////////////// 45 /////////////// WDF definitions /////////////// 46 /////////////////////////////////////////////////////////////////////////////// 47 48 // First a magic is defined to identify a WDF clearly. The magic should never be 49 // a possible Wii ISO image identification. Wii ISO images starts with the ID6. 50 // And so the WDF magic contains one contral character (CTRL-A) within. 51 52 #define WDF_MAGIC "WII\1DISC" 53 #define WDF_MAGIC_SIZE 8 54 #define WDF_COMPATIBLE 1 55 56 // WDF head sizes 57 58 #define WDF_VERSION1_SIZE sizeof(WDF_Head_t) 59 #define WDF_VERSION2_SIZE sizeof(WDF_Head_t) 60 61 // the minimal size of holes in bytes that will be detected. 62 63 #define WDF_MIN_HOLE_SIZE (sizeof(WDF_Chunk_t)+sizeof(WDF_Hole_t)) 64 65 // WDF hole detection type 66 typedef u32 WDF_Hole_t; 67 68 // 69 /////////////////////////////////////////////////////////////////////////////// 70 /////////////// struct WDF_Head_t /////////////// 71 /////////////////////////////////////////////////////////////////////////////// 72 // This is the header of a WDF v1. 73 // Remember: Within a file the data is stored in network byte order (big endian) 74 75 typedef struct WDF_Head_t // split param replaced by others, 2012-09 76 { 77 // magic and version number 78 char magic[WDF_MAGIC_SIZE]; // WDF_MAGIC, what else! 79 u32 wdf_version; // WDF_VERSION 80 81 #if 0 // first head definition, WDF v1 before 2012-09 82 // split file support (not used, values are *,0,1) 83 u32 split_file_id; // for plausibility checks 84 u32 split_file_index; // zero based index ot this file 85 u32 split_file_num_of; // number of split files 86 #else 87 u32 wdf_head_size; // size of version related WDF_Head_t 88 // (WDF v1: ignored) 89 u32 align_factor; // info: all data is aligned with a multiple of # 90 // (WDF v1: always 0, ignored) 91 u32 wdf_compatible; // this file is compatible down to version # 92 // (WDF v1: always 1) 93 #endif 94 95 // virtual file infos 96 u64 file_size; // the size of the virtual file 97 98 // data size of this file 99 u64 data_size; // the ISO data size in this file 100 // (without header and chunk table) 101 // chunks 102 #if 0 // first head definition, WDF v1 before 2012-09 103 u32 chunk_split_file; // which split file contains the chunk table 104 #else 105 u32 chunk_size_factor; // info: all chunk sizes are multiple of # 106 // (WDF v1: always 0, ignored) 107 #endif 108 u32 chunk_n; // total number of data chunks 109 u64 chunk_off; // the 'MAGIC + chunk_table' file offset 110 111 } __attribute__ ((packed)) WDF_Head_t; 112 113 // 114 /////////////////////////////////////////////////////////////////////////////// 115 /////////////// struct WDF_Chunk_t /////////////// 116 /////////////////////////////////////////////////////////////////////////////// 117 // This is the chunk info of WDF. 118 // Remember: Within a file the data is stored in network byte order (big endian) 119 120 typedef struct WDF_Chunk_t 121 { 122 // split_file_index is obsolete in WDF v2 123 u32 ignored_split_file_index; // which split file contains that chunk 124 // (WDF v1: always 0, ignored) 125 u64 file_pos; // the virtual ISO file position 126 u64 data_off; // the data file offset 127 u64 data_size; // the data size 128 129 } __attribute__ ((packed)) WDF_Chunk_t; 130 131 // 132 /////////////////////////////////////////////////////////////////////////////// 133 /////////////// interface for WDF_Head_t /////////////// 134 /////////////////////////////////////////////////////////////////////////////// 135 136 // initialize WH 137 void InitializeWH ( WDF_Head_t * wh ); 138 139 // convert WH data, src + dest may point to same structure 140 void ConvertToNetworkWH ( WDF_Head_t * dest, const WDF_Head_t * src ); 141 void ConvertToHostWH ( WDF_Head_t * dest, const WDF_Head_t * src ); 142 143 // helpers 144 size_t GetHeadSizeWDF ( u32 version ); 145 size_t AdjustHeaderWDF ( WDF_Head_t * wh ); 146 147 /////////////////////////////////////////////////////////////////////////////// 148 /////////////// interface for WDF_Chunk_t /////////////// 149 /////////////////////////////////////////////////////////////////////////////// 150 151 // initialize WC 152 void InitializeWC ( WDF_Chunk_t * wc, int n_elem ); 153 154 // convert WC data, src + dest may point to same structure 155 void ConvertToNetworkWC ( WDF_Chunk_t * dest, const WDF_Chunk_t * src ); 156 void ConvertToHostWC ( WDF_Chunk_t * dest, const WDF_Chunk_t * src ); 157 158 // 159 /////////////////////////////////////////////////////////////////////////////// 160 /////////////// SuperFile_t interface /////////////// 161 /////////////////////////////////////////////////////////////////////////////// 162 163 #undef SUPERFILE 164 #define SUPERFILE struct SuperFile_t 165 SUPERFILE; 166 167 // WDF reading support 168 enumError SetupReadWDF ( SUPERFILE * sf ); 169 enumError ReadWDF ( SUPERFILE * sf, off_t off, void * buf, size_t size ); 170 off_t DataBlockWDF ( SUPERFILE * sf, off_t off, size_t hint_align, off_t * block_size ); 171 172 // WDF writing support 173 enumError SetupWriteWDF ( SUPERFILE * sf ); 174 enumError TermWriteWDF ( SUPERFILE * sf ); 175 enumError WriteWDF ( SUPERFILE * sf, off_t off, const void * buf, size_t size ); 176 enumError WriteSparseWDF( SUPERFILE * sf, off_t off, const void * buf, size_t size ); 177 enumError WriteZeroWDF ( SUPERFILE * sf, off_t off, size_t size ); 178 179 // chunk managment 180 WDF_Chunk_t * NeedChunkWDF ( SUPERFILE * sf, int at_index ); 181 182 #undef SUPERFILE 183 184 // 185 /////////////////////////////////////////////////////////////////////////////// 186 /////////////// etc /////////////// 187 /////////////////////////////////////////////////////////////////////////////// 188 189 int SetWDF2Mode ( uint c, ccp align ); 190 int ScanOptWDFAlign ( ccp arg ); 191 192 // 193 /////////////////////////////////////////////////////////////////////////////// 194 /////////////// END /////////////// 195 /////////////////////////////////////////////////////////////////////////////// 196 197 #endif // WIT_LIB_WDF_H 198 199