diff options
Diffstat (limited to 'rbutil/ipodpatcher/ipodio-win32.c')
-rw-r--r-- | rbutil/ipodpatcher/ipodio-win32.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/rbutil/ipodpatcher/ipodio-win32.c b/rbutil/ipodpatcher/ipodio-win32.c index 27c1b24f01..d4bdbf0173 100644 --- a/rbutil/ipodpatcher/ipodio-win32.c +++ b/rbutil/ipodpatcher/ipodio-win32.c | |||
@@ -158,12 +158,12 @@ int ipod_close(struct ipod_t* ipod) | |||
158 | return 0; | 158 | return 0; |
159 | } | 159 | } |
160 | 160 | ||
161 | int ipod_alloc_buffer(unsigned char** sectorbuf, int bufsize) | 161 | int ipod_alloc_buffer(struct ipod_t* ipod, int bufsize) |
162 | { | 162 | { |
163 | /* The ReadFile function requires a memory buffer aligned to a multiple of | 163 | /* The ReadFile function requires a memory buffer aligned to a multiple of |
164 | the disk sector size. */ | 164 | the disk sector size. */ |
165 | *sectorbuf = (unsigned char*)VirtualAlloc(NULL, bufsize, MEM_COMMIT, PAGE_READWRITE); | 165 | ipod->sectorbuf = (unsigned char*)VirtualAlloc(NULL, bufsize, MEM_COMMIT, PAGE_READWRITE); |
166 | if (*sectorbuf == NULL) { | 166 | if (ipod->sectorbuf== NULL) { |
167 | ipod_print_error(" Error allocating a buffer: "); | 167 | ipod_print_error(" Error allocating a buffer: "); |
168 | return -1; | 168 | return -1; |
169 | } | 169 | } |
@@ -179,11 +179,14 @@ int ipod_seek(struct ipod_t* ipod, unsigned long pos) | |||
179 | return 0; | 179 | return 0; |
180 | } | 180 | } |
181 | 181 | ||
182 | ssize_t ipod_read(struct ipod_t* ipod, unsigned char* buf, int nbytes) | 182 | ssize_t ipod_read(struct ipod_t* ipod, int nbytes) |
183 | { | 183 | { |
184 | unsigned long count; | 184 | unsigned long count; |
185 | 185 | ||
186 | if (!ReadFile(ipod->dh, buf, nbytes, &count, NULL)) { | 186 | if(ipod->sectorbuf == NULL) { |
187 | return -1; | ||
188 | } | ||
189 | if (!ReadFile(ipod->dh, ipod->sectorbuf, nbytes, &count, NULL)) { | ||
187 | ipod_print_error(" Error reading from disk: "); | 190 | ipod_print_error(" Error reading from disk: "); |
188 | return -1; | 191 | return -1; |
189 | } | 192 | } |
@@ -191,11 +194,14 @@ ssize_t ipod_read(struct ipod_t* ipod, unsigned char* buf, int nbytes) | |||
191 | return count; | 194 | return count; |
192 | } | 195 | } |
193 | 196 | ||
194 | ssize_t ipod_write(struct ipod_t* ipod, unsigned char* buf, int nbytes) | 197 | ssize_t ipod_write(struct ipod_t* ipod, int nbytes) |
195 | { | 198 | { |
196 | unsigned long count; | 199 | unsigned long count; |
197 | 200 | ||
198 | if (!WriteFile(ipod->dh, buf, nbytes, &count, NULL)) { | 201 | if(ipod->sectorbuf == NULL) { |
202 | return -1; | ||
203 | } | ||
204 | if (!WriteFile(ipod->dh, ipod->sectorbuf, nbytes, &count, NULL)) { | ||
199 | ipod_print_error(" Error writing to disk: "); | 205 | ipod_print_error(" Error writing to disk: "); |
200 | return -1; | 206 | return -1; |
201 | } | 207 | } |