diff options
author | Nikias Bassen | 2009-03-08 11:57:58 -0700 |
---|---|---|
committer | Matt Colyer | 2009-03-08 11:59:02 -0700 |
commit | 927a6d3d437ca4532f8e9e906089b3a24542ebd3 (patch) | |
tree | b98d85db19727387c3e8aff2968b1e6919ad63bc | |
parent | aab730841f6bf9fe93383649c2e1e25cea3818a8 (diff) | |
download | libimobiledevice-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>
-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 iphone_error_t iphone_afc_delete_file ( iphone_afc_client_t client, const char *path); iphone_error_t iphone_afc_rename_file ( iphone_afc_client_t client, const char *from, const char *to); iphone_error_t iphone_afc_mkdir ( iphone_afc_client_t client, const char *dir); +iphone_error_t iphone_afc_truncate(iphone_afc_client_t client, const char *path, off_t newsize); #ifdef __cplusplus @@ -179,7 +179,7 @@ static int dispatch_AFC_packet(iphone_afc_client_t client, const char *data, int log_debug_msg("dispatch_AFC_packet: sent the first now go with the second\n"); log_debug_msg("Length: %i\n", length - offset); log_debug_msg("Buffer: \n"); - log_debug_msg(data + offset); + log_debug_buffer(data + offset, length - offset); iphone_mux_send(client->connection, data + offset, length - offset, &bytes); return bytes; @@ -1017,6 +1017,53 @@ iphone_error_t iphone_afc_truncate_file(iphone_afc_client_t client, iphone_afc_f } } +/** Sets the size of a file on the phone without prior opening it. + * + * @param client The client to use to set the file size. + * @param path The path of the file to be truncated. + * @param newsize The size to set the file to. + * + * @return IPHONE_E_SUCCESS if everything went well, IPHONE_E_INVALID_ARG + * if arguments are NULL or invalid, IPHONE_E_NOT_ENOUGH_DATA otherwise. + */ +iphone_error_t iphone_afc_truncate(iphone_afc_client_t client, const char *path, off_t newsize) +{ + char *response = NULL; + char *send = (char *) malloc(sizeof(char) * (strlen(path) + 1 + 8)); + int bytes = 0; + uint64_t size_requested = newsize; + + if (!client || !path || !client->afc_packet || !client->connection) + return IPHONE_E_INVALID_ARG; + + afc_lock(client); + + // Send command + memcpy(send, &size_requested, 8); + memcpy(send + 8, path, strlen(path) + 1); + client->afc_packet->entire_length = client->afc_packet->this_length = 0; + client->afc_packet->operation = AFC_TRUNCATE; + bytes = dispatch_AFC_packet(client, send, 8 + strlen(path)); + free(send); + if (bytes <= 0) { + afc_unlock(client); + return IPHONE_E_NOT_ENOUGH_DATA; + } + // Receive response + bytes = receive_AFC_data(client, &response); + if (response) + free(response); + + afc_unlock(client); + + if (bytes < 0) { + return IPHONE_E_NOT_ENOUGH_DATA; + } else { + return IPHONE_E_SUCCESS; + } +} + + uint32 iphone_afc_get_file_handle(iphone_afc_file_t file) { return file->filehandle; @@ -63,6 +63,7 @@ enum { AFC_LIST_DIR = 0x00000003, AFC_MAKE_DIR = 0x00000009, AFC_DELETE = 0x00000008, + AFC_TRUNCATE = 0x00000007, AFC_RENAME = 0x00000018, AFC_SUCCESS_RESPONSE = 0x00000002, AFC_FILE_OPEN = 0x0000000d, |