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 | * |
Dave Chapman | e332f4c | 2007-02-05 01:20:20 +0000 | [diff] [blame] | 10 | * Copyright (C) 2006-2007 Dave Chapman |
Dave Chapman | 4b7e1e0 | 2006-12-13 09:02:18 +0000 | [diff] [blame] | 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> |
Dave Chapman | b045a24 | 2007-02-16 20:45:00 +0000 | [diff] [blame] | 24 | #include <unistd.h> |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame] | 25 | |
Dave Chapman | 4b7e1e0 | 2006-12-13 09:02:18 +0000 | [diff] [blame] | 26 | #ifdef __WIN32__ |
| 27 | #include <windows.h> |
| 28 | #else |
| 29 | #define HANDLE int |
| 30 | #define O_BINARY 0 |
| 31 | #endif |
| 32 | |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame] | 33 | /* The maximum number of images in a firmware partition - a guess... */ |
| 34 | #define MAX_IMAGES 10 |
| 35 | |
| 36 | enum firmwaretype_t { |
| 37 | FTYPE_OSOS = 0, |
| 38 | FTYPE_RSRC, |
| 39 | FTYPE_AUPD, |
| 40 | FTYPE_HIBE |
| 41 | }; |
| 42 | |
| 43 | struct ipod_directory_t { |
| 44 | enum firmwaretype_t ftype; |
| 45 | int id; |
| 46 | uint32_t devOffset; /* Offset of image relative to one sector into bootpart*/ |
| 47 | uint32_t len; |
| 48 | uint32_t addr; |
| 49 | uint32_t entryOffset; |
| 50 | uint32_t chksum; |
| 51 | uint32_t vers; |
| 52 | uint32_t loadAddr; |
| 53 | }; |
| 54 | |
Dave Chapman | 2cc80f5 | 2007-07-29 21:19:14 +0000 | [diff] [blame] | 55 | /* A fake partition type - DOS partition tables can't include HFS partitions */ |
| 56 | #define PARTTYPE_HFS 0xffff |
| 57 | |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame] | 58 | struct partinfo_t { |
Dave Chapman | 35735c66 | 2007-07-27 20:51:36 +0000 | [diff] [blame] | 59 | uint32_t start; /* first sector (LBA) */ |
| 60 | uint32_t size; /* number of sectors */ |
| 61 | uint32_t type; |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | struct ipod_t { |
| 65 | HANDLE dh; |
| 66 | char diskname[4096]; |
| 67 | int sector_size; |
Dave Chapman | 56780e3 | 2007-06-16 22:32:57 +0000 | [diff] [blame] | 68 | int sectors_per_track; |
| 69 | int num_heads; |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame] | 70 | struct ipod_directory_t ipod_directory[MAX_IMAGES]; |
| 71 | int nimages; |
| 72 | off_t diroffset; |
| 73 | off_t start; /* Offset in bytes of firmware partition from start of disk */ |
| 74 | off_t fwoffset; /* Offset in bytes of start of firmware images from start of disk */ |
| 75 | struct partinfo_t pinfo[4]; |
| 76 | int modelnum; |
| 77 | char* modelname; |
| 78 | char* modelstr; |
Dave Chapman | a6d68bd | 2007-02-10 20:09:23 +0000 | [diff] [blame] | 79 | char* targetname; |
Dave Chapman | 6e641e8 | 2007-02-05 18:29:39 +0000 | [diff] [blame] | 80 | int macpod; |
Dave Chapman | bdc27ff | 2007-02-08 18:05:50 +0000 | [diff] [blame] | 81 | #ifdef WITH_BOOTOBJS |
| 82 | unsigned char* bootloader; |
| 83 | int bootloader_len; |
| 84 | #endif |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
Dave Chapman | 4b7e1e0 | 2006-12-13 09:02:18 +0000 | [diff] [blame] | 87 | void print_error(char* msg); |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame] | 88 | int ipod_open(struct ipod_t* ipod, int silent); |
| 89 | int ipod_reopen_rw(struct ipod_t* ipod); |
| 90 | int ipod_close(struct ipod_t* ipod); |
| 91 | int ipod_seek(struct ipod_t* ipod, unsigned long pos); |
Dave Chapman | 2cc80f5 | 2007-07-29 21:19:14 +0000 | [diff] [blame] | 92 | ssize_t ipod_read(struct ipod_t* ipod, unsigned char* buf, int nbytes); |
| 93 | ssize_t ipod_write(struct ipod_t* ipod, unsigned char* buf, int nbytes); |
Dave Chapman | 4b7e1e0 | 2006-12-13 09:02:18 +0000 | [diff] [blame] | 94 | int ipod_alloc_buffer(unsigned char** sectorbuf, int bufsize); |
| 95 | |
Dave Chapman | 56780e3 | 2007-06-16 22:32:57 +0000 | [diff] [blame] | 96 | /* In fat32format.c */ |
| 97 | int format_partition(struct ipod_t* ipod, int partition); |
| 98 | |
Dave Chapman | 4b7e1e0 | 2006-12-13 09:02:18 +0000 | [diff] [blame] | 99 | #endif |