diff options
| author | 2010-03-16 03:13:38 +0100 | |
|---|---|---|
| committer | 2010-03-16 03:13:38 +0100 | |
| commit | 08d2af5d611319748afba2aaba5e6c8a99f1b396 (patch) | |
| tree | 8bf4a3533f2acf11368dc37a9c653689ace99b77 /src/afc.c | |
| parent | 3e0c5021100c879ff7d0776d4c7bb4f0ec88e0d7 (diff) | |
| download | libimobiledevice-08d2af5d611319748afba2aaba5e6c8a99f1b396.tar.gz libimobiledevice-08d2af5d611319748afba2aaba5e6c8a99f1b396.tar.bz2 | |
Complete documentation of public interface and fix a lot of bogus comments
This change unifies the documentation comment syntax, fixes a few bad
documentation comments and completes documentation where it was missing.
Diffstat (limited to 'src/afc.c')
| -rw-r--r-- | src/afc.c | 213 |
1 files changed, 120 insertions, 93 deletions
| @@ -27,10 +27,11 @@ | |||
| 27 | #include "idevice.h" | 27 | #include "idevice.h" |
| 28 | #include "debug.h" | 28 | #include "debug.h" |
| 29 | 29 | ||
| 30 | // This is the maximum size an AFC data packet can be | 30 | /** The maximum size an AFC data packet can be */ |
| 31 | static const int MAXIMUM_PACKET_SIZE = (2 << 15); | 31 | static const int MAXIMUM_PACKET_SIZE = (2 << 15); |
| 32 | 32 | ||
| 33 | /** Locks an AFC client, done for thread safety stuff | 33 | /** |
| 34 | * Locks an AFC client, done for thread safety stuff | ||
| 34 | * | 35 | * |
| 35 | * @param client The AFC client connection to lock | 36 | * @param client The AFC client connection to lock |
| 36 | */ | 37 | */ |
| @@ -40,7 +41,8 @@ static void afc_lock(afc_client_t client) | |||
| 40 | g_mutex_lock(client->mutex); | 41 | g_mutex_lock(client->mutex); |
| 41 | } | 42 | } |
| 42 | 43 | ||
| 43 | /** Unlocks an AFC client, done for thread safety stuff. | 44 | /** |
| 45 | * Unlocks an AFC client, done for thread safety stuff. | ||
| 44 | * | 46 | * |
| 45 | * @param client The AFC | 47 | * @param client The AFC |
| 46 | */ | 48 | */ |
| @@ -50,7 +52,8 @@ static void afc_unlock(afc_client_t client) | |||
| 50 | g_mutex_unlock(client->mutex); | 52 | g_mutex_unlock(client->mutex); |
| 51 | } | 53 | } |
| 52 | 54 | ||
| 53 | /** Makes a connection to the AFC service on the phone. | 55 | /** |
| 56 | * Makes a connection to the AFC service on the phone. | ||
| 54 | * | 57 | * |
| 55 | * @param device The device to connect to. | 58 | * @param device The device to connect to. |
| 56 | * @param port The destination port. | 59 | * @param port The destination port. |
| @@ -118,14 +121,15 @@ afc_error_t afc_client_free(afc_client_t client) | |||
| 118 | return AFC_E_SUCCESS; | 121 | return AFC_E_SUCCESS; |
| 119 | } | 122 | } |
| 120 | 123 | ||
| 121 | /** Dispatches an AFC packet over a client. | 124 | /** |
| 125 | * Dispatches an AFC packet over a client. | ||
| 122 | * | 126 | * |
| 123 | * @param client The client to send data through. | 127 | * @param client The client to send data through. |
| 124 | * @param data The data to send. | 128 | * @param data The data to send. |
| 125 | * @param length The length to send. | 129 | * @param length The length to send. |
| 126 | * @param bytes_sent The number of bytes actually sent. | 130 | * @param bytes_sent The number of bytes actually sent. |
| 127 | * | 131 | * |
| 128 | * @return AFC_E_SUCCESS on success, or an AFC_E_* error value on error. | 132 | * @return AFC_E_SUCCESS on success or an AFC_E_* error value. |
| 129 | * | 133 | * |
| 130 | * @warning set client->afc_packet->this_length and | 134 | * @warning set client->afc_packet->this_length and |
| 131 | * client->afc_packet->entire_length to 0 before calling this. The | 135 | * client->afc_packet->entire_length to 0 before calling this. The |
| @@ -153,9 +157,9 @@ static afc_error_t afc_dispatch_packet(afc_client_t client, const char *data, ui | |||
| 153 | if (!client->afc_packet->this_length) { | 157 | if (!client->afc_packet->this_length) { |
| 154 | client->afc_packet->this_length = sizeof(AFCPacket); | 158 | client->afc_packet->this_length = sizeof(AFCPacket); |
| 155 | } | 159 | } |
| 156 | // We want to send two segments; buffer+sizeof(AFCPacket) to | 160 | /* We want to send two segments; buffer+sizeof(AFCPacket) to this_length |
| 157 | // this_length is the parameters | 161 | is the parameters and everything beyond that is the next packet. |
| 158 | // And everything beyond that is the next packet. (for writing) | 162 | (for writing) */ |
| 159 | if (client->afc_packet->this_length != client->afc_packet->entire_length) { | 163 | if (client->afc_packet->this_length != client->afc_packet->entire_length) { |
| 160 | offset = client->afc_packet->this_length - sizeof(AFCPacket); | 164 | offset = client->afc_packet->this_length - sizeof(AFCPacket); |
| 161 | 165 | ||
| @@ -222,14 +226,14 @@ static afc_error_t afc_dispatch_packet(afc_client_t client, const char *data, ui | |||
| 222 | return AFC_E_INTERNAL_ERROR; | 226 | return AFC_E_INTERNAL_ERROR; |
| 223 | } | 227 | } |
| 224 | 228 | ||
| 225 | /** Receives data through an AFC client and sets a variable to the received data. | 229 | /** |
| 230 | * Receives data through an AFC client and sets a variable to the received data. | ||
| 226 | * | 231 | * |
| 227 | * @param client The client to receive data on. | 232 | * @param client The client to receive data on. |
| 228 | * @param dump_here The char* to point to the newly-received data. | 233 | * @param dump_here The char* to point to the newly-received data. |
| 229 | * @param bytes_recv How much data was received. | 234 | * @param bytes_recv How much data was received. |
| 230 | * | 235 | * |
| 231 | * @return AFC_E_SUCCESS when data has been received, or an AFC_E_* error value | 236 | * @return AFC_E_SUCCESS on success or an AFC_E_* error value. |
| 232 | * when an error occured. | ||
| 233 | */ | 237 | */ |
| 234 | static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, uint32_t *bytes_recv) | 238 | static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, uint32_t *bytes_recv) |
| 235 | { | 239 | { |
| @@ -371,6 +375,9 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, uint3 | |||
| 371 | return AFC_E_SUCCESS; | 375 | return AFC_E_SUCCESS; |
| 372 | } | 376 | } |
| 373 | 377 | ||
| 378 | /** | ||
| 379 | * Returns counts of null characters within a string. | ||
| 380 | */ | ||
| 374 | static uint32_t count_nullspaces(char *string, uint32_t number) | 381 | static uint32_t count_nullspaces(char *string, uint32_t number) |
| 375 | { | 382 | { |
| 376 | uint32_t i = 0, nulls = 0; | 383 | uint32_t i = 0, nulls = 0; |
| @@ -412,13 +419,15 @@ static char **make_strings_list(char *tokens, uint32_t length) | |||
| 412 | return list; | 419 | return list; |
| 413 | } | 420 | } |
| 414 | 421 | ||
| 415 | /** Gets a directory listing of the directory requested. | 422 | /** |
| 423 | * Gets a directory listing of the directory requested. | ||
| 416 | * | 424 | * |
| 417 | * @param client The client to get a directory listing from. | 425 | * @param client The client to get a directory listing from. |
| 418 | * @param dir The directory to list. (must be a fully-qualified path) | 426 | * @param dir The directory to list. (must be a fully-qualified path) |
| 427 | * @param list A char list of files in that directory, terminated by an empty | ||
| 428 | * string or NULL if there was an error. | ||
| 419 | * | 429 | * |
| 420 | * @return A char ** list of files in that directory, terminated by an empty | 430 | * @return AFC_E_SUCCESS on success or an AFC_E_* error value. |
| 421 | * string for now or NULL if there was an error. | ||
| 422 | */ | 431 | */ |
| 423 | afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***list) | 432 | afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***list) |
| 424 | { | 433 | { |
| @@ -431,7 +440,7 @@ afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***lis | |||
| 431 | 440 | ||
| 432 | afc_lock(client); | 441 | afc_lock(client); |
| 433 | 442 | ||
| 434 | // Send the command | 443 | /* Send the command */ |
| 435 | client->afc_packet->operation = AFC_OP_READ_DIR; | 444 | client->afc_packet->operation = AFC_OP_READ_DIR; |
| 436 | client->afc_packet->entire_length = 0; | 445 | client->afc_packet->entire_length = 0; |
| 437 | client->afc_packet->this_length = 0; | 446 | client->afc_packet->this_length = 0; |
| @@ -440,13 +449,13 @@ afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***lis | |||
| 440 | afc_unlock(client); | 449 | afc_unlock(client); |
| 441 | return AFC_E_NOT_ENOUGH_DATA; | 450 | return AFC_E_NOT_ENOUGH_DATA; |
| 442 | } | 451 | } |
| 443 | // Receive the data | 452 | /* Receive the data */ |
| 444 | ret = afc_receive_data(client, &data, &bytes); | 453 | ret = afc_receive_data(client, &data, &bytes); |
| 445 | if (ret != AFC_E_SUCCESS) { | 454 | if (ret != AFC_E_SUCCESS) { |
| 446 | afc_unlock(client); | 455 | afc_unlock(client); |
| 447 | return ret; | 456 | return ret; |
| 448 | } | 457 | } |
| 449 | // Parse the data | 458 | /* Parse the data */ |
| 450 | list_loc = make_strings_list(data, bytes); | 459 | list_loc = make_strings_list(data, bytes); |
| 451 | if (data) | 460 | if (data) |
| 452 | free(data); | 461 | free(data); |
| @@ -457,12 +466,16 @@ afc_error_t afc_read_directory(afc_client_t client, const char *dir, char ***lis | |||
| 457 | return ret; | 466 | return ret; |
| 458 | } | 467 | } |
| 459 | 468 | ||
| 460 | /** Get device info for a client connection to phone. (free space on disk, etc.) | 469 | /** |
| 470 | * Get device info for a client connection to phone. The device information | ||
| 471 | * returned is the device model as well as the free space, the total capacity | ||
| 472 | * and blocksize on the accessed disk partition. | ||
| 461 | * | 473 | * |
| 462 | * @param client The client to get device info for. | 474 | * @param client The client to get device info for. |
| 475 | * @param infos A char ** list of parameters as given by AFC or NULL if there | ||
| 476 | * was an error. | ||
| 463 | * | 477 | * |
| 464 | * @return A char ** list of parameters as given by AFC or NULL if there was an | 478 | * @return AFC_E_SUCCESS on success or an AFC_E_* error value. |
| 465 | * error. | ||
| 466 | */ | 479 | */ |
| 467 | afc_error_t afc_get_device_info(afc_client_t client, char ***infos) | 480 | afc_error_t afc_get_device_info(afc_client_t client, char ***infos) |
| 468 | { | 481 | { |
| @@ -475,7 +488,7 @@ afc_error_t afc_get_device_info(afc_client_t client, char ***infos) | |||
| 475 | 488 | ||
| 476 | afc_lock(client); | 489 | afc_lock(client); |
| 477 | 490 | ||
| 478 | // Send the command | 491 | /* Send the command */ |
| 479 | client->afc_packet->operation = AFC_OP_GET_DEVINFO; | 492 | client->afc_packet->operation = AFC_OP_GET_DEVINFO; |
| 480 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; | 493 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; |
| 481 | ret = afc_dispatch_packet(client, NULL, 0, &bytes); | 494 | ret = afc_dispatch_packet(client, NULL, 0, &bytes); |
| @@ -483,13 +496,13 @@ afc_error_t afc_get_device_info(afc_client_t client, char ***infos) | |||
| 483 | afc_unlock(client); | 496 | afc_unlock(client); |
| 484 | return AFC_E_NOT_ENOUGH_DATA; | 497 | return AFC_E_NOT_ENOUGH_DATA; |
| 485 | } | 498 | } |
| 486 | // Receive the data | 499 | /* Receive the data */ |
| 487 | ret = afc_receive_data(client, &data, &bytes); | 500 | ret = afc_receive_data(client, &data, &bytes); |
| 488 | if (ret != AFC_E_SUCCESS) { | 501 | if (ret != AFC_E_SUCCESS) { |
| 489 | afc_unlock(client); | 502 | afc_unlock(client); |
| 490 | return ret; | 503 | return ret; |
| 491 | } | 504 | } |
| 492 | // Parse the data | 505 | /* Parse the data */ |
| 493 | list = make_strings_list(data, bytes); | 506 | list = make_strings_list(data, bytes); |
| 494 | if (data) | 507 | if (data) |
| 495 | free(data); | 508 | free(data); |
| @@ -501,7 +514,8 @@ afc_error_t afc_get_device_info(afc_client_t client, char ***infos) | |||
| 501 | return ret; | 514 | return ret; |
| 502 | } | 515 | } |
| 503 | 516 | ||
| 504 | /** Get a specific key of the device info list for a client connection. | 517 | /** |
| 518 | * Get a specific key of the device info list for a client connection. | ||
| 505 | * Known key values are: Model, FSTotalBytes, FSFreeBytes and FSBlockSize. | 519 | * Known key values are: Model, FSTotalBytes, FSFreeBytes and FSBlockSize. |
| 506 | * This is a helper function for afc_get_device_info(). | 520 | * This is a helper function for afc_get_device_info(). |
| 507 | * | 521 | * |
| @@ -536,7 +550,8 @@ afc_error_t afc_get_device_info_key(afc_client_t client, const char *key, char * | |||
| 536 | return ret; | 550 | return ret; |
| 537 | } | 551 | } |
| 538 | 552 | ||
| 539 | /** Deletes a file or directory. | 553 | /** |
| 554 | * Deletes a file or directory. | ||
| 540 | * | 555 | * |
| 541 | * @param client The client to use. | 556 | * @param client The client to use. |
| 542 | * @param path The path to delete. (must be a fully-qualified path) | 557 | * @param path The path to delete. (must be a fully-qualified path) |
| @@ -554,7 +569,7 @@ afc_error_t afc_remove_path(afc_client_t client, const char *path) | |||
| 554 | 569 | ||
| 555 | afc_lock(client); | 570 | afc_lock(client); |
| 556 | 571 | ||
| 557 | // Send command | 572 | /* Send command */ |
| 558 | client->afc_packet->this_length = client->afc_packet->entire_length = 0; | 573 | client->afc_packet->this_length = client->afc_packet->entire_length = 0; |
| 559 | client->afc_packet->operation = AFC_OP_REMOVE_PATH; | 574 | client->afc_packet->operation = AFC_OP_REMOVE_PATH; |
| 560 | ret = afc_dispatch_packet(client, path, strlen(path)+1, &bytes); | 575 | ret = afc_dispatch_packet(client, path, strlen(path)+1, &bytes); |
| @@ -562,7 +577,7 @@ afc_error_t afc_remove_path(afc_client_t client, const char *path) | |||
| 562 | afc_unlock(client); | 577 | afc_unlock(client); |
| 563 | return AFC_E_NOT_ENOUGH_DATA; | 578 | return AFC_E_NOT_ENOUGH_DATA; |
| 564 | } | 579 | } |
| 565 | // Receive response | 580 | /* Receive response */ |
| 566 | ret = afc_receive_data(client, &response, &bytes); | 581 | ret = afc_receive_data(client, &response, &bytes); |
| 567 | if (response) | 582 | if (response) |
| 568 | free(response); | 583 | free(response); |
| @@ -576,7 +591,8 @@ afc_error_t afc_remove_path(afc_client_t client, const char *path) | |||
| 576 | return ret; | 591 | return ret; |
| 577 | } | 592 | } |
| 578 | 593 | ||
| 579 | /** Renames a file or directory on the phone. | 594 | /** |
| 595 | * Renames a file or directory on the phone. | ||
| 580 | * | 596 | * |
| 581 | * @param client The client to have rename. | 597 | * @param client The client to have rename. |
| 582 | * @param from The name to rename from. (must be a fully-qualified path) | 598 | * @param from The name to rename from. (must be a fully-qualified path) |
| @@ -596,7 +612,7 @@ afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *t | |||
| 596 | 612 | ||
| 597 | afc_lock(client); | 613 | afc_lock(client); |
| 598 | 614 | ||
| 599 | // Send command | 615 | /* Send command */ |
| 600 | memcpy(send, from, strlen(from) + 1); | 616 | memcpy(send, from, strlen(from) + 1); |
| 601 | memcpy(send + strlen(from) + 1, to, strlen(to) + 1); | 617 | memcpy(send + strlen(from) + 1, to, strlen(to) + 1); |
| 602 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; | 618 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; |
| @@ -607,7 +623,7 @@ afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *t | |||
| 607 | afc_unlock(client); | 623 | afc_unlock(client); |
| 608 | return AFC_E_NOT_ENOUGH_DATA; | 624 | return AFC_E_NOT_ENOUGH_DATA; |
| 609 | } | 625 | } |
| 610 | // Receive response | 626 | /* Receive response */ |
| 611 | ret = afc_receive_data(client, &response, &bytes); | 627 | ret = afc_receive_data(client, &response, &bytes); |
| 612 | if (response) | 628 | if (response) |
| 613 | free(response); | 629 | free(response); |
| @@ -617,7 +633,8 @@ afc_error_t afc_rename_path(afc_client_t client, const char *from, const char *t | |||
| 617 | return ret; | 633 | return ret; |
| 618 | } | 634 | } |
| 619 | 635 | ||
| 620 | /** Creates a directory on the phone. | 636 | /** |
| 637 | * Creates a directory on the phone. | ||
| 621 | * | 638 | * |
| 622 | * @param client The client to use to make a directory. | 639 | * @param client The client to use to make a directory. |
| 623 | * @param dir The directory's path. (must be a fully-qualified path, I assume | 640 | * @param dir The directory's path. (must be a fully-qualified path, I assume |
| @@ -636,7 +653,7 @@ afc_error_t afc_make_directory(afc_client_t client, const char *dir) | |||
| 636 | 653 | ||
| 637 | afc_lock(client); | 654 | afc_lock(client); |
| 638 | 655 | ||
| 639 | // Send command | 656 | /* Send command */ |
| 640 | client->afc_packet->operation = AFC_OP_MAKE_DIR; | 657 | client->afc_packet->operation = AFC_OP_MAKE_DIR; |
| 641 | client->afc_packet->this_length = client->afc_packet->entire_length = 0; | 658 | client->afc_packet->this_length = client->afc_packet->entire_length = 0; |
| 642 | ret = afc_dispatch_packet(client, dir, strlen(dir)+1, &bytes); | 659 | ret = afc_dispatch_packet(client, dir, strlen(dir)+1, &bytes); |
| @@ -644,7 +661,7 @@ afc_error_t afc_make_directory(afc_client_t client, const char *dir) | |||
| 644 | afc_unlock(client); | 661 | afc_unlock(client); |
| 645 | return AFC_E_NOT_ENOUGH_DATA; | 662 | return AFC_E_NOT_ENOUGH_DATA; |
| 646 | } | 663 | } |
| 647 | // Receive response | 664 | /* Receive response */ |
| 648 | ret = afc_receive_data(client, &response, &bytes); | 665 | ret = afc_receive_data(client, &response, &bytes); |
| 649 | if (response) | 666 | if (response) |
| 650 | free(response); | 667 | free(response); |
| @@ -654,7 +671,8 @@ afc_error_t afc_make_directory(afc_client_t client, const char *dir) | |||
| 654 | return ret; | 671 | return ret; |
| 655 | } | 672 | } |
| 656 | 673 | ||
| 657 | /** Gets information about a specific file. | 674 | /** |
| 675 | * Gets information about a specific file. | ||
| 658 | * | 676 | * |
| 659 | * @param client The client to use to get the information of the file. | 677 | * @param client The client to use to get the information of the file. |
| 660 | * @param path The fully-qualified path to the file. | 678 | * @param path The fully-qualified path to the file. |
| @@ -662,8 +680,7 @@ afc_error_t afc_make_directory(afc_client_t client, const char *dir) | |||
| 662 | * list of strings with the file information. | 680 | * list of strings with the file information. |
| 663 | * Set to NULL before calling this function. | 681 | * Set to NULL before calling this function. |
| 664 | * | 682 | * |
| 665 | * @return AFC_E_SUCCESS on success or an AFC_E_* error value | 683 | * @return AFC_E_SUCCESS on success or an AFC_E_* error value. |
| 666 | * when something went wrong. | ||
| 667 | */ | 684 | */ |
| 668 | afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***infolist) | 685 | afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***infolist) |
| 669 | { | 686 | { |
| @@ -676,7 +693,7 @@ afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***inf | |||
| 676 | 693 | ||
| 677 | afc_lock(client); | 694 | afc_lock(client); |
| 678 | 695 | ||
| 679 | // Send command | 696 | /* Send command */ |
| 680 | client->afc_packet->operation = AFC_OP_GET_FILE_INFO; | 697 | client->afc_packet->operation = AFC_OP_GET_FILE_INFO; |
| 681 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; | 698 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; |
| 682 | ret = afc_dispatch_packet(client, path, strlen(path)+1, &bytes); | 699 | ret = afc_dispatch_packet(client, path, strlen(path)+1, &bytes); |
| @@ -685,7 +702,7 @@ afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***inf | |||
| 685 | return AFC_E_NOT_ENOUGH_DATA; | 702 | return AFC_E_NOT_ENOUGH_DATA; |
| 686 | } | 703 | } |
| 687 | 704 | ||
| 688 | // Receive data | 705 | /* Receive data */ |
| 689 | ret = afc_receive_data(client, &received, &bytes); | 706 | ret = afc_receive_data(client, &received, &bytes); |
| 690 | if (received) { | 707 | if (received) { |
| 691 | *infolist = make_strings_list(received, bytes); | 708 | *infolist = make_strings_list(received, bytes); |
| @@ -697,7 +714,8 @@ afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***inf | |||
| 697 | return ret; | 714 | return ret; |
| 698 | } | 715 | } |
| 699 | 716 | ||
| 700 | /** Opens a file on the phone. | 717 | /** |
| 718 | * Opens a file on the phone. | ||
| 701 | * | 719 | * |
| 702 | * @param client The client to use to open the file. | 720 | * @param client The client to use to open the file. |
| 703 | * @param filename The file to open. (must be a fully-qualified path) | 721 | * @param filename The file to open. (must be a fully-qualified path) |
| @@ -707,7 +725,7 @@ afc_error_t afc_get_file_info(afc_client_t client, const char *path, char ***inf | |||
| 707 | * destroying anything previously there. | 725 | * destroying anything previously there. |
| 708 | * @param handle Pointer to a uint64_t that will hold the handle of the file | 726 | * @param handle Pointer to a uint64_t that will hold the handle of the file |
| 709 | * | 727 | * |
| 710 | * @return AFC_E_SUCCESS on success or an AFC_E_* error on failure. | 728 | * @return AFC_E_SUCCESS on success or an AFC_E_* error value. |
| 711 | */ | 729 | */ |
| 712 | idevice_error_t | 730 | idevice_error_t |
| 713 | afc_file_open(afc_client_t client, const char *filename, | 731 | afc_file_open(afc_client_t client, const char *filename, |
| @@ -718,7 +736,7 @@ afc_file_open(afc_client_t client, const char *filename, | |||
| 718 | char *data = (char *) malloc(sizeof(char) * (8 + strlen(filename) + 1)); | 736 | char *data = (char *) malloc(sizeof(char) * (8 + strlen(filename) + 1)); |
| 719 | afc_error_t ret = AFC_E_UNKNOWN_ERROR; | 737 | afc_error_t ret = AFC_E_UNKNOWN_ERROR; |
| 720 | 738 | ||
| 721 | // set handle to 0 so in case an error occurs, the handle is invalid | 739 | /* set handle to 0 so in case an error occurs, the handle is invalid */ |
| 722 | *handle = 0; | 740 | *handle = 0; |
| 723 | 741 | ||
| 724 | if (!client || !client->connection || !client->afc_packet) | 742 | if (!client || !client->connection || !client->afc_packet) |
| @@ -726,7 +744,7 @@ afc_file_open(afc_client_t client, const char *filename, | |||
| 726 | 744 | ||
| 727 | afc_lock(client); | 745 | afc_lock(client); |
| 728 | 746 | ||
| 729 | // Send command | 747 | /* Send command */ |
| 730 | memcpy(data, &file_mode_loc, 8); | 748 | memcpy(data, &file_mode_loc, 8); |
| 731 | memcpy(data + 8, filename, strlen(filename)); | 749 | memcpy(data + 8, filename, strlen(filename)); |
| 732 | data[8 + strlen(filename)] = '\0'; | 750 | data[8 + strlen(filename)] = '\0'; |
| @@ -740,12 +758,12 @@ afc_file_open(afc_client_t client, const char *filename, | |||
| 740 | afc_unlock(client); | 758 | afc_unlock(client); |
| 741 | return AFC_E_NOT_ENOUGH_DATA; | 759 | return AFC_E_NOT_ENOUGH_DATA; |
| 742 | } | 760 | } |
| 743 | // Receive the data | 761 | /* Receive the data */ |
| 744 | ret = afc_receive_data(client, &data, &bytes); | 762 | ret = afc_receive_data(client, &data, &bytes); |
| 745 | if ((ret == AFC_E_SUCCESS) && (bytes > 0) && data) { | 763 | if ((ret == AFC_E_SUCCESS) && (bytes > 0) && data) { |
| 746 | afc_unlock(client); | 764 | afc_unlock(client); |
| 747 | 765 | ||
| 748 | // Get the file handle | 766 | /* Get the file handle */ |
| 749 | memcpy(handle, data, sizeof(uint64_t)); | 767 | memcpy(handle, data, sizeof(uint64_t)); |
| 750 | free(data); | 768 | free(data); |
| 751 | return ret; | 769 | return ret; |
| @@ -758,7 +776,8 @@ afc_file_open(afc_client_t client, const char *filename, | |||
| 758 | return ret; | 776 | return ret; |
| 759 | } | 777 | } |
| 760 | 778 | ||
| 761 | /** Attempts to the read the given number of bytes from the given file. | 779 | /** |
| 780 | * Attempts to the read the given number of bytes from the given file. | ||
| 762 | * | 781 | * |
| 763 | * @param client The relevant AFC client | 782 | * @param client The relevant AFC client |
| 764 | * @param handle File handle of a previously opened file | 783 | * @param handle File handle of a previously opened file |
| @@ -766,7 +785,7 @@ afc_file_open(afc_client_t client, const char *filename, | |||
| 766 | * @param length The number of bytes to read | 785 | * @param length The number of bytes to read |
| 767 | * @param bytes_read The number of bytes actually read. | 786 | * @param bytes_read The number of bytes actually read. |
| 768 | * | 787 | * |
| 769 | * @return AFC_E_SUCCESS on success or an AFC_E_* error value on error. | 788 | * @return AFC_E_SUCCESS on success or an AFC_E_* error value. |
| 770 | */ | 789 | */ |
| 771 | idevice_error_t | 790 | idevice_error_t |
| 772 | afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, uint32_t *bytes_read) | 791 | afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, uint32_t *bytes_read) |
| @@ -782,12 +801,12 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, | |||
| 782 | 801 | ||
| 783 | afc_lock(client); | 802 | afc_lock(client); |
| 784 | 803 | ||
| 785 | // Looping here to get around the maximum amount of data that | 804 | /* Looping here to get around the maximum amount of data that |
| 786 | // afc_receive_data can handle | 805 | afc_receive_data can handle */ |
| 787 | while (current_count < length) { | 806 | while (current_count < length) { |
| 788 | debug_info("current count is %i but length is %i", current_count, length); | 807 | debug_info("current count is %i but length is %i", current_count, length); |
| 789 | 808 | ||
| 790 | // Send the read command | 809 | /* Send the read command */ |
| 791 | AFCFilePacket *packet = (AFCFilePacket *) malloc(sizeof(AFCFilePacket)); | 810 | AFCFilePacket *packet = (AFCFilePacket *) malloc(sizeof(AFCFilePacket)); |
| 792 | packet->filehandle = handle; | 811 | packet->filehandle = handle; |
| 793 | packet->size = GUINT64_TO_LE(((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE); | 812 | packet->size = GUINT64_TO_LE(((length - current_count) < MAXIMUM_READ_SIZE) ? (length - current_count) : MAXIMUM_READ_SIZE); |
| @@ -800,7 +819,7 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, | |||
| 800 | afc_unlock(client); | 819 | afc_unlock(client); |
| 801 | return AFC_E_NOT_ENOUGH_DATA; | 820 | return AFC_E_NOT_ENOUGH_DATA; |
| 802 | } | 821 | } |
| 803 | // Receive the data | 822 | /* Receive the data */ |
| 804 | ret = afc_receive_data(client, &input, &bytes_loc); | 823 | ret = afc_receive_data(client, &input, &bytes_loc); |
| 805 | debug_info("afc_receive_data returned error: %d", ret); | 824 | debug_info("afc_receive_data returned error: %d", ret); |
| 806 | debug_info("bytes returned: %i", bytes_loc); | 825 | debug_info("bytes returned: %i", bytes_loc); |
| @@ -831,7 +850,8 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, | |||
| 831 | return ret; | 850 | return ret; |
| 832 | } | 851 | } |
| 833 | 852 | ||
| 834 | /** Writes a given number of bytes to a file. | 853 | /** |
| 854 | * Writes a given number of bytes to a file. | ||
| 835 | * | 855 | * |
| 836 | * @param client The client to use to write to the file. | 856 | * @param client The client to use to write to the file. |
| 837 | * @param handle File handle of previously opened file. | 857 | * @param handle File handle of previously opened file. |
| @@ -839,7 +859,7 @@ afc_file_read(afc_client_t client, uint64_t handle, char *data, uint32_t length, | |||
| 839 | * @param length How much data to write. | 859 | * @param length How much data to write. |
| 840 | * @param bytes_written The number of bytes actually written to the file. | 860 | * @param bytes_written The number of bytes actually written to the file. |
| 841 | * | 861 | * |
| 842 | * @return AFC_E_SUCCESS on success, or an AFC_E_* error value on error. | 862 | * @return AFC_E_SUCCESS on success or an AFC_E_* error value. |
| 843 | */ | 863 | */ |
| 844 | idevice_error_t | 864 | idevice_error_t |
| 845 | afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t length, uint32_t *bytes_written) | 865 | afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t length, uint32_t *bytes_written) |
| @@ -859,9 +879,9 @@ afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t | |||
| 859 | 879 | ||
| 860 | debug_info("Write length: %i", length); | 880 | debug_info("Write length: %i", length); |
| 861 | 881 | ||
| 862 | // Divide the file into segments. | 882 | /* Divide the file into segments. */ |
| 863 | for (i = 0; i < segments; i++) { | 883 | for (i = 0; i < segments; i++) { |
| 864 | // Send the segment | 884 | /* Send the segment */ |
| 865 | client->afc_packet->this_length = sizeof(AFCPacket) + 8; | 885 | client->afc_packet->this_length = sizeof(AFCPacket) + 8; |
| 866 | client->afc_packet->entire_length = client->afc_packet->this_length + MAXIMUM_WRITE_SIZE; | 886 | client->afc_packet->entire_length = client->afc_packet->this_length + MAXIMUM_WRITE_SIZE; |
| 867 | client->afc_packet->operation = AFC_OP_WRITE; | 887 | client->afc_packet->operation = AFC_OP_WRITE; |
| @@ -886,10 +906,9 @@ afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t | |||
| 886 | } | 906 | } |
| 887 | } | 907 | } |
| 888 | 908 | ||
| 889 | // By this point, we should be at the end. i.e. the last segment that | 909 | /* By this point, we should be at the end. i.e. the last segment that didn't |
| 890 | // didn't get sent in the for loop | 910 | get sent in the for loop. This length is fine because it's always |
| 891 | // this length is fine because it's always sizeof(AFCPacket) + 8, but | 911 | sizeof(AFCPacket) + 8, but to be sure we do it again */ |
| 892 | // to be sure we do it again | ||
| 893 | if (current_count == length) { | 912 | if (current_count == length) { |
| 894 | afc_unlock(client); | 913 | afc_unlock(client); |
| 895 | *bytes_written = current_count; | 914 | *bytes_written = current_count; |
| @@ -925,7 +944,8 @@ afc_file_write(afc_client_t client, uint64_t handle, const char *data, uint32_t | |||
| 925 | return ret; | 944 | return ret; |
| 926 | } | 945 | } |
| 927 | 946 | ||
| 928 | /** Closes a file on the phone. | 947 | /** |
| 948 | * Closes a file on the phone. | ||
| 929 | * | 949 | * |
| 930 | * @param client The client to close the file with. | 950 | * @param client The client to close the file with. |
| 931 | * @param handle File handle of a previously opened file. | 951 | * @param handle File handle of a previously opened file. |
| @@ -943,7 +963,7 @@ afc_error_t afc_file_close(afc_client_t client, uint64_t handle) | |||
| 943 | 963 | ||
| 944 | debug_info("File handle %i", handle); | 964 | debug_info("File handle %i", handle); |
| 945 | 965 | ||
| 946 | // Send command | 966 | /* Send command */ |
| 947 | memcpy(buffer, &handle, sizeof(uint64_t)); | 967 | memcpy(buffer, &handle, sizeof(uint64_t)); |
| 948 | client->afc_packet->operation = AFC_OP_FILE_CLOSE; | 968 | client->afc_packet->operation = AFC_OP_FILE_CLOSE; |
| 949 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; | 969 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; |
| @@ -956,7 +976,7 @@ afc_error_t afc_file_close(afc_client_t client, uint64_t handle) | |||
| 956 | return AFC_E_UNKNOWN_ERROR; | 976 | return AFC_E_UNKNOWN_ERROR; |
| 957 | } | 977 | } |
| 958 | 978 | ||
| 959 | // Receive the response | 979 | /* Receive the response */ |
| 960 | ret = afc_receive_data(client, &buffer, &bytes); | 980 | ret = afc_receive_data(client, &buffer, &bytes); |
| 961 | if (buffer) | 981 | if (buffer) |
| 962 | free(buffer); | 982 | free(buffer); |
| @@ -966,7 +986,8 @@ afc_error_t afc_file_close(afc_client_t client, uint64_t handle) | |||
| 966 | return ret; | 986 | return ret; |
| 967 | } | 987 | } |
| 968 | 988 | ||
| 969 | /** Locks or unlocks a file on the phone. | 989 | /** |
| 990 | * Locks or unlocks a file on the phone. | ||
| 970 | * | 991 | * |
| 971 | * makes use of flock on the device, see | 992 | * makes use of flock on the device, see |
| 972 | * http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/flock.2.html | 993 | * http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/flock.2.html |
| @@ -991,7 +1012,7 @@ afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t op | |||
| 991 | 1012 | ||
| 992 | debug_info("file handle %i", handle); | 1013 | debug_info("file handle %i", handle); |
| 993 | 1014 | ||
| 994 | // Send command | 1015 | /* Send command */ |
| 995 | memcpy(buffer, &handle, sizeof(uint64_t)); | 1016 | memcpy(buffer, &handle, sizeof(uint64_t)); |
| 996 | memcpy(buffer + 8, &op, 8); | 1017 | memcpy(buffer + 8, &op, 8); |
| 997 | 1018 | ||
| @@ -1006,7 +1027,7 @@ afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t op | |||
| 1006 | debug_info("could not send lock command"); | 1027 | debug_info("could not send lock command"); |
| 1007 | return AFC_E_UNKNOWN_ERROR; | 1028 | return AFC_E_UNKNOWN_ERROR; |
| 1008 | } | 1029 | } |
| 1009 | // Receive the response | 1030 | /* Receive the response */ |
| 1010 | ret = afc_receive_data(client, &buffer, &bytes); | 1031 | ret = afc_receive_data(client, &buffer, &bytes); |
| 1011 | if (buffer) { | 1032 | if (buffer) { |
| 1012 | debug_buffer(buffer, bytes); | 1033 | debug_buffer(buffer, bytes); |
| @@ -1017,14 +1038,15 @@ afc_error_t afc_file_lock(afc_client_t client, uint64_t handle, afc_lock_op_t op | |||
| 1017 | return ret; | 1038 | return ret; |
| 1018 | } | 1039 | } |
| 1019 | 1040 | ||
| 1020 | /** Seeks to a given position of a pre-opened file on the phone. | 1041 | /** |
| 1042 | * Seeks to a given position of a pre-opened file on the phone. | ||
| 1021 | * | 1043 | * |
| 1022 | * @param client The client to use to seek to the position. | 1044 | * @param client The client to use to seek to the position. |
| 1023 | * @param handle File handle of a previously opened. | 1045 | * @param handle File handle of a previously opened. |
| 1024 | * @param offset Seek offset. | 1046 | * @param offset Seek offset. |
| 1025 | * @param whence Seeking direction, one of SEEK_SET, SEEK_CUR, or SEEK_END. | 1047 | * @param whence Seeking direction, one of SEEK_SET, SEEK_CUR, or SEEK_END. |
| 1026 | * | 1048 | * |
| 1027 | * @return AFC_E_SUCCESS on success, AFC_E_NOT_ENOUGH_DATA on failure. | 1049 | * @return AFC_E_SUCCESS on success or an AFC_E_* error value. |
| 1028 | */ | 1050 | */ |
| 1029 | afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence) | 1051 | afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, int whence) |
| 1030 | { | 1052 | { |
| @@ -1039,10 +1061,10 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, | |||
| 1039 | 1061 | ||
| 1040 | afc_lock(client); | 1062 | afc_lock(client); |
| 1041 | 1063 | ||
| 1042 | // Send the command | 1064 | /* Send the command */ |
| 1043 | memcpy(buffer, &handle, sizeof(uint64_t)); // handle | 1065 | memcpy(buffer, &handle, sizeof(uint64_t)); /* handle */ |
| 1044 | memcpy(buffer + 8, &whence_loc, sizeof(uint64_t)); // fromwhere | 1066 | memcpy(buffer + 8, &whence_loc, sizeof(uint64_t)); /* fromwhere */ |
| 1045 | memcpy(buffer + 16, &offset_loc, sizeof(uint64_t)); // offset | 1067 | memcpy(buffer + 16, &offset_loc, sizeof(uint64_t)); /* offset */ |
| 1046 | client->afc_packet->operation = AFC_OP_FILE_SEEK; | 1068 | client->afc_packet->operation = AFC_OP_FILE_SEEK; |
| 1047 | client->afc_packet->this_length = client->afc_packet->entire_length = 0; | 1069 | client->afc_packet->this_length = client->afc_packet->entire_length = 0; |
| 1048 | ret = afc_dispatch_packet(client, buffer, 24, &bytes); | 1070 | ret = afc_dispatch_packet(client, buffer, 24, &bytes); |
| @@ -1053,7 +1075,7 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, | |||
| 1053 | afc_unlock(client); | 1075 | afc_unlock(client); |
| 1054 | return AFC_E_NOT_ENOUGH_DATA; | 1076 | return AFC_E_NOT_ENOUGH_DATA; |
| 1055 | } | 1077 | } |
| 1056 | // Receive response | 1078 | /* Receive response */ |
| 1057 | ret = afc_receive_data(client, &buffer, &bytes); | 1079 | ret = afc_receive_data(client, &buffer, &bytes); |
| 1058 | if (buffer) | 1080 | if (buffer) |
| 1059 | free(buffer); | 1081 | free(buffer); |
| @@ -1063,13 +1085,14 @@ afc_error_t afc_file_seek(afc_client_t client, uint64_t handle, int64_t offset, | |||
| 1063 | return ret; | 1085 | return ret; |
| 1064 | } | 1086 | } |
| 1065 | 1087 | ||
| 1066 | /** Returns current position in a pre-opened file on the phone. | 1088 | /** |
| 1089 | * Returns current position in a pre-opened file on the phone. | ||
| 1067 | * | 1090 | * |
| 1068 | * @param client The client to use. | 1091 | * @param client The client to use. |
| 1069 | * @param handle File handle of a previously opened file. | 1092 | * @param handle File handle of a previously opened file. |
| 1070 | * @param position Position in bytes of indicator | 1093 | * @param position Position in bytes of indicator |
| 1071 | * | 1094 | * |
| 1072 | * @return AFC_E_SUCCESS on success, AFC_E_NOT_ENOUGH_DATA on failure. | 1095 | * @return AFC_E_SUCCESS on success or an AFC_E_* error value. |
| 1073 | */ | 1096 | */ |
| 1074 | afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position) | 1097 | afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *position) |
| 1075 | { | 1098 | { |
| @@ -1082,8 +1105,8 @@ afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *positi | |||
| 1082 | 1105 | ||
| 1083 | afc_lock(client); | 1106 | afc_lock(client); |
| 1084 | 1107 | ||
| 1085 | // Send the command | 1108 | /* Send the command */ |
| 1086 | memcpy(buffer, &handle, sizeof(uint64_t)); // handle | 1109 | memcpy(buffer, &handle, sizeof(uint64_t)); /* handle */ |
| 1087 | client->afc_packet->operation = AFC_OP_FILE_TELL; | 1110 | client->afc_packet->operation = AFC_OP_FILE_TELL; |
| 1088 | client->afc_packet->this_length = client->afc_packet->entire_length = 0; | 1111 | client->afc_packet->this_length = client->afc_packet->entire_length = 0; |
| 1089 | ret = afc_dispatch_packet(client, buffer, 8, &bytes); | 1112 | ret = afc_dispatch_packet(client, buffer, 8, &bytes); |
| @@ -1095,7 +1118,7 @@ afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *positi | |||
| 1095 | return AFC_E_NOT_ENOUGH_DATA; | 1118 | return AFC_E_NOT_ENOUGH_DATA; |
| 1096 | } | 1119 | } |
| 1097 | 1120 | ||
| 1098 | // Receive the data | 1121 | /* Receive the data */ |
| 1099 | ret = afc_receive_data(client, &buffer, &bytes); | 1122 | ret = afc_receive_data(client, &buffer, &bytes); |
| 1100 | if (bytes > 0 && buffer) { | 1123 | if (bytes > 0 && buffer) { |
| 1101 | /* Get the position */ | 1124 | /* Get the position */ |
| @@ -1110,13 +1133,14 @@ afc_error_t afc_file_tell(afc_client_t client, uint64_t handle, uint64_t *positi | |||
| 1110 | return ret; | 1133 | return ret; |
| 1111 | } | 1134 | } |
| 1112 | 1135 | ||
| 1113 | /** Sets the size of a file on the phone. | 1136 | /** |
| 1137 | * Sets the size of a file on the phone. | ||
| 1114 | * | 1138 | * |
| 1115 | * @param client The client to use to set the file size. | 1139 | * @param client The client to use to set the file size. |
| 1116 | * @param handle File handle of a previously opened file. | 1140 | * @param handle File handle of a previously opened file. |
| 1117 | * @param newsize The size to set the file to. | 1141 | * @param newsize The size to set the file to. |
| 1118 | * | 1142 | * |
| 1119 | * @return 0 on success, -1 on failure. | 1143 | * @return AFC_E_SUCCESS on success or an AFC_E_* error value. |
| 1120 | * | 1144 | * |
| 1121 | * @note This function is more akin to ftruncate than truncate, and truncate | 1145 | * @note This function is more akin to ftruncate than truncate, and truncate |
| 1122 | * calls would have to open the file before calling this, sadly. | 1146 | * calls would have to open the file before calling this, sadly. |
| @@ -1133,9 +1157,9 @@ afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t new | |||
| 1133 | 1157 | ||
| 1134 | afc_lock(client); | 1158 | afc_lock(client); |
| 1135 | 1159 | ||
| 1136 | // Send command | 1160 | /* Send command */ |
| 1137 | memcpy(buffer, &handle, sizeof(uint64_t)); // handle | 1161 | memcpy(buffer, &handle, sizeof(uint64_t)); /* handle */ |
| 1138 | memcpy(buffer + 8, &newsize_loc, sizeof(uint64_t)); // newsize | 1162 | memcpy(buffer + 8, &newsize_loc, sizeof(uint64_t)); /* newsize */ |
| 1139 | client->afc_packet->operation = AFC_OP_FILE_SET_SIZE; | 1163 | client->afc_packet->operation = AFC_OP_FILE_SET_SIZE; |
| 1140 | client->afc_packet->this_length = client->afc_packet->entire_length = 0; | 1164 | client->afc_packet->this_length = client->afc_packet->entire_length = 0; |
| 1141 | ret = afc_dispatch_packet(client, buffer, 16, &bytes); | 1165 | ret = afc_dispatch_packet(client, buffer, 16, &bytes); |
| @@ -1146,7 +1170,7 @@ afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t new | |||
| 1146 | afc_unlock(client); | 1170 | afc_unlock(client); |
| 1147 | return AFC_E_NOT_ENOUGH_DATA; | 1171 | return AFC_E_NOT_ENOUGH_DATA; |
| 1148 | } | 1172 | } |
| 1149 | // Receive response | 1173 | /* Receive response */ |
| 1150 | ret = afc_receive_data(client, &buffer, &bytes); | 1174 | ret = afc_receive_data(client, &buffer, &bytes); |
| 1151 | if (buffer) | 1175 | if (buffer) |
| 1152 | free(buffer); | 1176 | free(buffer); |
| @@ -1156,7 +1180,8 @@ afc_error_t afc_file_truncate(afc_client_t client, uint64_t handle, uint64_t new | |||
| 1156 | return ret; | 1180 | return ret; |
| 1157 | } | 1181 | } |
| 1158 | 1182 | ||
| 1159 | /** Sets the size of a file on the phone without prior opening it. | 1183 | /** |
| 1184 | * Sets the size of a file on the phone without prior opening it. | ||
| 1160 | * | 1185 | * |
| 1161 | * @param client The client to use to set the file size. | 1186 | * @param client The client to use to set the file size. |
| 1162 | * @param path The path of the file to be truncated. | 1187 | * @param path The path of the file to be truncated. |
| @@ -1177,7 +1202,7 @@ afc_error_t afc_truncate(afc_client_t client, const char *path, uint64_t newsize | |||
| 1177 | 1202 | ||
| 1178 | afc_lock(client); | 1203 | afc_lock(client); |
| 1179 | 1204 | ||
| 1180 | // Send command | 1205 | /* Send command */ |
| 1181 | memcpy(send, &size_requested, 8); | 1206 | memcpy(send, &size_requested, 8); |
| 1182 | memcpy(send + 8, path, strlen(path) + 1); | 1207 | memcpy(send + 8, path, strlen(path) + 1); |
| 1183 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; | 1208 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; |
| @@ -1188,7 +1213,7 @@ afc_error_t afc_truncate(afc_client_t client, const char *path, uint64_t newsize | |||
| 1188 | afc_unlock(client); | 1213 | afc_unlock(client); |
| 1189 | return AFC_E_NOT_ENOUGH_DATA; | 1214 | return AFC_E_NOT_ENOUGH_DATA; |
| 1190 | } | 1215 | } |
| 1191 | // Receive response | 1216 | /* Receive response */ |
| 1192 | ret = afc_receive_data(client, &response, &bytes); | 1217 | ret = afc_receive_data(client, &response, &bytes); |
| 1193 | if (response) | 1218 | if (response) |
| 1194 | free(response); | 1219 | free(response); |
| @@ -1198,10 +1223,11 @@ afc_error_t afc_truncate(afc_client_t client, const char *path, uint64_t newsize | |||
| 1198 | return ret; | 1223 | return ret; |
| 1199 | } | 1224 | } |
| 1200 | 1225 | ||
| 1201 | /** Creates a hard link or symbolic link on the device. | 1226 | /** |
| 1227 | * Creates a hard link or symbolic link on the device. | ||
| 1202 | * | 1228 | * |
| 1203 | * @param client The client to use for making a link | 1229 | * @param client The client to use for making a link |
| 1204 | * @param type 1 = hard link, 2 = symlink | 1230 | * @param linktype 1 = hard link, 2 = symlink |
| 1205 | * @param target The file to be linked. | 1231 | * @param target The file to be linked. |
| 1206 | * @param linkname The name of link. | 1232 | * @param linkname The name of link. |
| 1207 | * | 1233 | * |
| @@ -1224,7 +1250,7 @@ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const c | |||
| 1224 | debug_info("target: %s, length:%d", target, strlen(target)); | 1250 | debug_info("target: %s, length:%d", target, strlen(target)); |
| 1225 | debug_info("linkname: %s, length:%d", linkname, strlen(linkname)); | 1251 | debug_info("linkname: %s, length:%d", linkname, strlen(linkname)); |
| 1226 | 1252 | ||
| 1227 | // Send command | 1253 | /* Send command */ |
| 1228 | memcpy(send, &type, 8); | 1254 | memcpy(send, &type, 8); |
| 1229 | memcpy(send + 8, target, strlen(target) + 1); | 1255 | memcpy(send + 8, target, strlen(target) + 1); |
| 1230 | memcpy(send + 8 + strlen(target) + 1, linkname, strlen(linkname) + 1); | 1256 | memcpy(send + 8 + strlen(target) + 1, linkname, strlen(linkname) + 1); |
| @@ -1236,7 +1262,7 @@ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const c | |||
| 1236 | afc_unlock(client); | 1262 | afc_unlock(client); |
| 1237 | return AFC_E_NOT_ENOUGH_DATA; | 1263 | return AFC_E_NOT_ENOUGH_DATA; |
| 1238 | } | 1264 | } |
| 1239 | // Receive response | 1265 | /* Receive response */ |
| 1240 | ret = afc_receive_data(client, &response, &bytes); | 1266 | ret = afc_receive_data(client, &response, &bytes); |
| 1241 | if (response) | 1267 | if (response) |
| 1242 | free(response); | 1268 | free(response); |
| @@ -1246,7 +1272,8 @@ afc_error_t afc_make_link(afc_client_t client, afc_link_type_t linktype, const c | |||
| 1246 | return ret; | 1272 | return ret; |
| 1247 | } | 1273 | } |
| 1248 | 1274 | ||
| 1249 | /** Sets the modification time of a file on the phone. | 1275 | /** |
| 1276 | * Sets the modification time of a file on the phone. | ||
| 1250 | * | 1277 | * |
| 1251 | * @param client The client to use to set the file size. | 1278 | * @param client The client to use to set the file size. |
| 1252 | * @param path Path of the file for which the modification time should be set. | 1279 | * @param path Path of the file for which the modification time should be set. |
| @@ -1267,7 +1294,7 @@ afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mt | |||
| 1267 | 1294 | ||
| 1268 | afc_lock(client); | 1295 | afc_lock(client); |
| 1269 | 1296 | ||
| 1270 | // Send command | 1297 | /* Send command */ |
| 1271 | memcpy(send, &mtime_loc, 8); | 1298 | memcpy(send, &mtime_loc, 8); |
| 1272 | memcpy(send + 8, path, strlen(path) + 1); | 1299 | memcpy(send + 8, path, strlen(path) + 1); |
| 1273 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; | 1300 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; |
| @@ -1278,7 +1305,7 @@ afc_error_t afc_set_file_time(afc_client_t client, const char *path, uint64_t mt | |||
| 1278 | afc_unlock(client); | 1305 | afc_unlock(client); |
| 1279 | return AFC_E_NOT_ENOUGH_DATA; | 1306 | return AFC_E_NOT_ENOUGH_DATA; |
| 1280 | } | 1307 | } |
| 1281 | // Receive response | 1308 | /* Receive response */ |
| 1282 | ret = afc_receive_data(client, &response, &bytes); | 1309 | ret = afc_receive_data(client, &response, &bytes); |
| 1283 | if (response) | 1310 | if (response) |
| 1284 | free(response); | 1311 | free(response); |
