2006-12-13 09:02:18 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
2007-02-05 01:20:20 +00:00
|
|
|
* Copyright (C) 2006-2007 Dave Chapman
|
2006-12-13 09:02:18 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-12-13 09:02:18 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __IPODIO_H
|
|
|
|
#define __IPODIO_H
|
|
|
|
|
2007-02-04 11:42:11 +00:00
|
|
|
#include <stdint.h>
|
2011-12-08 21:59:13 +00:00
|
|
|
#if !defined(_WIN32)
|
2007-02-16 20:45:00 +00:00
|
|
|
#include <unistd.h>
|
2011-12-08 21:59:13 +00:00
|
|
|
#elif defined(_MSC_VER)
|
|
|
|
/* MSVC uses a different name for ssize_t */
|
|
|
|
#define ssize_t SSIZE_T
|
|
|
|
#endif
|
2007-02-04 11:42:11 +00:00
|
|
|
|
2011-12-08 21:59:13 +00:00
|
|
|
#if defined(__WIN32__) || defined(_WIN32)
|
2006-12-13 09:02:18 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#else
|
|
|
|
#define HANDLE int
|
|
|
|
#define O_BINARY 0
|
|
|
|
#endif
|
|
|
|
|
2007-02-04 11:42:11 +00:00
|
|
|
/* The maximum number of images in a firmware partition - a guess... */
|
|
|
|
#define MAX_IMAGES 10
|
|
|
|
|
|
|
|
enum firmwaretype_t {
|
|
|
|
FTYPE_OSOS = 0,
|
|
|
|
FTYPE_RSRC,
|
|
|
|
FTYPE_AUPD,
|
2009-10-13 08:02:59 +00:00
|
|
|
FTYPE_HIBE,
|
|
|
|
FTYPE_OSBK
|
2007-02-04 11:42:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ipod_directory_t {
|
|
|
|
enum firmwaretype_t ftype;
|
|
|
|
int id;
|
|
|
|
uint32_t devOffset; /* Offset of image relative to one sector into bootpart*/
|
|
|
|
uint32_t len;
|
|
|
|
uint32_t addr;
|
|
|
|
uint32_t entryOffset;
|
|
|
|
uint32_t chksum;
|
|
|
|
uint32_t vers;
|
|
|
|
uint32_t loadAddr;
|
|
|
|
};
|
|
|
|
|
2007-07-29 21:19:14 +00:00
|
|
|
/* A fake partition type - DOS partition tables can't include HFS partitions */
|
|
|
|
#define PARTTYPE_HFS 0xffff
|
|
|
|
|
2007-02-04 11:42:11 +00:00
|
|
|
struct partinfo_t {
|
2007-07-27 20:51:36 +00:00
|
|
|
uint32_t start; /* first sector (LBA) */
|
|
|
|
uint32_t size; /* number of sectors */
|
|
|
|
uint32_t type;
|
2007-02-04 11:42:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ipod_t {
|
2012-12-23 22:30:57 +00:00
|
|
|
unsigned char* sectorbuf;
|
2007-02-04 11:42:11 +00:00
|
|
|
HANDLE dh;
|
|
|
|
char diskname[4096];
|
|
|
|
int sector_size;
|
2007-06-16 22:32:57 +00:00
|
|
|
int sectors_per_track;
|
|
|
|
int num_heads;
|
2007-02-04 11:42:11 +00:00
|
|
|
struct ipod_directory_t ipod_directory[MAX_IMAGES];
|
|
|
|
int nimages;
|
2009-10-13 08:02:59 +00:00
|
|
|
int ososimage;
|
2007-02-04 11:42:11 +00:00
|
|
|
off_t diroffset;
|
|
|
|
off_t start; /* Offset in bytes of firmware partition from start of disk */
|
|
|
|
off_t fwoffset; /* Offset in bytes of start of firmware images from start of disk */
|
|
|
|
struct partinfo_t pinfo[4];
|
|
|
|
int modelnum;
|
|
|
|
char* modelname;
|
|
|
|
char* modelstr;
|
2007-02-10 20:09:23 +00:00
|
|
|
char* targetname;
|
2007-02-05 18:29:39 +00:00
|
|
|
int macpod;
|
2009-08-04 20:32:30 +00:00
|
|
|
char* xmlinfo; /* The XML Device Information (if available) */
|
|
|
|
int xmlinfo_len;
|
|
|
|
int ramsize; /* The amount of RAM in the ipod (if available) */
|
2007-02-08 18:05:50 +00:00
|
|
|
#ifdef WITH_BOOTOBJS
|
|
|
|
unsigned char* bootloader;
|
|
|
|
int bootloader_len;
|
|
|
|
#endif
|
2007-02-04 11:42:11 +00:00
|
|
|
};
|
|
|
|
|
2009-11-08 13:38:10 +00:00
|
|
|
void ipod_print_error(char* msg);
|
2007-02-04 11:42:11 +00:00
|
|
|
int ipod_open(struct ipod_t* ipod, int silent);
|
|
|
|
int ipod_reopen_rw(struct ipod_t* ipod);
|
|
|
|
int ipod_close(struct ipod_t* ipod);
|
|
|
|
int ipod_seek(struct ipod_t* ipod, unsigned long pos);
|
2009-08-04 20:32:30 +00:00
|
|
|
int ipod_scsi_inquiry(struct ipod_t* ipod, int page_code,
|
|
|
|
unsigned char* buf, int bufsize);
|
2012-12-23 22:30:57 +00:00
|
|
|
ssize_t ipod_read(struct ipod_t* ipod, int nbytes);
|
|
|
|
ssize_t ipod_write(struct ipod_t* ipod, int nbytes);
|
|
|
|
int ipod_alloc_buffer(struct ipod_t* ipod, int bufsize);
|
2013-01-01 10:04:21 +00:00
|
|
|
int ipod_dealloc_buffer(struct ipod_t* ipod);
|
2006-12-13 09:02:18 +00:00
|
|
|
|
2007-06-16 22:32:57 +00:00
|
|
|
/* In fat32format.c */
|
|
|
|
int format_partition(struct ipod_t* ipod, int partition);
|
|
|
|
|
2006-12-13 09:02:18 +00:00
|
|
|
#endif
|