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> |
Dominik Riebeling | 5ffd2f7 | 2011-12-08 21:59:13 +0000 | [diff] [blame] | 26 | #if !defined(_WIN32) |
Dave Chapman | b045a24 | 2007-02-16 20:45:00 +0000 | [diff] [blame] | 27 | #include <unistd.h> |
Dominik Riebeling | 5ffd2f7 | 2011-12-08 21:59:13 +0000 | [diff] [blame] | 28 | #elif defined(_MSC_VER) |
| 29 | /* MSVC uses a different name for ssize_t */ |
| 30 | #define ssize_t SSIZE_T |
| 31 | #endif |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame] | 32 | |
Dominik Riebeling | 5ffd2f7 | 2011-12-08 21:59:13 +0000 | [diff] [blame] | 33 | #if defined(__WIN32__) || defined(_WIN32) |
Dave Chapman | 4b7e1e0 | 2006-12-13 09:02:18 +0000 | [diff] [blame] | 34 | #include <windows.h> |
| 35 | #else |
| 36 | #define HANDLE int |
| 37 | #define O_BINARY 0 |
| 38 | #endif |
| 39 | |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame] | 40 | /* The maximum number of images in a firmware partition - a guess... */ |
| 41 | #define MAX_IMAGES 10 |
| 42 | |
| 43 | enum firmwaretype_t { |
| 44 | FTYPE_OSOS = 0, |
| 45 | FTYPE_RSRC, |
| 46 | FTYPE_AUPD, |
Dave Chapman | 8e95cc4 | 2009-10-13 08:02:59 +0000 | [diff] [blame] | 47 | FTYPE_HIBE, |
| 48 | FTYPE_OSBK |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | struct ipod_directory_t { |
| 52 | enum firmwaretype_t ftype; |
| 53 | int id; |
| 54 | uint32_t devOffset; /* Offset of image relative to one sector into bootpart*/ |
| 55 | uint32_t len; |
| 56 | uint32_t addr; |
| 57 | uint32_t entryOffset; |
| 58 | uint32_t chksum; |
| 59 | uint32_t vers; |
| 60 | uint32_t loadAddr; |
| 61 | }; |
| 62 | |
Dave Chapman | 2cc80f5 | 2007-07-29 21:19:14 +0000 | [diff] [blame] | 63 | /* A fake partition type - DOS partition tables can't include HFS partitions */ |
| 64 | #define PARTTYPE_HFS 0xffff |
| 65 | |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame] | 66 | struct partinfo_t { |
Dave Chapman | 35735c66 | 2007-07-27 20:51:36 +0000 | [diff] [blame] | 67 | uint32_t start; /* first sector (LBA) */ |
| 68 | uint32_t size; /* number of sectors */ |
| 69 | uint32_t type; |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | struct ipod_t { |
Dominik Riebeling | 24e37dd | 2012-12-23 23:30:57 +0100 | [diff] [blame] | 73 | unsigned char* sectorbuf; |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame] | 74 | HANDLE dh; |
| 75 | char diskname[4096]; |
| 76 | int sector_size; |
Dave Chapman | 56780e3 | 2007-06-16 22:32:57 +0000 | [diff] [blame] | 77 | int sectors_per_track; |
| 78 | int num_heads; |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame] | 79 | struct ipod_directory_t ipod_directory[MAX_IMAGES]; |
| 80 | int nimages; |
Dave Chapman | 8e95cc4 | 2009-10-13 08:02:59 +0000 | [diff] [blame] | 81 | int ososimage; |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame] | 82 | off_t diroffset; |
| 83 | off_t start; /* Offset in bytes of firmware partition from start of disk */ |
| 84 | off_t fwoffset; /* Offset in bytes of start of firmware images from start of disk */ |
| 85 | struct partinfo_t pinfo[4]; |
| 86 | int modelnum; |
| 87 | char* modelname; |
| 88 | char* modelstr; |
Dave Chapman | a6d68bd | 2007-02-10 20:09:23 +0000 | [diff] [blame] | 89 | char* targetname; |
Dave Chapman | 6e641e8 | 2007-02-05 18:29:39 +0000 | [diff] [blame] | 90 | int macpod; |
Dave Chapman | 1eca02d | 2009-08-04 20:32:30 +0000 | [diff] [blame] | 91 | char* xmlinfo; /* The XML Device Information (if available) */ |
| 92 | int xmlinfo_len; |
| 93 | int ramsize; /* The amount of RAM in the ipod (if available) */ |
Dave Chapman | bdc27ff | 2007-02-08 18:05:50 +0000 | [diff] [blame] | 94 | #ifdef WITH_BOOTOBJS |
| 95 | unsigned char* bootloader; |
| 96 | int bootloader_len; |
| 97 | #endif |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
Dominik Riebeling | 3e489c1 | 2009-11-08 13:38:10 +0000 | [diff] [blame] | 100 | void ipod_print_error(char* msg); |
Dave Chapman | 31aa452 | 2007-02-04 11:42:11 +0000 | [diff] [blame] | 101 | int ipod_open(struct ipod_t* ipod, int silent); |
| 102 | int ipod_reopen_rw(struct ipod_t* ipod); |
| 103 | int ipod_close(struct ipod_t* ipod); |
| 104 | int ipod_seek(struct ipod_t* ipod, unsigned long pos); |
Dave Chapman | 1eca02d | 2009-08-04 20:32:30 +0000 | [diff] [blame] | 105 | int ipod_scsi_inquiry(struct ipod_t* ipod, int page_code, |
| 106 | unsigned char* buf, int bufsize); |
Dominik Riebeling | 24e37dd | 2012-12-23 23:30:57 +0100 | [diff] [blame] | 107 | ssize_t ipod_read(struct ipod_t* ipod, int nbytes); |
| 108 | ssize_t ipod_write(struct ipod_t* ipod, int nbytes); |
| 109 | int ipod_alloc_buffer(struct ipod_t* ipod, int bufsize); |
Dominik Riebeling | b63d429 | 2013-01-01 11:04:21 +0100 | [diff] [blame] | 110 | int ipod_dealloc_buffer(struct ipod_t* ipod); |
Dave Chapman | 4b7e1e0 | 2006-12-13 09:02:18 +0000 | [diff] [blame] | 111 | |
Dave Chapman | 56780e3 | 2007-06-16 22:32:57 +0000 | [diff] [blame] | 112 | /* In fat32format.c */ |
| 113 | int format_partition(struct ipod_t* ipod, int partition); |
| 114 | |
Dave Chapman | 4b7e1e0 | 2006-12-13 09:02:18 +0000 | [diff] [blame] | 115 | #endif |