diff options
| -rw-r--r-- | include/libiphone/libiphone.h | 1 | ||||
| -rw-r--r-- | src/AFC.c | 49 | ||||
| -rw-r--r-- | src/AFC.h | 1 |
3 files changed, 50 insertions, 1 deletions
diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index 32d47d3..158fd84 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h | |||
| @@ -118,6 +118,7 @@ iphone_error_t iphone_afc_truncate_file ( iphone_afc_client_t client, iphone_afc | |||
| 118 | iphone_error_t iphone_afc_delete_file ( iphone_afc_client_t client, const char *path); | 118 | iphone_error_t iphone_afc_delete_file ( iphone_afc_client_t client, const char *path); |
| 119 | iphone_error_t iphone_afc_rename_file ( iphone_afc_client_t client, const char *from, const char *to); | 119 | iphone_error_t iphone_afc_rename_file ( iphone_afc_client_t client, const char *from, const char *to); |
| 120 | iphone_error_t iphone_afc_mkdir ( iphone_afc_client_t client, const char *dir); | 120 | iphone_error_t iphone_afc_mkdir ( iphone_afc_client_t client, const char *dir); |
| 121 | iphone_error_t iphone_afc_truncate(iphone_afc_client_t client, const char *path, off_t newsize); | ||
| 121 | 122 | ||
| 122 | 123 | ||
| 123 | #ifdef __cplusplus | 124 | #ifdef __cplusplus |
| @@ -179,7 +179,7 @@ static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, int | |||
| 179 | log_debug_msg("dispatch_AFC_packet: sent the first now go with the second\n"); | 179 | log_debug_msg("dispatch_AFC_packet: sent the first now go with the second\n"); |
| 180 | log_debug_msg("Length: %i\n", length - offset); | 180 | log_debug_msg("Length: %i\n", length - offset); |
| 181 | log_debug_msg("Buffer: \n"); | 181 | log_debug_msg("Buffer: \n"); |
| 182 | log_debug_msg(data + offset); | 182 | log_debug_buffer(data + offset, length - offset); |
| 183 | 183 | ||
| 184 | iphone_mux_send(client->connection, data + offset, length - offset, &bytes); | 184 | iphone_mux_send(client->connection, data + offset, length - offset, &bytes); |
| 185 | return bytes; | 185 | return bytes; |
| @@ -1017,6 +1017,53 @@ iphone_error_t iphone_afc_truncate_file(iphone_afc_client_t client, iphone_afc_f | |||
| 1017 | } | 1017 | } |
| 1018 | } | 1018 | } |
| 1019 | 1019 | ||
| 1020 | /** Sets the size of a file on the phone without prior opening it. | ||
| 1021 | * | ||
| 1022 | * @param client The client to use to set the file size. | ||
| 1023 | * @param path The path of the file to be truncated. | ||
| 1024 | * @param newsize The size to set the file to. | ||
| 1025 | * | ||
| 1026 | * @return IPHONE_E_SUCCESS if everything went well, IPHONE_E_INVALID_ARG | ||
| 1027 | * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. | ||
| 1028 | */ | ||
| 1029 | iphone_error_t iphone_afc_truncate(iphone_afc_client_t client, const char *path, off_t newsize) | ||
| 1030 | { | ||
| 1031 | char *response = NULL; | ||
| 1032 | char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8)); | ||
| 1033 | int bytes = 0; | ||
| 1034 | uint64_t size_requested = newsize; | ||
| 1035 | |||
| 1036 | if (!client || !path || !client->afc_packet || !client->connection) | ||
| 1037 | return IPHONE_E_INVALID_ARG; | ||
| 1038 | |||
| 1039 | afc_lock(client); | ||
| 1040 | |||
| 1041 | // Send command | ||
| 1042 | memcpy(send, &size_requested, 8); | ||
| 1043 | memcpy(send + 8, path, strlen(path) + 1); | ||
| 1044 | client->afc_packet->entire_length = client->afc_packet->this_length = 0; | ||
| 1045 | client->afc_packet->operation = AFC_TRUNCATE; | ||
| 1046 | bytes = dispatch_AFC_packet(client, send, 8 + strlen(path)); | ||
| 1047 | free(send); | ||
| 1048 | if (bytes <= 0) { | ||
| 1049 | afc_unlock(client); | ||
| 1050 | return IPHONE_E_NOT_ENOUGH_DATA; | ||
| 1051 | } | ||
| 1052 | // Receive response | ||
| 1053 | bytes = receive_AFC_data(client, &response); | ||
| 1054 | if (response) | ||
| 1055 | free(response); | ||
| 1056 | |||
| 1057 | afc_unlock(client); | ||
| 1058 | |||
| 1059 | if (bytes < 0) { | ||
| 1060 | return IPHONE_E_NOT_ENOUGH_DATA; | ||
| 1061 | } else { | ||
| 1062 | return IPHONE_E_SUCCESS; | ||
| 1063 | } | ||
| 1064 | } | ||
| 1065 | |||
| 1066 | |||
| 1020 | uint32 iphone_afc_get_file_handle(iphone_afc_file_t file) | 1067 | uint32 iphone_afc_get_file_handle(iphone_afc_file_t file) |
| 1021 | { | 1068 | { |
| 1022 | return file->filehandle; | 1069 | return file->filehandle; |
| @@ -63,6 +63,7 @@ enum { | |||
| 63 | AFC_LIST_DIR = 0x00000003, | 63 | AFC_LIST_DIR = 0x00000003, |
| 64 | AFC_MAKE_DIR = 0x00000009, | 64 | AFC_MAKE_DIR = 0x00000009, |
| 65 | AFC_DELETE = 0x00000008, | 65 | AFC_DELETE = 0x00000008, |
| 66 | AFC_TRUNCATE = 0x00000007, | ||
| 66 | AFC_RENAME = 0x00000018, | 67 | AFC_RENAME = 0x00000018, |
| 67 | AFC_SUCCESS_RESPONSE = 0x00000002, | 68 | AFC_SUCCESS_RESPONSE = 0x00000002, |
| 68 | AFC_FILE_OPEN = 0x0000000d, | 69 | AFC_FILE_OPEN = 0x0000000d, |
