blob: 2f106df5219b79e59ffc5d6903541ae009f0a5f8 [file] [log] [blame]
Dave Chapman4b7e1e02006-12-13 09:02:18 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
Dave Chapmane332f4c2007-02-05 01:20:20 +000010 * Copyright (C) 2006-2007 Dave Chapman
Dave Chapman4b7e1e02006-12-13 09:02:18 +000011 *
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 Chapman31aa4522007-02-04 11:42:11 +000023#include <stdint.h>
Dave Chapmanb045a242007-02-16 20:45:00 +000024#include <unistd.h>
Dave Chapman31aa4522007-02-04 11:42:11 +000025
Dave Chapman4b7e1e02006-12-13 09:02:18 +000026#ifdef __WIN32__
27#include <windows.h>
28#else
29#define HANDLE int
30#define O_BINARY 0
31#endif
32
Dave Chapman31aa4522007-02-04 11:42:11 +000033/* The maximum number of images in a firmware partition - a guess... */
34#define MAX_IMAGES 10
35
36enum firmwaretype_t {
37 FTYPE_OSOS = 0,
38 FTYPE_RSRC,
39 FTYPE_AUPD,
40 FTYPE_HIBE
41};
42
43struct 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 Chapman2cc80f52007-07-29 21:19:14 +000055/* A fake partition type - DOS partition tables can't include HFS partitions */
56#define PARTTYPE_HFS 0xffff
57
Dave Chapman31aa4522007-02-04 11:42:11 +000058struct partinfo_t {
Dave Chapman35735c662007-07-27 20:51:36 +000059 uint32_t start; /* first sector (LBA) */
60 uint32_t size; /* number of sectors */
61 uint32_t type;
Dave Chapman31aa4522007-02-04 11:42:11 +000062};
63
64struct ipod_t {
65 HANDLE dh;
66 char diskname[4096];
67 int sector_size;
Dave Chapman56780e32007-06-16 22:32:57 +000068 int sectors_per_track;
69 int num_heads;
Dave Chapman31aa4522007-02-04 11:42:11 +000070 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 Chapmana6d68bd2007-02-10 20:09:23 +000079 char* targetname;
Dave Chapman6e641e82007-02-05 18:29:39 +000080 int macpod;
Dave Chapmanbdc27ff2007-02-08 18:05:50 +000081#ifdef WITH_BOOTOBJS
82 unsigned char* bootloader;
83 int bootloader_len;
84#endif
Dave Chapman31aa4522007-02-04 11:42:11 +000085};
86
Dave Chapman4b7e1e02006-12-13 09:02:18 +000087void print_error(char* msg);
Dave Chapman31aa4522007-02-04 11:42:11 +000088int ipod_open(struct ipod_t* ipod, int silent);
89int ipod_reopen_rw(struct ipod_t* ipod);
90int ipod_close(struct ipod_t* ipod);
91int ipod_seek(struct ipod_t* ipod, unsigned long pos);
Dave Chapman2cc80f52007-07-29 21:19:14 +000092ssize_t ipod_read(struct ipod_t* ipod, unsigned char* buf, int nbytes);
93ssize_t ipod_write(struct ipod_t* ipod, unsigned char* buf, int nbytes);
Dave Chapman4b7e1e02006-12-13 09:02:18 +000094int ipod_alloc_buffer(unsigned char** sectorbuf, int bufsize);
95
Dave Chapman56780e32007-06-16 22:32:57 +000096/* In fat32format.c */
97int format_partition(struct ipod_t* ipod, int partition);
98
Dave Chapman4b7e1e02006-12-13 09:02:18 +000099#endif