From 955afed1b74793a3f06f98f3c259ec98f26a0b82 Mon Sep 17 00:00:00 2001 From: Dave Chapman Date: Sat, 10 Feb 2007 19:49:43 +0000 Subject: Move ipodpatcher into rbutil directory git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12263 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/ipodpatcher/ipodio-posix.c | 115 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 rbutil/ipodpatcher/ipodio-posix.c (limited to 'rbutil/ipodpatcher/ipodio-posix.c') diff --git a/rbutil/ipodpatcher/ipodio-posix.c b/rbutil/ipodpatcher/ipodio-posix.c new file mode 100644 index 0000000000..365bc27291 --- /dev/null +++ b/rbutil/ipodpatcher/ipodio-posix.c @@ -0,0 +1,115 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006-2007 Dave Chapman + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(linux) || defined (__linux) +#include +#define IPOD_SECTORSIZE_IOCTL BLKSSZGET +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) \ + || defined(__bsdi__) || defined(__DragonFly__) +#include +#define IPOD_SECTORSIZE_IOCTL DIOCGSECTORSIZE +#elif defined(__APPLE__) && defined(__MACH__) +#include +#define IPOD_SECTORSIZE_IOCTL DKIOCGETBLOCKSIZE +#else + #error No sector-size detection implemented for this platform +#endif + +#include "ipodio.h" + +void print_error(char* msg) +{ + perror(msg); +} + +int ipod_open(struct ipod_t* ipod, int silent) +{ + ipod->dh=open(ipod->diskname,O_RDONLY); + if (ipod->dh < 0) { + if (!silent) perror(ipod->diskname); + return -1; + } + + if(ioctl(ipod->dh,IPOD_SECTORSIZE_IOCTL,&ipod->sector_size) < 0) { + ipod->sector_size=512; + if (!silent) { + fprintf(stderr,"[ERR] ioctl() call to get sector size failed, defaulting to %d\n" + ,ipod->sector_size); + } + } + return 0; +} + + +int ipod_reopen_rw(struct ipod_t* ipod) +{ + close(ipod->dh); + ipod->dh=open(ipod->diskname,O_RDWR); + if (ipod->dh < 0) { + perror(ipod->diskname); + return -1; + } + return 0; +} + +int ipod_close(struct ipod_t* ipod) +{ + close(ipod->dh); + return 0; +} + +int ipod_alloc_buffer(unsigned char** sectorbuf, int bufsize) +{ + *sectorbuf=malloc(bufsize); + if (*sectorbuf == NULL) { + return -1; + } + return 0; +} + +int ipod_seek(struct ipod_t* ipod, unsigned long pos) +{ + off_t res; + + res = lseek(ipod->dh, pos, SEEK_SET); + + if (res == -1) { + return -1; + } + return 0; +} + +int ipod_read(struct ipod_t* ipod, unsigned char* buf, int nbytes) +{ + return read(ipod->dh, buf, nbytes); +} + +int ipod_write(struct ipod_t* ipod, unsigned char* buf, int nbytes) +{ + return write(ipod->dh, buf, nbytes); +} -- cgit v1.2.3