diff options
author | Dave Chapman <dave@dchapman.com> | 2007-02-10 19:49:43 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2007-02-10 19:49:43 +0000 |
commit | 955afed1b74793a3f06f98f3c259ec98f26a0b82 (patch) | |
tree | 6dcaa6b318ce282b21327530171f4f6a3297cb04 /rbutil/ipodpatcher/ipodio-posix.c | |
parent | f0efde23039064d393e8cc35c2d88a487c47b1c7 (diff) | |
download | rockbox-955afed1b74793a3f06f98f3c259ec98f26a0b82.tar.gz rockbox-955afed1b74793a3f06f98f3c259ec98f26a0b82.zip |
Move ipodpatcher into rbutil directory
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12263 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/ipodpatcher/ipodio-posix.c')
-rw-r--r-- | rbutil/ipodpatcher/ipodio-posix.c | 115 |
1 files changed, 115 insertions, 0 deletions
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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2006-2007 Dave Chapman | ||
11 | * | ||
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 | #include <stdio.h> | ||
21 | #include <unistd.h> | ||
22 | #include <fcntl.h> | ||
23 | #include <string.h> | ||
24 | #include <stdlib.h> | ||
25 | #include <sys/types.h> | ||
26 | #include <sys/stat.h> | ||
27 | #include <sys/ioctl.h> | ||
28 | |||
29 | #if defined(linux) || defined (__linux) | ||
30 | #include <sys/mount.h> | ||
31 | #define IPOD_SECTORSIZE_IOCTL BLKSSZGET | ||
32 | #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) \ | ||
33 | || defined(__bsdi__) || defined(__DragonFly__) | ||
34 | #include <sys/disk.h> | ||
35 | #define IPOD_SECTORSIZE_IOCTL DIOCGSECTORSIZE | ||
36 | #elif defined(__APPLE__) && defined(__MACH__) | ||
37 | #include <sys/disk.h> | ||
38 | #define IPOD_SECTORSIZE_IOCTL DKIOCGETBLOCKSIZE | ||
39 | #else | ||
40 | #error No sector-size detection implemented for this platform | ||
41 | #endif | ||
42 | |||
43 | #include "ipodio.h" | ||
44 | |||
45 | void print_error(char* msg) | ||
46 | { | ||
47 | perror(msg); | ||
48 | } | ||
49 | |||
50 | int ipod_open(struct ipod_t* ipod, int silent) | ||
51 | { | ||
52 | ipod->dh=open(ipod->diskname,O_RDONLY); | ||
53 | if (ipod->dh < 0) { | ||
54 | if (!silent) perror(ipod->diskname); | ||
55 | return -1; | ||
56 | } | ||
57 | |||
58 | if(ioctl(ipod->dh,IPOD_SECTORSIZE_IOCTL,&ipod->sector_size) < 0) { | ||
59 | ipod->sector_size=512; | ||
60 | if (!silent) { | ||
61 | fprintf(stderr,"[ERR] ioctl() call to get sector size failed, defaulting to %d\n" | ||
62 | ,ipod->sector_size); | ||
63 | } | ||
64 | } | ||
65 | return 0; | ||
66 | } | ||
67 | |||
68 | |||
69 | int ipod_reopen_rw(struct ipod_t* ipod) | ||
70 | { | ||
71 | close(ipod->dh); | ||
72 | ipod->dh=open(ipod->diskname,O_RDWR); | ||
73 | if (ipod->dh < 0) { | ||
74 | perror(ipod->diskname); | ||
75 | return -1; | ||
76 | } | ||
77 | return 0; | ||
78 | } | ||
79 | |||
80 | int ipod_close(struct ipod_t* ipod) | ||
81 | { | ||
82 | close(ipod->dh); | ||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | int ipod_alloc_buffer(unsigned char** sectorbuf, int bufsize) | ||
87 | { | ||
88 | *sectorbuf=malloc(bufsize); | ||
89 | if (*sectorbuf == NULL) { | ||
90 | return -1; | ||
91 | } | ||
92 | return 0; | ||
93 | } | ||
94 | |||
95 | int ipod_seek(struct ipod_t* ipod, unsigned long pos) | ||
96 | { | ||
97 | off_t res; | ||
98 | |||
99 | res = lseek(ipod->dh, pos, SEEK_SET); | ||
100 | |||
101 | if (res == -1) { | ||
102 | return -1; | ||
103 | } | ||
104 | return 0; | ||
105 | } | ||
106 | |||
107 | int ipod_read(struct ipod_t* ipod, unsigned char* buf, int nbytes) | ||
108 | { | ||
109 | return read(ipod->dh, buf, nbytes); | ||
110 | } | ||
111 | |||
112 | int ipod_write(struct ipod_t* ipod, unsigned char* buf, int nbytes) | ||
113 | { | ||
114 | return write(ipod->dh, buf, nbytes); | ||
115 | } | ||