summaryrefslogtreecommitdiffstats
path: root/rbutil/ipodpatcher/ipodio-win32.c
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/ipodpatcher/ipodio-win32.c')
-rw-r--r--rbutil/ipodpatcher/ipodio-win32.c20
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)
return 0;
}
-int ipod_alloc_buffer(unsigned char** sectorbuf, int bufsize)
+int ipod_alloc_buffer(struct ipod_t* ipod, int bufsize)
{
/* The ReadFile function requires a memory buffer aligned to a multiple of
the disk sector size. */
- *sectorbuf = (unsigned char*)VirtualAlloc(NULL, bufsize, MEM_COMMIT, PAGE_READWRITE);
- if (*sectorbuf == NULL) {
+ ipod->sectorbuf = (unsigned char*)VirtualAlloc(NULL, bufsize, MEM_COMMIT, PAGE_READWRITE);
+ if (ipod->sectorbuf== NULL) {
ipod_print_error(" Error allocating a buffer: ");
return -1;
}
@@ -179,11 +179,14 @@ int ipod_seek(struct ipod_t* ipod, unsigned long pos)
return 0;
}
-ssize_t ipod_read(struct ipod_t* ipod, unsigned char* buf, int nbytes)
+ssize_t ipod_read(struct ipod_t* ipod, int nbytes)
{
unsigned long count;
- if (!ReadFile(ipod->dh, buf, nbytes, &count, NULL)) {
+ if(ipod->sectorbuf == NULL) {
+ return -1;
+ }
+ if (!ReadFile(ipod->dh, ipod->sectorbuf, nbytes, &count, NULL)) {
ipod_print_error(" Error reading from disk: ");
return -1;
}
@@ -191,11 +194,14 @@ ssize_t ipod_read(struct ipod_t* ipod, unsigned char* buf, int nbytes)
return count;
}
-ssize_t ipod_write(struct ipod_t* ipod, unsigned char* buf, int nbytes)
+ssize_t ipod_write(struct ipod_t* ipod, int nbytes)
{
unsigned long count;
- if (!WriteFile(ipod->dh, buf, nbytes, &count, NULL)) {
+ if(ipod->sectorbuf == NULL) {
+ return -1;
+ }
+ if (!WriteFile(ipod->dh, ipod->sectorbuf, nbytes, &count, NULL)) {
ipod_print_error(" Error writing to disk: ");
return -1;
}