blob: 4f1a35dd09904de5b217caf521fabdf6645f97b0 [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 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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 Chapman4b7e1e02006-12-13 09:02:18 +000016 *
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 Chapman31aa4522007-02-04 11:42:11 +000025#include <stdint.h>
Dominik Riebeling5ffd2f72011-12-08 21:59:13 +000026#if !defined(_WIN32)
Dave Chapmanb045a242007-02-16 20:45:00 +000027#include <unistd.h>
Dominik Riebeling5ffd2f72011-12-08 21:59:13 +000028#elif defined(_MSC_VER)
29/* MSVC uses a different name for ssize_t */
30#define ssize_t SSIZE_T
31#endif
Dave Chapman31aa4522007-02-04 11:42:11 +000032
Dominik Riebeling5ffd2f72011-12-08 21:59:13 +000033#if defined(__WIN32__) || defined(_WIN32)
Dave Chapman4b7e1e02006-12-13 09:02:18 +000034#include <windows.h>
35#else
36#define HANDLE int
37#define O_BINARY 0
38#endif
39
Dave Chapman31aa4522007-02-04 11:42:11 +000040/* The maximum number of images in a firmware partition - a guess... */
41#define MAX_IMAGES 10
42
43enum firmwaretype_t {
44 FTYPE_OSOS = 0,
45 FTYPE_RSRC,
46 FTYPE_AUPD,
Dave Chapman8e95cc42009-10-13 08:02:59 +000047 FTYPE_HIBE,
48 FTYPE_OSBK
Dave Chapman31aa4522007-02-04 11:42:11 +000049};
50
51struct 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 Chapman2cc80f52007-07-29 21:19:14 +000063/* A fake partition type - DOS partition tables can't include HFS partitions */
64#define PARTTYPE_HFS 0xffff
65
Dave Chapman31aa4522007-02-04 11:42:11 +000066struct partinfo_t {
Dave Chapman35735c662007-07-27 20:51:36 +000067 uint32_t start; /* first sector (LBA) */
68 uint32_t size; /* number of sectors */
69 uint32_t type;
Dave Chapman31aa4522007-02-04 11:42:11 +000070};
71
72struct ipod_t {
Dominik Riebeling24e37dd2012-12-23 23:30:57 +010073 unsigned char* sectorbuf;
Dave Chapman31aa4522007-02-04 11:42:11 +000074 HANDLE dh;
75 char diskname[4096];
76 int sector_size;
Dave Chapman56780e32007-06-16 22:32:57 +000077 int sectors_per_track;
78 int num_heads;
Dave Chapman31aa4522007-02-04 11:42:11 +000079 struct ipod_directory_t ipod_directory[MAX_IMAGES];
80 int nimages;
Dave Chapman8e95cc42009-10-13 08:02:59 +000081 int ososimage;
Dave Chapman31aa4522007-02-04 11:42:11 +000082 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 Chapmana6d68bd2007-02-10 20:09:23 +000089 char* targetname;
Dave Chapman6e641e82007-02-05 18:29:39 +000090 int macpod;
Dave Chapman1eca02d2009-08-04 20:32:30 +000091 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 Chapmanbdc27ff2007-02-08 18:05:50 +000094#ifdef WITH_BOOTOBJS
95 unsigned char* bootloader;
96 int bootloader_len;
97#endif
Dave Chapman31aa4522007-02-04 11:42:11 +000098};
99
Dominik Riebeling3e489c12009-11-08 13:38:10 +0000100void ipod_print_error(char* msg);
Dave Chapman31aa4522007-02-04 11:42:11 +0000101int ipod_open(struct ipod_t* ipod, int silent);
102int ipod_reopen_rw(struct ipod_t* ipod);
103int ipod_close(struct ipod_t* ipod);
104int ipod_seek(struct ipod_t* ipod, unsigned long pos);
Dave Chapman1eca02d2009-08-04 20:32:30 +0000105int ipod_scsi_inquiry(struct ipod_t* ipod, int page_code,
106 unsigned char* buf, int bufsize);
Dominik Riebeling24e37dd2012-12-23 23:30:57 +0100107ssize_t ipod_read(struct ipod_t* ipod, int nbytes);
108ssize_t ipod_write(struct ipod_t* ipod, int nbytes);
109int ipod_alloc_buffer(struct ipod_t* ipod, int bufsize);
Dominik Riebelingb63d4292013-01-01 11:04:21 +0100110int ipod_dealloc_buffer(struct ipod_t* ipod);
Dave Chapman4b7e1e02006-12-13 09:02:18 +0000111
Dave Chapman56780e32007-06-16 22:32:57 +0000112/* In fat32format.c */
113int format_partition(struct ipod_t* ipod, int partition);
114
Dave Chapman4b7e1e02006-12-13 09:02:18 +0000115#endif