summaryrefslogtreecommitdiffstats
path: root/rbutil/ipodpatcher/ipodio-win32.c
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2012-12-23 23:30:57 +0100
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2013-01-01 15:05:52 +0100
commit24e37ddf57bac6a1c9786d50abbe3a1982930382 (patch)
treeb34ae751986f185f51556a040f388025cac4c383 /rbutil/ipodpatcher/ipodio-win32.c
parent6803d7b10cd9651ded08674f1597d4511cabb7af (diff)
downloadrockbox-24e37ddf57bac6a1c9786d50abbe3a1982930382.tar.gz
rockbox-24e37ddf57bac6a1c9786d50abbe3a1982930382.tar.bz2
rockbox-24e37ddf57bac6a1c9786d50abbe3a1982930382.zip
ipodpatcher: move sectorbuf pointer into ipod_t structure.
The ipod_t structure holds all relevant information for ipodpatcher. Put the global ipod_sectorbuf pointer into it as well. Allows the Rockbox Utility Ipod class to be instanciated multiple times since each instance can now have its own buffer. Change-Id: Ie319cbadbc20c367ceadba9a46b4dc34b57a79a7
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;
}