Dave Chapman | 4b7e1e0 | 2006-12-13 09:02:18 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2006 Dave Chapman |
| 11 | * |
| 12 | * All files in this archive are subject to the GNU General Public License. |
| 13 | * See the file COPYING in the source tree root for full license agreement. |
| 14 | * |
| 15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 16 | * KIND, either express or implied. |
| 17 | * |
| 18 | ****************************************************************************/ |
| 19 | |
| 20 | #ifndef __IPODIO_H |
| 21 | #define __IPODIO_H |
| 22 | |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame^] | 23 | #include <stdint.h> |
| 24 | |
Dave Chapman | 4b7e1e0 | 2006-12-13 09:02:18 +0000 | [diff] [blame] | 25 | #ifdef __WIN32__ |
| 26 | #include <windows.h> |
| 27 | #else |
| 28 | #define HANDLE int |
| 29 | #define O_BINARY 0 |
| 30 | #endif |
| 31 | |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame^] | 32 | /* The maximum number of images in a firmware partition - a guess... */ |
| 33 | #define MAX_IMAGES 10 |
| 34 | |
| 35 | enum firmwaretype_t { |
| 36 | FTYPE_OSOS = 0, |
| 37 | FTYPE_RSRC, |
| 38 | FTYPE_AUPD, |
| 39 | FTYPE_HIBE |
| 40 | }; |
| 41 | |
| 42 | struct ipod_directory_t { |
| 43 | enum firmwaretype_t ftype; |
| 44 | int id; |
| 45 | uint32_t devOffset; /* Offset of image relative to one sector into bootpart*/ |
| 46 | uint32_t len; |
| 47 | uint32_t addr; |
| 48 | uint32_t entryOffset; |
| 49 | uint32_t chksum; |
| 50 | uint32_t vers; |
| 51 | uint32_t loadAddr; |
| 52 | }; |
| 53 | |
| 54 | struct partinfo_t { |
| 55 | unsigned long start; /* first sector (LBA) */ |
| 56 | unsigned long size; /* number of sectors */ |
| 57 | unsigned char type; |
| 58 | }; |
| 59 | |
| 60 | struct ipod_t { |
| 61 | HANDLE dh; |
| 62 | char diskname[4096]; |
| 63 | int sector_size; |
| 64 | struct ipod_directory_t ipod_directory[MAX_IMAGES]; |
| 65 | int nimages; |
| 66 | off_t diroffset; |
| 67 | off_t start; /* Offset in bytes of firmware partition from start of disk */ |
| 68 | off_t fwoffset; /* Offset in bytes of start of firmware images from start of disk */ |
| 69 | struct partinfo_t pinfo[4]; |
| 70 | int modelnum; |
| 71 | char* modelname; |
| 72 | char* modelstr; |
| 73 | }; |
| 74 | |
Dave Chapman | 4b7e1e0 | 2006-12-13 09:02:18 +0000 | [diff] [blame] | 75 | void print_error(char* msg); |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame^] | 76 | int ipod_open(struct ipod_t* ipod, int silent); |
| 77 | int ipod_reopen_rw(struct ipod_t* ipod); |
| 78 | int ipod_close(struct ipod_t* ipod); |
| 79 | int ipod_seek(struct ipod_t* ipod, unsigned long pos); |
| 80 | int ipod_read(struct ipod_t* ipod, unsigned char* buf, int nbytes); |
| 81 | int ipod_write(struct ipod_t* ipod, unsigned char* buf, int nbytes); |
Dave Chapman | 4b7e1e0 | 2006-12-13 09:02:18 +0000 | [diff] [blame] | 82 | int ipod_alloc_buffer(unsigned char** sectorbuf, int bufsize); |
| 83 | |
| 84 | #endif |