From 24e37ddf57bac6a1c9786d50abbe3a1982930382 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Sun, 23 Dec 2012 23:30:57 +0100 Subject: 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 --- rbutil/ipodpatcher/ipodio-win32.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'rbutil/ipodpatcher/ipodio-win32.c') 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; } -- cgit v1.2.3