diff options
Diffstat (limited to 'tools/ipodpatcher/ipodio-win32.c')
-rw-r--r-- | tools/ipodpatcher/ipodio-win32.c | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/tools/ipodpatcher/ipodio-win32.c b/tools/ipodpatcher/ipodio-win32.c index 97e3fb6fec..5232e12719 100644 --- a/tools/ipodpatcher/ipodio-win32.c +++ b/tools/ipodpatcher/ipodio-win32.c | |||
@@ -66,27 +66,27 @@ void print_error(char* msg) | |||
66 | LocalFree(pMsgBuf); | 66 | LocalFree(pMsgBuf); |
67 | } | 67 | } |
68 | 68 | ||
69 | int ipod_open(HANDLE* dh, char* diskname, int* sector_size, int silent) | 69 | int ipod_open(struct ipod_t* ipod, int silent) |
70 | { | 70 | { |
71 | DISK_GEOMETRY_EX diskgeometry_ex; | 71 | DISK_GEOMETRY_EX diskgeometry_ex; |
72 | DISK_GEOMETRY diskgeometry; | 72 | DISK_GEOMETRY diskgeometry; |
73 | unsigned long n; | 73 | unsigned long n; |
74 | 74 | ||
75 | *dh = CreateFile(diskname, GENERIC_READ, | 75 | ipod->dh = CreateFile(ipod->diskname, GENERIC_READ, |
76 | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, | 76 | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, |
77 | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_NO_BUFFERING, NULL); | 77 | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_NO_BUFFERING, NULL); |
78 | 78 | ||
79 | if (*dh == INVALID_HANDLE_VALUE) { | 79 | if (ipod->dh == INVALID_HANDLE_VALUE) { |
80 | if (!silent) print_error(" Error opening disk: "); | 80 | if (!silent) print_error(" Error opening disk: "); |
81 | return -1; | 81 | return -1; |
82 | } | 82 | } |
83 | 83 | ||
84 | if (!lock_volume(*dh)) { | 84 | if (!lock_volume(ipod->dh)) { |
85 | if (!silent) print_error(" Error locking disk: "); | 85 | if (!silent) print_error(" Error locking disk: "); |
86 | return -1; | 86 | return -1; |
87 | } | 87 | } |
88 | 88 | ||
89 | if (!DeviceIoControl(*dh, | 89 | if (!DeviceIoControl(ipod->dh, |
90 | IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, | 90 | IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, |
91 | NULL, | 91 | NULL, |
92 | 0, | 92 | 0, |
@@ -94,7 +94,7 @@ int ipod_open(HANDLE* dh, char* diskname, int* sector_size, int silent) | |||
94 | sizeof(diskgeometry_ex), | 94 | sizeof(diskgeometry_ex), |
95 | &n, | 95 | &n, |
96 | NULL)) { | 96 | NULL)) { |
97 | if (!DeviceIoControl(*dh, | 97 | if (!DeviceIoControl(ipod->dh, |
98 | IOCTL_DISK_GET_DRIVE_GEOMETRY, | 98 | IOCTL_DISK_GET_DRIVE_GEOMETRY, |
99 | NULL, | 99 | NULL, |
100 | 0, | 100 | 0, |
@@ -105,31 +105,31 @@ int ipod_open(HANDLE* dh, char* diskname, int* sector_size, int silent) | |||
105 | if (!silent) print_error(" Error reading disk geometry: "); | 105 | if (!silent) print_error(" Error reading disk geometry: "); |
106 | return -1; | 106 | return -1; |
107 | } else { | 107 | } else { |
108 | *sector_size=diskgeometry.BytesPerSector; | 108 | ipod->sector_size=diskgeometry.BytesPerSector; |
109 | } | 109 | } |
110 | } else { | 110 | } else { |
111 | *sector_size=diskgeometry_ex.Geometry.BytesPerSector; | 111 | ipod->sector_size=diskgeometry_ex.Geometry.BytesPerSector; |
112 | } | 112 | } |
113 | 113 | ||
114 | return 0; | 114 | return 0; |
115 | } | 115 | } |
116 | 116 | ||
117 | int ipod_reopen_rw(HANDLE* dh, char* diskname) | 117 | int ipod_reopen_rw(struct ipod_t* ipod) |
118 | { | 118 | { |
119 | /* Close existing file and re-open for writing */ | 119 | /* Close existing file and re-open for writing */ |
120 | unlock_volume(*dh); | 120 | unlock_volume(ipod->dh); |
121 | CloseHandle(*dh); | 121 | CloseHandle(ipod->dh); |
122 | 122 | ||
123 | *dh = CreateFile(diskname, GENERIC_READ | GENERIC_WRITE, | 123 | ipod->dh = CreateFile(ipod->diskname, GENERIC_READ | GENERIC_WRITE, |
124 | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, | 124 | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, |
125 | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_NO_BUFFERING, NULL); | 125 | FILE_FLAG_WRITE_THROUGH | FILE_FLAG_NO_BUFFERING, NULL); |
126 | 126 | ||
127 | if (*dh == INVALID_HANDLE_VALUE) { | 127 | if (ipod->dh == INVALID_HANDLE_VALUE) { |
128 | print_error(" Error opening disk: "); | 128 | print_error(" Error opening disk: "); |
129 | return -1; | 129 | return -1; |
130 | } | 130 | } |
131 | 131 | ||
132 | if (!lock_volume(*dh)) { | 132 | if (!lock_volume(ipod->dh)) { |
133 | print_error(" Error locking disk: "); | 133 | print_error(" Error locking disk: "); |
134 | return -1; | 134 | return -1; |
135 | } | 135 | } |
@@ -137,10 +137,10 @@ int ipod_reopen_rw(HANDLE* dh, char* diskname) | |||
137 | return 0; | 137 | return 0; |
138 | } | 138 | } |
139 | 139 | ||
140 | int ipod_close(HANDLE dh) | 140 | int ipod_close(struct ipod_t* ipod) |
141 | { | 141 | { |
142 | unlock_volume(dh); | 142 | unlock_volume(ipod->dh); |
143 | CloseHandle(dh); | 143 | CloseHandle(ipod->dh); |
144 | return 0; | 144 | return 0; |
145 | } | 145 | } |
146 | 146 | ||
@@ -156,20 +156,20 @@ int ipod_alloc_buffer(unsigned char** sectorbuf, int bufsize) | |||
156 | return 0; | 156 | return 0; |
157 | } | 157 | } |
158 | 158 | ||
159 | int ipod_seek(HANDLE dh, unsigned long pos) | 159 | int ipod_seek(struct ipod_t* ipod, unsigned long pos) |
160 | { | 160 | { |
161 | if (SetFilePointer(dh, pos, NULL, FILE_BEGIN)==0xffffffff) { | 161 | if (SetFilePointer(ipod->dh, pos, NULL, FILE_BEGIN)==0xffffffff) { |
162 | print_error(" Seek error "); | 162 | print_error(" Seek error "); |
163 | return -1; | 163 | return -1; |
164 | } | 164 | } |
165 | return 0; | 165 | return 0; |
166 | } | 166 | } |
167 | 167 | ||
168 | int ipod_read(HANDLE dh, unsigned char* buf, int nbytes) | 168 | int ipod_read(struct ipod_t* ipod, unsigned char* buf, int nbytes) |
169 | { | 169 | { |
170 | unsigned long count; | 170 | unsigned long count; |
171 | 171 | ||
172 | if (!ReadFile(dh, buf, nbytes, &count, NULL)) { | 172 | if (!ReadFile(ipod->dh, buf, nbytes, &count, NULL)) { |
173 | print_error(" Error reading from disk: "); | 173 | print_error(" Error reading from disk: "); |
174 | return -1; | 174 | return -1; |
175 | } | 175 | } |
@@ -177,11 +177,11 @@ int ipod_read(HANDLE dh, unsigned char* buf, int nbytes) | |||
177 | return count; | 177 | return count; |
178 | } | 178 | } |
179 | 179 | ||
180 | int ipod_write(HANDLE dh, unsigned char* buf, int nbytes) | 180 | int ipod_write(struct ipod_t* ipod, unsigned char* buf, int nbytes) |
181 | { | 181 | { |
182 | unsigned long count; | 182 | unsigned long count; |
183 | 183 | ||
184 | if (!WriteFile(dh, buf, nbytes, &count, NULL)) { | 184 | if (!WriteFile(ipod->dh, buf, nbytes, &count, NULL)) { |
185 | print_error(" Error writing to disk: "); | 185 | print_error(" Error writing to disk: "); |
186 | return -1; | 186 | return -1; |
187 | } | 187 | } |