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