summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-11-28 04:33:24 +0100
committerGravatar Matt Colyer2009-11-30 21:02:41 -0800
commit7adc81dddd764b0ef76fefd73852b835d3211b9b (patch)
tree7125966103693842686ff71922dce4459e7c6251
parent12a44afce569c2cdf31018c259745e09b13bffc3 (diff)
downloadlibimobiledevice-7adc81dddd764b0ef76fefd73852b835d3211b9b.tar.gz
libimobiledevice-7adc81dddd764b0ef76fefd73852b835d3211b9b.tar.bz2
uint32_t type fixes for afc_file_read/afc_file_write
This patch also adapts all corresponding internal functions. The buffer lengths are now consistently handled as uint32_t.
-rw-r--r--include/libiphone/afc.h4
-rw-r--r--src/AFC.c230
2 files changed, 124 insertions, 110 deletions
diff --git a/include/libiphone/afc.h b/include/libiphone/afc.h
index 1c714c9..94eb02e 100644
--- a/include/libiphone/afc.h
+++ b/include/libiphone/afc.h
@@ -95,8 +95,8 @@ afc_error_t afc_get_file_info(afc_client_t client, const char *filename, char **
95afc_error_t afc_file_open(afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle); 95afc_error_t afc_file_open(afc_client_t client, const char *filename, afc_file_mode_t file_mode, uint64_t *handle);
96afc_error_t afc_file_close(afc_client_t client, uint64_t handle); 96afc_error_t afc_file_close(afc_client_t client, uint64_t handle);
97afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t operation); 97afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t operation);
98afc_error_t afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint32_t *bytes); 98afc_error_t afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, uint32_t *bytes_read);
99afc_error_t afc_file_write(afc_client_t client, uint64_t handle, const char *data, int length, uint32_t *bytes); 99afc_error_t afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t length, uint32_t *bytes_written);
100afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence); 100afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence);
101afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position); 101afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position);
102afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize); 102afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize);
diff --git a/src/AFC.c b/src/AFC.c
index 2b83c44..15d746e 100644
--- a/src/AFC.c
+++ b/src/AFC.c
@@ -119,21 +119,24 @@ afc_error_t afc_client_free(afc_client_t client)
119 * @param client The client to send data through. 119 * @param client The client to send data through.
120 * @param data The data to send. 120 * @param data The data to send.
121 * @param length The length to send. 121 * @param length The length to send.
122 * 122 * @param bytes_sent The number of bytes actually sent.
123 * @return The number of bytes actually sent, or -1 on error. 123 *
124 * @return AFC_E_SUCCESS on success, or an AFC_E_* error value on error.
124 * 125 *
125 * @warning set client->afc_packet->this_length and 126 * @warning set client->afc_packet->this_length and
126 * client->afc_packet->entire_length to 0 before calling this. The 127 * client->afc_packet->entire_length to 0 before calling this. The
127 * reason is that if you set them to different values, it indicates 128 * reason is that if you set them to different values, it indicates
128 * you want to send the data as two packets. 129 * you want to send the data as two packets.
129 */ 130 */
130static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t length) 131static afc_error_t afc_dispatch_packet(afc_client_t client, const char *data, uint32_t length, uint32_t *bytes_sent)
131{ 132{
132 int bytes = 0, offset = 0; 133 uint32_t offset = 0;
133 uint32_t sent = 0; 134 uint32_t sent = 0;
134 135
135 if (!client || !client->connection || !client->afc_packet) 136 if (!client || !client->connection || !client->afc_packet)
136 return 0; 137 return AFC_E_INVALID_ARGUMENT;
138
139 *bytes_sent = 0;
137 140
138 if (!data || !length) 141 if (!data || !length)
139 length = 0; 142 length = 0;
@@ -158,21 +161,26 @@ static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t l
158 log_debug_msg("to based on the packet.\n"); 161 log_debug_msg("to based on the packet.\n");
159 log_debug_msg("%s: length minus offset: %i\n", __func__, length - offset); 162 log_debug_msg("%s: length minus offset: %i\n", __func__, length - offset);
160 log_debug_msg("%s: rest of packet: %i\n", __func__, client->afc_packet->entire_length - client->afc_packet->this_length); 163 log_debug_msg("%s: rest of packet: %i\n", __func__, client->afc_packet->entire_length - client->afc_packet->this_length);
161 return -1; 164 return AFC_E_INTERNAL_ERROR;
162 } 165 }
163 166
167 /* send AFC packet header */
164 AFCPacket_to_LE(client->afc_packet); 168 AFCPacket_to_LE(client->afc_packet);
169 sent = 0;
165 iphone_device_send(client->connection, (void*)client->afc_packet, sizeof(AFCPacket), &sent); 170 iphone_device_send(client->connection, (void*)client->afc_packet, sizeof(AFCPacket), &sent);
166 if (sent == 0) { 171 if (sent == 0) {
167 return bytes; 172 /* FIXME: should this be handled as success?! */
173 return AFC_E_SUCCESS;
168 } 174 }
169 bytes += sent; 175 *bytes_sent += sent;
170 176
177 /* send AFC packet data */
178 sent = 0;
171 iphone_device_send(client->connection, data, offset, &sent); 179 iphone_device_send(client->connection, data, offset, &sent);
172 if (sent == 0) { 180 if (sent == 0) {
173 return bytes; 181 return AFC_E_SUCCESS;
174 } 182 }
175 bytes += sent; 183 *bytes_sent += sent;
176 184
177 log_debug_msg("%s: sent the first now go with the second\n", __func__); 185 log_debug_msg("%s: sent the first now go with the second\n", __func__);
178 log_debug_msg("%s: Length: %i\n", __func__, length - offset); 186 log_debug_msg("%s: Length: %i\n", __func__, length - offset);
@@ -182,8 +190,8 @@ static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t l
182 sent = 0; 190 sent = 0;
183 iphone_device_send(client->connection, data + offset, length - offset, &sent); 191 iphone_device_send(client->connection, data + offset, length - offset, &sent);
184 192
185 bytes = sent; 193 *bytes_sent = sent;
186 return bytes; 194 return AFC_E_SUCCESS;
187 } else { 195 } else {
188 log_debug_msg("%s: doin things the old way\n", __func__); 196 log_debug_msg("%s: doin things the old way\n", __func__);
189 log_debug_msg("%s: packet length = %i\n", __func__, client->afc_packet->this_length); 197 log_debug_msg("%s: packet length = %i\n", __func__, client->afc_packet->this_length);
@@ -191,36 +199,38 @@ static int afc_dispatch_packet(afc_client_t client, const char *data, uint64_t l
191 log_debug_buffer((char*)client->afc_packet, sizeof(AFCPacket)); 199 log_debug_buffer((char*)client->afc_packet, sizeof(AFCPacket));
192 log_debug_msg("\n"); 200 log_debug_msg("\n");
193 201
202 /* send AFC packet header */
194 AFCPacket_to_LE(client->afc_packet); 203 AFCPacket_to_LE(client->afc_packet);
204 sent = 0;
195 iphone_device_send(client->connection, (void*)client->afc_packet, sizeof(AFCPacket), &sent); 205 iphone_device_send(client->connection, (void*)client->afc_packet, sizeof(AFCPacket), &sent);
196 if (sent == 0) { 206 if (sent == 0) {
197 return bytes; 207 return AFC_E_SUCCESS;
198 } 208 }
199 bytes += sent; 209 *bytes_sent += sent;
210 /* send AFC packet data (if there's data to send) */
200 if (length > 0) { 211 if (length > 0) {
201 log_debug_msg("%s: packet data follows\n", __func__); 212 log_debug_msg("%s: packet data follows\n", __func__);
202 213
203 log_debug_buffer(data, length); 214 log_debug_buffer(data, length);
204 log_debug_msg("\n"); 215 log_debug_msg("\n");
205 iphone_device_send(client->connection, data, length, &sent); 216 iphone_device_send(client->connection, data, length, &sent);
206 bytes += sent; 217 *bytes_sent += sent;
207 } 218 }
208 return bytes; 219 return AFC_E_SUCCESS;
209 } 220 }
210 return -1; 221 return AFC_E_INTERNAL_ERROR;
211} 222}
212 223
213/** Receives data through an AFC client and sets a variable to the received data. 224/** Receives data through an AFC client and sets a variable to the received data.
214 * 225 *
215 * @param client The client to receive data on. 226 * @param client The client to receive data on.
216 * @param dump_here The char* to point to the newly-received data. 227 * @param dump_here The char* to point to the newly-received data.
228 * @param bytes_recv How much data was received.
217 * 229 *
218 * @return How much data was received, 0 on successful receive with no errors, 230 * @return AFC_E_SUCCESS when data has been received, or an AFC_E_* error value
219 * -1 if there was an error involved with receiving or if the packet 231 * when an error occured.
220 * received raised a non-trivial error condition (i.e. non-zero with
221 * AFC_ERROR operation)
222 */ 232 */
223static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int *bytes) 233static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, uint32_t *bytes_recv)
224{ 234{
225 AFCPacket header; 235 AFCPacket header;
226 uint32_t entire_len = 0; 236 uint32_t entire_len = 0;
@@ -228,16 +238,16 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int *
228 uint32_t current_count = 0; 238 uint32_t current_count = 0;
229 uint64_t param1 = -1; 239 uint64_t param1 = -1;
230 240
231 *bytes = 0; 241 *bytes_recv = 0;
232 242
233 /* first, read the AFC header */ 243 /* first, read the AFC header */
234 iphone_device_recv(client->connection, (char*)&header, sizeof(AFCPacket), (uint32_t*)bytes); 244 iphone_device_recv(client->connection, (char*)&header, sizeof(AFCPacket), bytes_recv);
235 AFCPacket_from_LE(&header); 245 AFCPacket_from_LE(&header);
236 if (*bytes <= 0) { 246 if (*bytes_recv == 0) {
237 log_debug_msg("%s: Just didn't get enough.\n", __func__); 247 log_debug_msg("%s: Just didn't get enough.\n", __func__);
238 *dump_here = NULL; 248 *dump_here = NULL;
239 return AFC_E_MUX_ERROR; 249 return AFC_E_MUX_ERROR;
240 } else if ((uint32_t)*bytes < sizeof(AFCPacket)) { 250 } else if (*bytes_recv < sizeof(AFCPacket)) {
241 log_debug_msg("%s: Did not even get the AFCPacket header\n", __func__); 251 log_debug_msg("%s: Did not even get the AFCPacket header\n", __func__);
242 *dump_here = NULL; 252 *dump_here = NULL;
243 return AFC_E_MUX_ERROR; 253 return AFC_E_MUX_ERROR;
@@ -265,7 +275,7 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int *
265 && header.entire_length == sizeof(AFCPacket)) { 275 && header.entire_length == sizeof(AFCPacket)) {
266 log_debug_msg("%s: Empty AFCPacket received!\n", __func__); 276 log_debug_msg("%s: Empty AFCPacket received!\n", __func__);
267 *dump_here = NULL; 277 *dump_here = NULL;
268 *bytes = 0; 278 *bytes_recv = 0;
269 if (header.operation == AFC_OP_DATA) { 279 if (header.operation == AFC_OP_DATA) {
270 return AFC_E_SUCCESS; 280 return AFC_E_SUCCESS;
271 } else { 281 } else {
@@ -285,13 +295,13 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int *
285 295
286 *dump_here = (char*)malloc(entire_len); 296 *dump_here = (char*)malloc(entire_len);
287 if (this_len > 0) { 297 if (this_len > 0) {
288 iphone_device_recv(client->connection, *dump_here, this_len, (uint32_t*)bytes); 298 iphone_device_recv(client->connection, *dump_here, this_len, bytes_recv);
289 if (*bytes <= 0) { 299 if (*bytes_recv <= 0) {
290 free(*dump_here); 300 free(*dump_here);
291 *dump_here = NULL; 301 *dump_here = NULL;
292 log_debug_msg("%s: Did not get packet contents!\n", __func__); 302 log_debug_msg("%s: Did not get packet contents!\n", __func__);
293 return AFC_E_NOT_ENOUGH_DATA; 303 return AFC_E_NOT_ENOUGH_DATA;
294 } else if ((uint32_t)*bytes < this_len) { 304 } else if (*bytes_recv < this_len) {
295 free(*dump_here); 305 free(*dump_here);
296 *dump_here = NULL; 306 *dump_here = NULL;
297 log_debug_msg("%s: Could not receive this_len=%d bytes\n", __func__, this_len); 307 log_debug_msg("%s: Could not receive this_len=%d bytes\n", __func__, this_len);
@@ -303,12 +313,12 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int *
303 313
304 if (entire_len > this_len) { 314 if (entire_len > this_len) {
305 while (current_count < entire_len) { 315 while (current_count < entire_len) {
306 iphone_device_recv(client->connection, (*dump_here)+current_count, entire_len - current_count, (uint32_t*)bytes); 316 iphone_device_recv(client->connection, (*dump_here)+current_count, entire_len - current_count, bytes_recv);
307 if (*bytes <= 0) { 317 if (*bytes_recv <= 0) {
308 log_debug_msg("%s: Error receiving data (recv returned %d)\n", __func__, *bytes); 318 log_debug_msg("%s: Error receiving data (recv returned %d)\n", __func__, *bytes_recv);
309 break; 319 break;
310 } 320 }
311 current_count += *bytes; 321 current_count += *bytes_recv;
312 } 322 }
313 if (current_count < entire_len) { 323 if (current_count < entire_len) {
314 log_debug_msg("%s: WARNING: could not receive full packet (read %s, size %d)\n", __func__, current_count, entire_len); 324 log_debug_msg("%s: WARNING: could not receive full packet (read %s, size %d)\n", __func__, current_count, entire_len);
@@ -348,7 +358,7 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int *
348 /* unknown operation code received */ 358 /* unknown operation code received */
349 free(*dump_here); 359 free(*dump_here);
350 *dump_here = NULL; 360 *dump_here = NULL;
351 *bytes = 0; 361 *bytes_recv = 0;
352 362
353 log_debug_msg("%s: WARNING: Unknown operation code received 0x%llx param1=%lld\n", __func__, header.operation, param1); 363 log_debug_msg("%s: WARNING: Unknown operation code received 0x%llx param1=%lld\n", __func__, header.operation, param1);
354 fprintf(stderr, "%s: WARNING: Unknown operation code received 0x%llx param1=%lld\n", __func__, (long long)header.operation, (long long)param1); 364 fprintf(stderr, "%s: WARNING: Unknown operation code received 0x%llx param1=%lld\n", __func__, (long long)header.operation, (long long)param1);
@@ -356,13 +366,13 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, int *
356 return AFC_E_OP_NOT_SUPPORTED; 366 return AFC_E_OP_NOT_SUPPORTED;
357 } 367 }
358 368
359 *bytes = current_count; 369 *bytes_recv = current_count;
360 return AFC_E_SUCCESS; 370 return AFC_E_SUCCESS;
361} 371}
362 372
363static int count_nullspaces(char *string, int number) 373static uint32_t count_nullspaces(char *string, uint32_t number)
364{ 374{
365 int i = 0, nulls = 0; 375 uint32_t i = 0, nulls = 0;
366 376
367 for (i = 0; i < number; i++) { 377 for (i = 0; i < number; i++) {
368 if (string[i] == '\0') 378 if (string[i] == '\0')
@@ -372,9 +382,9 @@ static int count_nullspaces(char *string, int number)
372 return nulls; 382 return nulls;
373} 383}
374 384
375static char **make_strings_list(char *tokens, int true_length) 385static char **make_strings_list(char *tokens, uint32_t true_length)
376{ 386{
377 int nulls = 0, i = 0, j = 0; 387 uint32_t nulls = 0, i = 0, j = 0;
378 char **list = NULL; 388 char **list = NULL;
379 389
380 if (!tokens || !true_length) 390 if (!tokens || !true_length)
@@ -401,7 +411,7 @@ static char **make_strings_list(char *tokens, int true_length)
401 */ 411 */
402afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***list) 412afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***list)
403{ 413{
404 int bytes = 0; 414 uint32_t bytes = 0;
405 char *data = NULL, **list_loc = NULL; 415 char *data = NULL, **list_loc = NULL;
406 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 416 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
407 417
@@ -414,8 +424,8 @@ afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***lis
414 client->afc_packet->operation = AFC_OP_READ_DIR; 424 client->afc_packet->operation = AFC_OP_READ_DIR;
415 client->afc_packet->entire_length = 0; 425 client->afc_packet->entire_length = 0;
416 client->afc_packet->this_length = 0; 426 client->afc_packet->this_length = 0;
417 bytes = afc_dispatch_packet(client, dir, strlen(dir)+1); 427 ret = afc_dispatch_packet(client, dir, strlen(dir)+1, &bytes);
418 if (bytes <= 0) { 428 if (ret != AFC_E_SUCCESS) {
419 afc_unlock(client); 429 afc_unlock(client);
420 return AFC_E_NOT_ENOUGH_DATA; 430 return AFC_E_NOT_ENOUGH_DATA;
421 } 431 }
@@ -445,7 +455,7 @@ afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***lis
445 */ 455 */
446afc_error_t afc_get_device_info(afc_client_t client, char ***infos) 456afc_error_t afc_get_device_info(afc_client_t client, char ***infos)
447{ 457{
448 int bytes = 0; 458 uint32_t bytes = 0;
449 char *data = NULL, **list = NULL; 459 char *data = NULL, **list = NULL;
450 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 460 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
451 461
@@ -457,8 +467,8 @@ afc_error_t afc_get_device_info(afc_client_t client, char ***infos)
457 // Send the command 467 // Send the command
458 client->afc_packet->operation = AFC_OP_GET_DEVINFO; 468 client->afc_packet->operation = AFC_OP_GET_DEVINFO;
459 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 469 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
460 bytes = afc_dispatch_packet(client, NULL, 0); 470 ret = afc_dispatch_packet(client, NULL, 0, &bytes);
461 if (bytes < 0) { 471 if (ret != AFC_E_SUCCESS) {
462 afc_unlock(client); 472 afc_unlock(client);
463 return AFC_E_NOT_ENOUGH_DATA; 473 return AFC_E_NOT_ENOUGH_DATA;
464 } 474 }
@@ -526,7 +536,7 @@ afc_error_t afc_get_device_info_key(afc_client_t client, const char *key, char *
526afc_error_t afc_remove_path(afc_client_t client, const char *path) 536afc_error_t afc_remove_path(afc_client_t client, const char *path)
527{ 537{
528 char *response = NULL; 538 char *response = NULL;
529 int bytes; 539 uint32_t bytes = 0;
530 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 540 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
531 541
532 if (!client || !path || !client->afc_packet || !client->connection) 542 if (!client || !path || !client->afc_packet || !client->connection)
@@ -537,8 +547,8 @@ afc_error_t afc_remove_path(afc_client_t client, const char *path)
537 // Send command 547 // Send command
538 client->afc_packet->this_length = client->afc_packet->entire_length = 0; 548 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
539 client->afc_packet->operation = AFC_OP_REMOVE_PATH; 549 client->afc_packet->operation = AFC_OP_REMOVE_PATH;
540 bytes = afc_dispatch_packet(client, path, strlen(path)+1); 550 ret = afc_dispatch_packet(client, path, strlen(path)+1, &bytes);
541 if (bytes <= 0) { 551 if (ret != AFC_E_SUCCESS) {
542 afc_unlock(client); 552 afc_unlock(client);
543 return AFC_E_NOT_ENOUGH_DATA; 553 return AFC_E_NOT_ENOUGH_DATA;
544 } 554 }
@@ -569,7 +579,7 @@ afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *t
569{ 579{
570 char *response = NULL; 580 char *response = NULL;
571 char *send = (char *) malloc(sizeof(char) * (strlen(from) + strlen(to) + 1 + sizeof(uint32_t))); 581 char *send = (char *) malloc(sizeof(char) * (strlen(from) + strlen(to) + 1 + sizeof(uint32_t)));
572 int bytes = 0; 582 uint32_t bytes = 0;
573 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 583 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
574 584
575 if (!client || !from || !to || !client->afc_packet || !client->connection) 585 if (!client || !from || !to || !client->afc_packet || !client->connection)
@@ -582,9 +592,9 @@ afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *t
582 memcpy(send + strlen(from) + 1, to, strlen(to) + 1); 592 memcpy(send + strlen(from) + 1, to, strlen(to) + 1);
583 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 593 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
584 client->afc_packet->operation = AFC_OP_RENAME_PATH; 594 client->afc_packet->operation = AFC_OP_RENAME_PATH;
585 bytes = afc_dispatch_packet(client, send, strlen(to)+1 + strlen(from)+1); 595 ret = afc_dispatch_packet(client, send, strlen(to)+1 + strlen(from)+1, &bytes);
586 free(send); 596 free(send);
587 if (bytes <= 0) { 597 if (ret != AFC_E_SUCCESS) {
588 afc_unlock(client); 598 afc_unlock(client);
589 return AFC_E_NOT_ENOUGH_DATA; 599 return AFC_E_NOT_ENOUGH_DATA;
590 } 600 }
@@ -609,7 +619,7 @@ afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *t
609 */ 619 */
610afc_error_t afc_make_directory(afc_client_t client, const char *dir) 620afc_error_t afc_make_directory(afc_client_t client, const char *dir)
611{ 621{
612 int bytes = 0; 622 uint32_t bytes = 0;
613 char *response = NULL; 623 char *response = NULL;
614 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 624 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
615 625
@@ -621,8 +631,8 @@ afc_error_t afc_make_directory(afc_client_t client, const char *dir)
621 // Send command 631 // Send command
622 client->afc_packet->operation = AFC_OP_MAKE_DIR; 632 client->afc_packet->operation = AFC_OP_MAKE_DIR;
623 client->afc_packet->this_length = client->afc_packet->entire_length = 0; 633 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
624 bytes = afc_dispatch_packet(client, dir, strlen(dir)+1); 634 ret = afc_dispatch_packet(client, dir, strlen(dir)+1, &bytes);
625 if (bytes <= 0) { 635 if (ret != AFC_E_SUCCESS) {
626 afc_unlock(client); 636 afc_unlock(client);
627 return AFC_E_NOT_ENOUGH_DATA; 637 return AFC_E_NOT_ENOUGH_DATA;
628 } 638 }
@@ -650,7 +660,7 @@ afc_error_t afc_make_directory(afc_client_t client, const char *dir)
650afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***infolist) 660afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***infolist)
651{ 661{
652 char *received = NULL; 662 char *received = NULL;
653 int bytes; 663 uint32_t bytes = 0;
654 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 664 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
655 665
656 if (!client || !path || !infolist) 666 if (!client || !path || !infolist)
@@ -661,7 +671,11 @@ afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***inf
661 // Send command 671 // Send command
662 client->afc_packet->operation = AFC_OP_GET_FILE_INFO; 672 client->afc_packet->operation = AFC_OP_GET_FILE_INFO;
663 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 673 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
664 afc_dispatch_packet(client, path, strlen(path)+1); 674 ret = afc_dispatch_packet(client, path, strlen(path)+1, &bytes);
675 if (ret != AFC_E_SUCCESS) {
676 afc_unlock(client);
677 return AFC_E_NOT_ENOUGH_DATA;
678 }
665 679
666 // Receive data 680 // Receive data
667 ret = afc_receive_data(client, &received, &bytes); 681 ret = afc_receive_data(client, &received, &bytes);
@@ -692,7 +706,7 @@ afc_file_open(afc_client_t client, const char *filename,
692 afc_file_mode_t file_mode, uint64_t *handle) 706 afc_file_mode_t file_mode, uint64_t *handle)
693{ 707{
694 uint64_t file_mode_loc = GUINT64_TO_LE(file_mode); 708 uint64_t file_mode_loc = GUINT64_TO_LE(file_mode);
695 int bytes = 0; 709 uint32_t bytes = 0;
696 char *data = (char *) malloc(sizeof(char) * (8 + strlen(filename) + 1)); 710 char *data = (char *) malloc(sizeof(char) * (8 + strlen(filename) + 1));
697 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 711 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
698 712
@@ -710,10 +724,10 @@ afc_file_open(afc_client_t client, const char *filename,
710 data[8 + strlen(filename)] = '\0'; 724 data[8 + strlen(filename)] = '\0';
711 client->afc_packet->operation = AFC_OP_FILE_OPEN; 725 client->afc_packet->operation = AFC_OP_FILE_OPEN;
712 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 726 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
713 bytes = afc_dispatch_packet(client, data, 8 + strlen(filename) + 1); 727 ret = afc_dispatch_packet(client, data, 8 + strlen(filename) + 1, &bytes);
714 free(data); 728 free(data);
715 729
716 if (bytes <= 0) { 730 if (ret != AFC_E_SUCCESS) {
717 log_debug_msg("%s: Didn't receive a response to the command\n", __func__); 731 log_debug_msg("%s: Didn't receive a response to the command\n", __func__);
718 afc_unlock(client); 732 afc_unlock(client);
719 return AFC_E_NOT_ENOUGH_DATA; 733 return AFC_E_NOT_ENOUGH_DATA;
@@ -742,18 +756,19 @@ afc_file_open(afc_client_t client, const char *filename,
742 * @param handle File handle of a previously opened file 756 * @param handle File handle of a previously opened file
743 * @param data The pointer to the memory region to store the read data 757 * @param data The pointer to the memory region to store the read data
744 * @param length The number of bytes to read 758 * @param length The number of bytes to read
759 * @param bytes_read The number of bytes actually read.
745 * 760 *
746 * @return The number of bytes read if successful. If there was an error -1. 761 * @return AFC_E_SUCCESS on success or an AFC_E_* error value on error.
747 */ 762 */
748iphone_error_t 763iphone_error_t
749afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint32_t * bytes) 764afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, uint32_t *bytes_read)
750{ 765{
751 char *input = NULL; 766 char *input = NULL;
752 int current_count = 0, bytes_loc = 0; 767 uint32_t current_count = 0, bytes_loc = 0;
753 const int MAXIMUM_READ_SIZE = 1 << 16; 768 const uint32_t MAXIMUM_READ_SIZE = 1 << 16;
754 afc_error_t ret = AFC_E_SUCCESS; 769 afc_error_t ret = AFC_E_SUCCESS;
755 770
756 if (!client || !client->afc_packet || !client->connection || handle == 0 || (length < 0)) 771 if (!client || !client->afc_packet || !client->connection || handle == 0)
757 return AFC_E_INVALID_ARGUMENT; 772 return AFC_E_INVALID_ARGUMENT;
758 log_debug_msg("%s: called for length %i\n", __func__, length); 773 log_debug_msg("%s: called for length %i\n", __func__, length);
759 774
@@ -770,10 +785,10 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint
770 packet->size = GUINT64_TO_LE(((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE); 785 packet->size = GUINT64_TO_LE(((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE);
771 client->afc_packet->operation = AFC_OP_READ; 786 client->afc_packet->operation = AFC_OP_READ;
772 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 787 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
773 bytes_loc = afc_dispatch_packet(client, (char *) packet, sizeof(AFCFilePacket)); 788 ret = afc_dispatch_packet(client, (char *) packet, sizeof(AFCFilePacket), &bytes_loc);
774 free(packet); 789 free(packet);
775 790
776 if (bytes_loc <= 0) { 791 if (ret != AFC_E_SUCCESS) {
777 afc_unlock(client); 792 afc_unlock(client);
778 return AFC_E_NOT_ENOUGH_DATA; 793 return AFC_E_NOT_ENOUGH_DATA;
779 } 794 }
@@ -788,7 +803,7 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint
788 if (input) 803 if (input)
789 free(input); 804 free(input);
790 afc_unlock(client); 805 afc_unlock(client);
791 *bytes = current_count; 806 *bytes_read = current_count;
792 /* FIXME: check that's actually a success */ 807 /* FIXME: check that's actually a success */
793 return ret; 808 return ret;
794 } else { 809 } else {
@@ -804,7 +819,7 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint
804 log_debug_msg("%s: returning current_count as %i\n", __func__, current_count); 819 log_debug_msg("%s: returning current_count as %i\n", __func__, current_count);
805 820
806 afc_unlock(client); 821 afc_unlock(client);
807 *bytes = current_count; 822 *bytes_read = current_count;
808 return ret; 823 return ret;
809} 824}
810 825
@@ -814,23 +829,22 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, int length, uint
814 * @param handle File handle of previously opened file. 829 * @param handle File handle of previously opened file.
815 * @param data The data to write to the file. 830 * @param data The data to write to the file.
816 * @param length How much data to write. 831 * @param length How much data to write.
832 * @param bytes_written The number of bytes actually written to the file.
817 * 833 *
818 * @return The number of bytes written to the file, or a value less than 0 if 834 * @return AFC_E_SUCCESS on success, or an AFC_E_* error value on error.
819 * none were written...
820 */ 835 */
821iphone_error_t 836iphone_error_t
822afc_file_write(afc_client_t client, uint64_t handle, 837afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t length, uint32_t *bytes_written)
823 const char *data, int length, uint32_t * bytes)
824{ 838{
825 char *acknowledgement = NULL; 839 char *acknowledgement = NULL;
826 const int MAXIMUM_WRITE_SIZE = 1 << 15; 840 const uint32_t MAXIMUM_WRITE_SIZE = 1 << 15;
827 uint32_t current_count = 0, i = 0; 841 uint32_t current_count = 0, i = 0;
828 uint32_t segments = (length / MAXIMUM_WRITE_SIZE); 842 uint32_t segments = (length / MAXIMUM_WRITE_SIZE);
829 int bytes_loc = 0; 843 uint32_t bytes_loc = 0;
830 char *out_buffer = NULL; 844 char *out_buffer = NULL;
831 afc_error_t ret = AFC_E_SUCCESS; 845 afc_error_t ret = AFC_E_SUCCESS;
832 846
833 if (!client || !client->afc_packet || !client->connection || !bytes || (handle == 0) || (length < 0)) 847 if (!client || !client->afc_packet || !client->connection || !bytes_written || (handle == 0))
834 return AFC_E_INVALID_ARGUMENT; 848 return AFC_E_INVALID_ARGUMENT;
835 849
836 afc_lock(client); 850 afc_lock(client);
@@ -846,8 +860,8 @@ afc_file_write(afc_client_t client, uint64_t handle,
846 out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket)); 860 out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket));
847 memcpy(out_buffer, (char *)&handle, sizeof(uint64_t)); 861 memcpy(out_buffer, (char *)&handle, sizeof(uint64_t));
848 memcpy(out_buffer + 8, data + current_count, MAXIMUM_WRITE_SIZE); 862 memcpy(out_buffer + 8, data + current_count, MAXIMUM_WRITE_SIZE);
849 bytes_loc = afc_dispatch_packet(client, out_buffer, MAXIMUM_WRITE_SIZE + 8); 863 ret = afc_dispatch_packet(client, out_buffer, MAXIMUM_WRITE_SIZE + 8, &bytes_loc);
850 if (bytes_loc < 0) { 864 if (ret != AFC_E_SUCCESS) {
851 afc_unlock(client); 865 afc_unlock(client);
852 return AFC_E_NOT_ENOUGH_DATA; 866 return AFC_E_NOT_ENOUGH_DATA;
853 } 867 }
@@ -868,9 +882,9 @@ afc_file_write(afc_client_t client, uint64_t handle,
868 // didn't get sent in the for loop 882 // didn't get sent in the for loop
869 // this length is fine because it's always sizeof(AFCPacket) + 8, but 883 // this length is fine because it's always sizeof(AFCPacket) + 8, but
870 // to be sure we do it again 884 // to be sure we do it again
871 if (current_count == (uint32_t)length) { 885 if (current_count == length) {
872 afc_unlock(client); 886 afc_unlock(client);
873 *bytes = current_count; 887 *bytes_written = current_count;
874 return ret; 888 return ret;
875 } 889 }
876 890
@@ -880,15 +894,15 @@ afc_file_write(afc_client_t client, uint64_t handle,
880 out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket)); 894 out_buffer = (char *) malloc(sizeof(char) * client->afc_packet->entire_length - sizeof(AFCPacket));
881 memcpy(out_buffer, (char *) &handle, sizeof(uint64_t)); 895 memcpy(out_buffer, (char *) &handle, sizeof(uint64_t));
882 memcpy(out_buffer + 8, data + current_count, (length - current_count)); 896 memcpy(out_buffer + 8, data + current_count, (length - current_count));
883 bytes_loc = afc_dispatch_packet(client, out_buffer, (length - current_count) + 8); 897 ret = afc_dispatch_packet(client, out_buffer, (length - current_count) + 8, &bytes_loc);
884 free(out_buffer); 898 free(out_buffer);
885 out_buffer = NULL; 899 out_buffer = NULL;
886 900
887 current_count += bytes_loc; 901 current_count += bytes_loc;
888 902
889 if (bytes_loc <= 0) { 903 if (ret != AFC_E_SUCCESS) {
890 afc_unlock(client); 904 afc_unlock(client);
891 *bytes = current_count; 905 *bytes_written = current_count;
892 return AFC_E_SUCCESS; 906 return AFC_E_SUCCESS;
893 } 907 }
894 908
@@ -899,7 +913,7 @@ afc_file_write(afc_client_t client, uint64_t handle,
899 } else { 913 } else {
900 free(acknowledgement); 914 free(acknowledgement);
901 } 915 }
902 *bytes = current_count; 916 *bytes_written = current_count;
903 return ret; 917 return ret;
904} 918}
905 919
@@ -911,7 +925,7 @@ afc_file_write(afc_client_t client, uint64_t handle,
911afc_error_t afc_file_close(afc_client_t client, uint64_t handle) 925afc_error_t afc_file_close(afc_client_t client, uint64_t handle)
912{ 926{
913 char *buffer = malloc(sizeof(char) * 8); 927 char *buffer = malloc(sizeof(char) * 8);
914 int bytes = 0; 928 uint32_t bytes = 0;
915 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 929 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
916 930
917 if (!client || (handle == 0)) 931 if (!client || (handle == 0))
@@ -925,11 +939,11 @@ afc_error_t afc_file_close(afc_client_t client, uint64_t handle)
925 memcpy(buffer, &handle, sizeof(uint64_t)); 939 memcpy(buffer, &handle, sizeof(uint64_t));
926 client->afc_packet->operation = AFC_OP_FILE_CLOSE; 940 client->afc_packet->operation = AFC_OP_FILE_CLOSE;
927 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 941 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
928 bytes = afc_dispatch_packet(client, buffer, 8); 942 ret = afc_dispatch_packet(client, buffer, 8, &bytes);
929 free(buffer); 943 free(buffer);
930 buffer = NULL; 944 buffer = NULL;
931 945
932 if (bytes <= 0) { 946 if (ret != AFC_E_SUCCESS) {
933 afc_unlock(client); 947 afc_unlock(client);
934 return AFC_E_UNKNOWN_ERROR; 948 return AFC_E_UNKNOWN_ERROR;
935 } 949 }
@@ -958,7 +972,7 @@ afc_error_t afc_file_close(afc_client_t client, uint64_t handle)
958afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t operation) 972afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t operation)
959{ 973{
960 char *buffer = malloc(16); 974 char *buffer = malloc(16);
961 int bytes = 0; 975 uint32_t bytes = 0;
962 uint64_t op = GUINT64_TO_LE(operation); 976 uint64_t op = GUINT64_TO_LE(operation);
963 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 977 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
964 978
@@ -975,11 +989,11 @@ afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t op
975 989
976 client->afc_packet->operation = AFC_OP_FILE_LOCK; 990 client->afc_packet->operation = AFC_OP_FILE_LOCK;
977 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 991 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
978 bytes = afc_dispatch_packet(client, buffer, 16); 992 ret = afc_dispatch_packet(client, buffer, 16, &bytes);
979 free(buffer); 993 free(buffer);
980 buffer = NULL; 994 buffer = NULL;
981 995
982 if (bytes <= 0) { 996 if (ret != AFC_E_SUCCESS) {
983 afc_unlock(client); 997 afc_unlock(client);
984 log_debug_msg("%s: could not send lock command\n", __func__); 998 log_debug_msg("%s: could not send lock command\n", __func__);
985 return AFC_E_UNKNOWN_ERROR; 999 return AFC_E_UNKNOWN_ERROR;
@@ -1009,7 +1023,7 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset,
1009 char *buffer = (char *) malloc(sizeof(char) * 24); 1023 char *buffer = (char *) malloc(sizeof(char) * 24);
1010 int64_t offset_loc = (int64_t)GUINT64_TO_LE(offset); 1024 int64_t offset_loc = (int64_t)GUINT64_TO_LE(offset);
1011 uint64_t whence_loc = GUINT64_TO_LE(whence); 1025 uint64_t whence_loc = GUINT64_TO_LE(whence);
1012 int bytes = 0; 1026 uint32_t bytes = 0;
1013 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1027 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1014 1028
1015 if (!client || (handle == 0)) 1029 if (!client || (handle == 0))
@@ -1023,11 +1037,11 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset,
1023 memcpy(buffer + 16, &offset_loc, sizeof(uint64_t)); // offset 1037 memcpy(buffer + 16, &offset_loc, sizeof(uint64_t)); // offset
1024 client->afc_packet->operation = AFC_OP_FILE_SEEK; 1038 client->afc_packet->operation = AFC_OP_FILE_SEEK;
1025 client->afc_packet->this_length = client->afc_packet->entire_length = 0; 1039 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
1026 bytes = afc_dispatch_packet(client, buffer, 24); 1040 ret = afc_dispatch_packet(client, buffer, 24, &bytes);
1027 free(buffer); 1041 free(buffer);
1028 buffer = NULL; 1042 buffer = NULL;
1029 1043
1030 if (bytes <= 0) { 1044 if (ret != AFC_E_SUCCESS) {
1031 afc_unlock(client); 1045 afc_unlock(client);
1032 return AFC_E_NOT_ENOUGH_DATA; 1046 return AFC_E_NOT_ENOUGH_DATA;
1033 } 1047 }
@@ -1052,7 +1066,7 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset,
1052afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position) 1066afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position)
1053{ 1067{
1054 char *buffer = (char *) malloc(sizeof(char) * 8); 1068 char *buffer = (char *) malloc(sizeof(char) * 8);
1055 int bytes = 0; 1069 uint32_t bytes = 0;
1056 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1070 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1057 1071
1058 if (!client || (handle == 0)) 1072 if (!client || (handle == 0))
@@ -1064,11 +1078,11 @@ afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *positi
1064 memcpy(buffer, &handle, sizeof(uint64_t)); // handle 1078 memcpy(buffer, &handle, sizeof(uint64_t)); // handle
1065 client->afc_packet->operation = AFC_OP_FILE_TELL; 1079 client->afc_packet->operation = AFC_OP_FILE_TELL;
1066 client->afc_packet->this_length = client->afc_packet->entire_length = 0; 1080 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
1067 bytes = afc_dispatch_packet(client, buffer, 8); 1081 ret = afc_dispatch_packet(client, buffer, 8, &bytes);
1068 free(buffer); 1082 free(buffer);
1069 buffer = NULL; 1083 buffer = NULL;
1070 1084
1071 if (bytes <= 0) { 1085 if (ret != AFC_E_SUCCESS) {
1072 afc_unlock(client); 1086 afc_unlock(client);
1073 return AFC_E_NOT_ENOUGH_DATA; 1087 return AFC_E_NOT_ENOUGH_DATA;
1074 } 1088 }
@@ -1102,7 +1116,7 @@ afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *positi
1102afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize) 1116afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t newsize)
1103{ 1117{
1104 char *buffer = (char *) malloc(sizeof(char) * 16); 1118 char *buffer = (char *) malloc(sizeof(char) * 16);
1105 int bytes = 0; 1119 uint32_t bytes = 0;
1106 uint64_t newsize_loc = GUINT64_TO_LE(newsize); 1120 uint64_t newsize_loc = GUINT64_TO_LE(newsize);
1107 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1121 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1108 1122
@@ -1116,11 +1130,11 @@ afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t new
1116 memcpy(buffer + 8, &newsize_loc, sizeof(uint64_t)); // newsize 1130 memcpy(buffer + 8, &newsize_loc, sizeof(uint64_t)); // newsize
1117 client->afc_packet->operation = AFC_OP_FILE_SET_SIZE; 1131 client->afc_packet->operation = AFC_OP_FILE_SET_SIZE;
1118 client->afc_packet->this_length = client->afc_packet->entire_length = 0; 1132 client->afc_packet->this_length = client->afc_packet->entire_length = 0;
1119 bytes = afc_dispatch_packet(client, buffer, 16); 1133 ret = afc_dispatch_packet(client, buffer, 16, &bytes);
1120 free(buffer); 1134 free(buffer);
1121 buffer = NULL; 1135 buffer = NULL;
1122 1136
1123 if (bytes <= 0) { 1137 if (ret != AFC_E_SUCCESS) {
1124 afc_unlock(client); 1138 afc_unlock(client);
1125 return AFC_E_NOT_ENOUGH_DATA; 1139 return AFC_E_NOT_ENOUGH_DATA;
1126 } 1140 }
@@ -1147,7 +1161,7 @@ afc_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize)
1147{ 1161{
1148 char *response = NULL; 1162 char *response = NULL;
1149 char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8)); 1163 char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8));
1150 int bytes = 0; 1164 uint32_t bytes = 0;
1151 uint64_t size_requested = GUINT64_TO_LE(newsize); 1165 uint64_t size_requested = GUINT64_TO_LE(newsize);
1152 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1166 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1153 1167
@@ -1161,9 +1175,9 @@ afc_error_t afc_truncate(afc_client_t client, const char *path, off_t newsize)
1161 memcpy(send + 8, path, strlen(path) + 1); 1175 memcpy(send + 8, path, strlen(path) + 1);
1162 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 1176 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
1163 client->afc_packet->operation = AFC_OP_TRUNCATE; 1177 client->afc_packet->operation = AFC_OP_TRUNCATE;
1164 bytes = afc_dispatch_packet(client, send, 8 + strlen(path) + 1); 1178 ret = afc_dispatch_packet(client, send, 8 + strlen(path) + 1, &bytes);
1165 free(send); 1179 free(send);
1166 if (bytes <= 0) { 1180 if (ret != AFC_E_SUCCESS) {
1167 afc_unlock(client); 1181 afc_unlock(client);
1168 return AFC_E_NOT_ENOUGH_DATA; 1182 return AFC_E_NOT_ENOUGH_DATA;
1169 } 1183 }
@@ -1191,7 +1205,7 @@ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const c
1191{ 1205{
1192 char *response = NULL; 1206 char *response = NULL;
1193 char *send = (char *) malloc(sizeof(char) * (strlen(target)+1 + strlen(linkname)+1 + 8)); 1207 char *send = (char *) malloc(sizeof(char) * (strlen(target)+1 + strlen(linkname)+1 + 8));
1194 int bytes = 0; 1208 uint32_t bytes = 0;
1195 uint64_t type = GUINT64_TO_LE(linktype); 1209 uint64_t type = GUINT64_TO_LE(linktype);
1196 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1210 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1197 1211
@@ -1210,9 +1224,9 @@ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const c
1210 memcpy(send + 8 + strlen(target) + 1, linkname, strlen(linkname) + 1); 1224 memcpy(send + 8 + strlen(target) + 1, linkname, strlen(linkname) + 1);
1211 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 1225 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
1212 client->afc_packet->operation = AFC_OP_MAKE_LINK; 1226 client->afc_packet->operation = AFC_OP_MAKE_LINK;
1213 bytes = afc_dispatch_packet(client, send, 8 + strlen(linkname) + 1 + strlen(target) + 1); 1227 ret = afc_dispatch_packet(client, send, 8 + strlen(linkname) + 1 + strlen(target) + 1, &bytes);
1214 free(send); 1228 free(send);
1215 if (bytes <= 0) { 1229 if (ret != AFC_E_SUCCESS) {
1216 afc_unlock(client); 1230 afc_unlock(client);
1217 return AFC_E_NOT_ENOUGH_DATA; 1231 return AFC_E_NOT_ENOUGH_DATA;
1218 } 1232 }
@@ -1239,7 +1253,7 @@ afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mt
1239{ 1253{
1240 char *response = NULL; 1254 char *response = NULL;
1241 char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8)); 1255 char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8));
1242 int bytes = 0; 1256 uint32_t bytes = 0;
1243 uint64_t mtime_loc = GUINT64_TO_LE(mtime); 1257 uint64_t mtime_loc = GUINT64_TO_LE(mtime);
1244 afc_error_t ret = AFC_E_UNKNOWN_ERROR; 1258 afc_error_t ret = AFC_E_UNKNOWN_ERROR;
1245 1259
@@ -1253,9 +1267,9 @@ afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mt
1253 memcpy(send + 8, path, strlen(path) + 1); 1267 memcpy(send + 8, path, strlen(path) + 1);
1254 client->afc_packet->entire_length = client->afc_packet->this_length = 0; 1268 client->afc_packet->entire_length = client->afc_packet->this_length = 0;
1255 client->afc_packet->operation = AFC_OP_SET_FILE_TIME; 1269 client->afc_packet->operation = AFC_OP_SET_FILE_TIME;
1256 bytes = afc_dispatch_packet(client, send, 8 + strlen(path) + 1); 1270 ret = afc_dispatch_packet(client, send, 8 + strlen(path) + 1, &bytes);
1257 free(send); 1271 free(send);
1258 if (bytes <= 0) { 1272 if (ret != AFC_E_SUCCESS) {
1259 afc_unlock(client); 1273 afc_unlock(client);
1260 return AFC_E_NOT_ENOUGH_DATA; 1274 return AFC_E_NOT_ENOUGH_DATA;
1261 } 1275 }