summaryrefslogtreecommitdiffstats
path: root/src/AFC.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-03-08 11:57:58 -0700
committerGravatar Matt Colyer2009-03-08 11:59:02 -0700
commit927a6d3d437ca4532f8e9e906089b3a24542ebd3 (patch)
treeb98d85db19727387c3e8aff2968b1e6919ad63bc /src/AFC.c
parentaab730841f6bf9fe93383649c2e1e25cea3818a8 (diff)
downloadlibimobiledevice-927a6d3d437ca4532f8e9e906089b3a24542ebd3.tar.gz
libimobiledevice-927a6d3d437ca4532f8e9e906089b3a24542ebd3.tar.bz2
Adds the iphone_afc_truncate function and fixes a small log_debug issue.
Signed-off-by: Matt Colyer <matt@colyer.name>
Diffstat (limited to 'src/AFC.c')
-rw-r--r--src/AFC.c49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/AFC.c b/src/AFC.c
index cd24cc6..dc8fe20 100644
--- a/src/AFC.c
+++ b/src/AFC.c
@@ -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 */
1029iphone_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
1020uint32 iphone_afc_get_file_handle(iphone_afc_file_t file) 1067uint32 iphone_afc_get_file_handle(iphone_afc_file_t file)
1021{ 1068{
1022 return file->filehandle; 1069 return file->filehandle;